Website Structure

This commit is contained in:
supalerk-ar66 2026-01-13 10:46:40 +07:00
parent 62812f2090
commit 71f0676a62
22365 changed files with 4265753 additions and 791 deletions

21
Frontend-Learner/node_modules/fast-npm-meta/LICENSE generated vendored Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Anthony Fu <https://github.com/antfu>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,133 @@
interface PackageManifest {
name: string;
distTags: Record<string, string> & {
latest: string;
};
versionsMeta: Record<string, PackageVersionMeta>;
timeCreated: string;
timeModified: string;
lastSynced: number;
}
type Engines = Partial<Record<string, string>>;
interface PackageVersionMeta {
time?: string;
engines?: Engines;
deprecated?: string;
provenance?: 'trustedPublisher' | boolean;
}
interface PackageVersionsInfo extends Pick<PackageManifest, 'name' | 'distTags' | 'lastSynced'> {
versions: string[];
specifier: string;
time: {
created: string;
modified: string;
} & Record<string, string>;
}
interface PackageVersionsInfoWithMetadata extends PackageManifest {
specifier: string;
}
interface PackageError {
name: string;
error: string;
}
type MaybeError<T> = T | PackageError;
interface PackageManifestError extends PackageError {
lastSynced: number;
}
interface ResolvedPackageVersion {
name: string;
version: string | null;
specifier: string;
publishedAt: string | null;
lastSynced: number;
}
interface ResolvedPackageVersionWithMetadata extends ResolvedPackageVersion, PackageVersionMeta {
}
interface FetchOptions<Throw extends boolean = true> {
/**
* API endpoint for fetching package versions
*
* @default 'https://npm.antfu.dev/'
*/
apiEndpoint?: string;
/**
* Fetch function
*
* @default [globalThis.fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
*/
fetch?: typeof fetch;
/**
* Should throw error or return error object
*
* @default true
*/
throw?: Throw;
}
interface GetVersionsOptions<Metadata extends boolean = false, Throw extends boolean = true> extends FetchOptions<Throw> {
/**
* By pass cache and get the latest data
*
* @default false
*/
force?: boolean;
/**
* Include all versions that are newer than the specified version
*
* @default false
*/
loose?: boolean;
/**
* Includes metadata, this will change the return type
*
* @default false
*/
metadata?: Metadata;
/**
* Only return versions published after this ISO date-time
*
* @default undefined
*/
after?: string;
}
interface GetLatestVersionOptions<Metadata extends boolean = false, Throw extends boolean = true> extends FetchOptions<Throw> {
/**
* By pass cache and get the latest data
*
* @default false
*/
force?: boolean;
/**
* Includes metadata
*
* @default false
*/
metadata?: Metadata;
}
type InferGetVersionsResult<Metadata, Throw> = Metadata extends true ? Throw extends true ? PackageVersionsInfoWithMetadata : MaybeError<PackageVersionsInfoWithMetadata> : Throw extends true ? PackageVersionsInfo : MaybeError<PackageVersionsInfo>;
type InferGetLatestVersionResult<Metadata, Throw> = Metadata extends true ? Throw extends true ? ResolvedPackageVersionWithMetadata : MaybeError<ResolvedPackageVersionWithMetadata> : Throw extends true ? ResolvedPackageVersion : MaybeError<ResolvedPackageVersion>;
declare const defaultOptions: {
/**
* API endpoint for fetching package versions
*
* @default 'https://npm.antfu.dev/'
*/
apiEndpoint: string;
};
declare function getLatestVersionBatch<Metadata extends boolean = false, Throw extends boolean = true>(packages: string[], options?: GetLatestVersionOptions<Metadata, Throw>): Promise<InferGetLatestVersionResult<Metadata, Throw>[]>;
declare function getLatestVersion<Metadata extends boolean = false, Throw extends boolean = true>(name: string, options?: GetLatestVersionOptions<Metadata, Throw>): Promise<InferGetLatestVersionResult<Metadata, Throw>>;
declare function getVersionsBatch<Metadata extends boolean = false, Throw extends boolean = true>(packages: string[], options?: GetVersionsOptions<Metadata, Throw>): Promise<InferGetVersionsResult<Metadata, Throw>[]>;
declare function getVersions<Metadata extends boolean = false, Throw extends boolean = true>(name: string, options?: GetVersionsOptions<Metadata, Throw>): Promise<InferGetVersionsResult<Metadata, Throw>>;
declare const NPM_REGISTRY = "https://registry.npmjs.org/";
/**
* Lightweight replacement of `npm-registry-fetch` function `pickRegistry`'
*
* @param scope - scope of package, get from 'npm-package-arg'
* @param npmConfigs - npm configs, read from `.npmrc` file
* @param defaultRegistry - default registry, default to 'https://registry.npmjs.org/'
*/
declare function pickRegistry(scope: string | null | undefined, npmConfigs: Record<string, unknown>, defaultRegistry?: string): string;
export { NPM_REGISTRY, defaultOptions, getLatestVersion, getLatestVersionBatch, getVersions, getVersionsBatch, pickRegistry };
export type { Engines, FetchOptions, GetLatestVersionOptions, GetVersionsOptions, InferGetLatestVersionResult, InferGetVersionsResult, MaybeError, PackageError, PackageManifest, PackageManifestError, PackageVersionMeta, PackageVersionsInfo, PackageVersionsInfoWithMetadata, ResolvedPackageVersion, ResolvedPackageVersionWithMetadata };

View file

@ -0,0 +1,78 @@
const defaultOptions = {
/**
* API endpoint for fetching package versions
*
* @default 'https://npm.antfu.dev/'
*/
apiEndpoint: "https://npm.antfu.dev/"
};
async function getLatestVersionBatch(packages, options = {}) {
const {
apiEndpoint = defaultOptions.apiEndpoint,
fetch: fetchApi = fetch,
throw: throwError = true
} = options;
let query = [
options.force ? "force=true" : "",
options.metadata ? "metadata=true" : "",
throwError ? "" : "throw=false"
].filter(Boolean).join("&");
if (query)
query = `?${query}`;
const data = await fetchApi(new URL(packages.join("+") + query, apiEndpoint)).then((r) => r.json());
const list = toArray(data);
return throwError ? throwErrorObject(list) : list;
}
async function getLatestVersion(name, options = {}) {
const [data] = await getLatestVersionBatch([name], options);
return data;
}
async function getVersionsBatch(packages, options = {}) {
const {
apiEndpoint = defaultOptions.apiEndpoint,
fetch: fetchApi = fetch,
throw: throwError = true
} = options;
let query = [
options.force ? "force=true" : "",
options.loose ? "loose=true" : "",
options.metadata ? "metadata=true" : "",
options.after ? `after=${encodeURIComponent(options.after)}` : "",
throwError ? "" : "throw=false"
].filter(Boolean).join("&");
if (query)
query = `?${query}`;
const data = await fetchApi(new URL(`/versions/${packages.join("+")}${query}`, apiEndpoint)).then((r) => r.json());
const list = toArray(data);
return throwError ? throwErrorObject(list) : list;
}
async function getVersions(name, options = {}) {
const [data] = await getVersionsBatch([name], options);
return data;
}
function throwErrorObject(data) {
for (const item of toArray(data)) {
if (item && "error" in item)
throw new Error(item.message || item.error);
}
return data;
}
function toArray(data) {
if (Array.isArray(data))
return data;
return [data];
}
const NPM_REGISTRY = "https://registry.npmjs.org/";
function pickRegistry(scope, npmConfigs, defaultRegistry = NPM_REGISTRY) {
let registry = scope ? npmConfigs[`${scope.replace(/^@?/, "@")}:registry`] : void 0;
if (!registry && typeof npmConfigs.scope === "string") {
registry = npmConfigs[`${npmConfigs.scope.replace(/^@?/, "@")}:registry`];
}
if (!registry) {
registry = npmConfigs.registry || defaultRegistry;
}
return registry;
}
export { NPM_REGISTRY, defaultOptions, getLatestVersion, getLatestVersionBatch, getVersions, getVersionsBatch, pickRegistry };

View file

@ -0,0 +1,30 @@
{
"name": "fast-npm-meta",
"type": "module",
"version": "0.4.7",
"description": "Get npm package metadata",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
"funding": "https://github.com/sponsors/antfu",
"homepage": "https://github.com/antfu/fast-npm-meta#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/antfu/fast-npm-meta.git"
},
"bugs": "https://github.com/antfu/fast-npm-meta/issues",
"keywords": [],
"sideEffects": false,
"exports": {
".": "./dist/index.mjs"
},
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.mts",
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"dev": "unbuild --stub"
}
}