fast-npm-meta 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const ofetch = require('ofetch');
4
-
5
3
  const defaultOptions = {
6
4
  /**
7
5
  * API endpoint for fetching package versions
@@ -12,17 +10,11 @@ const defaultOptions = {
12
10
  };
13
11
  async function getLatestVersionBatch(packages, options = {}) {
14
12
  const {
15
- apiEndpoint = defaultOptions.apiEndpoint
13
+ apiEndpoint = defaultOptions.apiEndpoint,
14
+ fetch: fetchApi = fetch
16
15
  } = options;
17
- const data = await ofetch.$fetch(
18
- packages.join("+"),
19
- {
20
- baseURL: apiEndpoint,
21
- query: {
22
- force: options.force ? true : void 0
23
- }
24
- }
25
- );
16
+ const query = options.force ? "?force=true" : "";
17
+ const data = await fetchApi(new URL(packages.join("+") + query, apiEndpoint)).then((r) => r.json());
26
18
  if (!Array.isArray(data))
27
19
  return [data];
28
20
  return data;
@@ -33,17 +25,16 @@ async function getLatestVersion(name, options = {}) {
33
25
  }
34
26
  async function getVersionsBatch(packages, options = {}) {
35
27
  const {
36
- apiEndpoint = defaultOptions.apiEndpoint
28
+ apiEndpoint = defaultOptions.apiEndpoint,
29
+ fetch: fetchApi = fetch
37
30
  } = options;
38
- const data = await ofetch.$fetch(
39
- `/versions/${packages.join("+")}`,
40
- {
41
- baseURL: apiEndpoint,
42
- query: {
43
- force: options.force ? true : void 0
44
- }
45
- }
46
- );
31
+ let query = [
32
+ options.force ? "force=true" : "",
33
+ options.loose ? "loose=true" : ""
34
+ ].filter(Boolean).join("&");
35
+ if (query)
36
+ query = `?${query}`;
37
+ const data = await fetchApi(new URL(`/versions/${packages.join("+")}${query}`, apiEndpoint)).then((r) => r.json());
47
38
  if (!Array.isArray(data))
48
39
  return [data];
49
40
  return data;
@@ -55,8 +46,8 @@ async function getVersions(name, options = {}) {
55
46
 
56
47
  const NPM_REGISTRY = "https://registry.npmjs.org/";
57
48
  function pickRegistry(scope, npmConfigs, defaultRegistry = NPM_REGISTRY) {
58
- let registry = scope && npmConfigs[`${scope.replace(/^@?/, "@")}:registry`];
59
- if (!registry && npmConfigs.scope) {
49
+ let registry = scope ? npmConfigs[`${scope.replace(/^@?/, "@")}:registry`] : void 0;
50
+ if (!registry && typeof npmConfigs.scope === "string") {
60
51
  registry = npmConfigs[`${npmConfigs.scope.replace(/^@?/, "@")}:registry`];
61
52
  }
62
53
  if (!registry) {
package/dist/index.d.cts CHANGED
@@ -4,18 +4,45 @@ interface PackageManifest {
4
4
  latest: string;
5
5
  };
6
6
  versions: string[];
7
+ time: Record<string, string> & {
8
+ created: string;
9
+ modified: string;
10
+ };
7
11
  lastSynced: number;
8
12
  }
13
+ interface PackageVersionsInfo extends PackageManifest {
14
+ specifier: string;
15
+ }
9
16
  interface ResolvedPackageVersion {
10
17
  name: string;
11
18
  version: string | null;
12
19
  specifier: string;
13
- lastSynced: string;
20
+ publishedAt: string | null;
21
+ lastSynced: number;
14
22
  }
15
23
 
16
- interface ApiOptions {
17
- force?: boolean;
24
+ interface FetchOptions {
18
25
  apiEndpoint?: string;
26
+ /**
27
+ * Fetch function
28
+ */
29
+ fetch?: typeof fetch;
30
+ }
31
+ interface GetVersionsOptions extends FetchOptions {
32
+ /**
33
+ * By pass cache and get the latest data
34
+ */
35
+ force?: boolean;
36
+ /**
37
+ * Include all versions that are newer than the specified version
38
+ */
39
+ loose?: boolean;
40
+ }
41
+ interface GetLatestVersionOptions extends FetchOptions {
42
+ /**
43
+ * By pass cache and get the latest data
44
+ */
45
+ force?: boolean;
19
46
  }
20
47
  declare const defaultOptions: {
21
48
  /**
@@ -25,18 +52,19 @@ declare const defaultOptions: {
25
52
  */
26
53
  apiEndpoint: string;
27
54
  };
28
- declare function getLatestVersionBatch(packages: string[], options?: ApiOptions): Promise<ResolvedPackageVersion[]>;
29
- declare function getLatestVersion(name: string, options?: ApiOptions): Promise<ResolvedPackageVersion>;
30
- declare function getVersionsBatch(packages: string[], options?: ApiOptions): Promise<PackageManifest[]>;
31
- declare function getVersions(name: string, options?: ApiOptions): Promise<PackageManifest>;
55
+ declare function getLatestVersionBatch(packages: string[], options?: GetLatestVersionOptions): Promise<ResolvedPackageVersion[]>;
56
+ declare function getLatestVersion(name: string, options?: GetLatestVersionOptions): Promise<ResolvedPackageVersion>;
57
+ declare function getVersionsBatch(packages: string[], options?: GetVersionsOptions): Promise<PackageVersionsInfo[]>;
58
+ declare function getVersions(name: string, options?: GetVersionsOptions): Promise<PackageVersionsInfo>;
32
59
 
33
60
  declare const NPM_REGISTRY = "https://registry.npmjs.org/";
34
61
  /**
35
62
  * Lightweight replacement of `npm-registry-fetch` function `pickRegistry`'
36
63
  *
37
- * @param scope - npm scope
64
+ * @param scope - scope of package, get from 'npm-package-arg'
38
65
  * @param npmConfigs - npm configs, read from `.npmrc` file
66
+ * @param defaultRegistry - default registry, default to 'https://registry.npmjs.org/'
39
67
  */
40
- declare function pickRegistry(scope: string, npmConfigs: Record<string, string>, defaultRegistry?: string): string;
68
+ declare function pickRegistry(scope: string | null | undefined, npmConfigs: Record<string, unknown>, defaultRegistry?: string): string;
41
69
 
42
- export { type ApiOptions, NPM_REGISTRY, type PackageManifest, type ResolvedPackageVersion, defaultOptions, getLatestVersion, getLatestVersionBatch, getVersions, getVersionsBatch, pickRegistry };
70
+ export { type FetchOptions, type GetLatestVersionOptions, type GetVersionsOptions, NPM_REGISTRY, type PackageManifest, type ResolvedPackageVersion, defaultOptions, getLatestVersion, getLatestVersionBatch, getVersions, getVersionsBatch, pickRegistry };
package/dist/index.d.mts CHANGED
@@ -4,18 +4,45 @@ interface PackageManifest {
4
4
  latest: string;
5
5
  };
6
6
  versions: string[];
7
+ time: Record<string, string> & {
8
+ created: string;
9
+ modified: string;
10
+ };
7
11
  lastSynced: number;
8
12
  }
13
+ interface PackageVersionsInfo extends PackageManifest {
14
+ specifier: string;
15
+ }
9
16
  interface ResolvedPackageVersion {
10
17
  name: string;
11
18
  version: string | null;
12
19
  specifier: string;
13
- lastSynced: string;
20
+ publishedAt: string | null;
21
+ lastSynced: number;
14
22
  }
15
23
 
16
- interface ApiOptions {
17
- force?: boolean;
24
+ interface FetchOptions {
18
25
  apiEndpoint?: string;
26
+ /**
27
+ * Fetch function
28
+ */
29
+ fetch?: typeof fetch;
30
+ }
31
+ interface GetVersionsOptions extends FetchOptions {
32
+ /**
33
+ * By pass cache and get the latest data
34
+ */
35
+ force?: boolean;
36
+ /**
37
+ * Include all versions that are newer than the specified version
38
+ */
39
+ loose?: boolean;
40
+ }
41
+ interface GetLatestVersionOptions extends FetchOptions {
42
+ /**
43
+ * By pass cache and get the latest data
44
+ */
45
+ force?: boolean;
19
46
  }
20
47
  declare const defaultOptions: {
21
48
  /**
@@ -25,18 +52,19 @@ declare const defaultOptions: {
25
52
  */
26
53
  apiEndpoint: string;
27
54
  };
28
- declare function getLatestVersionBatch(packages: string[], options?: ApiOptions): Promise<ResolvedPackageVersion[]>;
29
- declare function getLatestVersion(name: string, options?: ApiOptions): Promise<ResolvedPackageVersion>;
30
- declare function getVersionsBatch(packages: string[], options?: ApiOptions): Promise<PackageManifest[]>;
31
- declare function getVersions(name: string, options?: ApiOptions): Promise<PackageManifest>;
55
+ declare function getLatestVersionBatch(packages: string[], options?: GetLatestVersionOptions): Promise<ResolvedPackageVersion[]>;
56
+ declare function getLatestVersion(name: string, options?: GetLatestVersionOptions): Promise<ResolvedPackageVersion>;
57
+ declare function getVersionsBatch(packages: string[], options?: GetVersionsOptions): Promise<PackageVersionsInfo[]>;
58
+ declare function getVersions(name: string, options?: GetVersionsOptions): Promise<PackageVersionsInfo>;
32
59
 
33
60
  declare const NPM_REGISTRY = "https://registry.npmjs.org/";
34
61
  /**
35
62
  * Lightweight replacement of `npm-registry-fetch` function `pickRegistry`'
36
63
  *
37
- * @param scope - npm scope
64
+ * @param scope - scope of package, get from 'npm-package-arg'
38
65
  * @param npmConfigs - npm configs, read from `.npmrc` file
66
+ * @param defaultRegistry - default registry, default to 'https://registry.npmjs.org/'
39
67
  */
40
- declare function pickRegistry(scope: string, npmConfigs: Record<string, string>, defaultRegistry?: string): string;
68
+ declare function pickRegistry(scope: string | null | undefined, npmConfigs: Record<string, unknown>, defaultRegistry?: string): string;
41
69
 
42
- export { type ApiOptions, NPM_REGISTRY, type PackageManifest, type ResolvedPackageVersion, defaultOptions, getLatestVersion, getLatestVersionBatch, getVersions, getVersionsBatch, pickRegistry };
70
+ export { type FetchOptions, type GetLatestVersionOptions, type GetVersionsOptions, NPM_REGISTRY, type PackageManifest, type ResolvedPackageVersion, defaultOptions, getLatestVersion, getLatestVersionBatch, getVersions, getVersionsBatch, pickRegistry };
package/dist/index.d.ts CHANGED
@@ -4,18 +4,45 @@ interface PackageManifest {
4
4
  latest: string;
5
5
  };
6
6
  versions: string[];
7
+ time: Record<string, string> & {
8
+ created: string;
9
+ modified: string;
10
+ };
7
11
  lastSynced: number;
8
12
  }
13
+ interface PackageVersionsInfo extends PackageManifest {
14
+ specifier: string;
15
+ }
9
16
  interface ResolvedPackageVersion {
10
17
  name: string;
11
18
  version: string | null;
12
19
  specifier: string;
13
- lastSynced: string;
20
+ publishedAt: string | null;
21
+ lastSynced: number;
14
22
  }
15
23
 
16
- interface ApiOptions {
17
- force?: boolean;
24
+ interface FetchOptions {
18
25
  apiEndpoint?: string;
26
+ /**
27
+ * Fetch function
28
+ */
29
+ fetch?: typeof fetch;
30
+ }
31
+ interface GetVersionsOptions extends FetchOptions {
32
+ /**
33
+ * By pass cache and get the latest data
34
+ */
35
+ force?: boolean;
36
+ /**
37
+ * Include all versions that are newer than the specified version
38
+ */
39
+ loose?: boolean;
40
+ }
41
+ interface GetLatestVersionOptions extends FetchOptions {
42
+ /**
43
+ * By pass cache and get the latest data
44
+ */
45
+ force?: boolean;
19
46
  }
20
47
  declare const defaultOptions: {
21
48
  /**
@@ -25,18 +52,19 @@ declare const defaultOptions: {
25
52
  */
26
53
  apiEndpoint: string;
27
54
  };
28
- declare function getLatestVersionBatch(packages: string[], options?: ApiOptions): Promise<ResolvedPackageVersion[]>;
29
- declare function getLatestVersion(name: string, options?: ApiOptions): Promise<ResolvedPackageVersion>;
30
- declare function getVersionsBatch(packages: string[], options?: ApiOptions): Promise<PackageManifest[]>;
31
- declare function getVersions(name: string, options?: ApiOptions): Promise<PackageManifest>;
55
+ declare function getLatestVersionBatch(packages: string[], options?: GetLatestVersionOptions): Promise<ResolvedPackageVersion[]>;
56
+ declare function getLatestVersion(name: string, options?: GetLatestVersionOptions): Promise<ResolvedPackageVersion>;
57
+ declare function getVersionsBatch(packages: string[], options?: GetVersionsOptions): Promise<PackageVersionsInfo[]>;
58
+ declare function getVersions(name: string, options?: GetVersionsOptions): Promise<PackageVersionsInfo>;
32
59
 
33
60
  declare const NPM_REGISTRY = "https://registry.npmjs.org/";
34
61
  /**
35
62
  * Lightweight replacement of `npm-registry-fetch` function `pickRegistry`'
36
63
  *
37
- * @param scope - npm scope
64
+ * @param scope - scope of package, get from 'npm-package-arg'
38
65
  * @param npmConfigs - npm configs, read from `.npmrc` file
66
+ * @param defaultRegistry - default registry, default to 'https://registry.npmjs.org/'
39
67
  */
40
- declare function pickRegistry(scope: string, npmConfigs: Record<string, string>, defaultRegistry?: string): string;
68
+ declare function pickRegistry(scope: string | null | undefined, npmConfigs: Record<string, unknown>, defaultRegistry?: string): string;
41
69
 
42
- export { type ApiOptions, NPM_REGISTRY, type PackageManifest, type ResolvedPackageVersion, defaultOptions, getLatestVersion, getLatestVersionBatch, getVersions, getVersionsBatch, pickRegistry };
70
+ export { type FetchOptions, type GetLatestVersionOptions, type GetVersionsOptions, NPM_REGISTRY, type PackageManifest, type ResolvedPackageVersion, defaultOptions, getLatestVersion, getLatestVersionBatch, getVersions, getVersionsBatch, pickRegistry };
package/dist/index.mjs CHANGED
@@ -1,5 +1,3 @@
1
- import { $fetch } from 'ofetch';
2
-
3
1
  const defaultOptions = {
4
2
  /**
5
3
  * API endpoint for fetching package versions
@@ -10,17 +8,11 @@ const defaultOptions = {
10
8
  };
11
9
  async function getLatestVersionBatch(packages, options = {}) {
12
10
  const {
13
- apiEndpoint = defaultOptions.apiEndpoint
11
+ apiEndpoint = defaultOptions.apiEndpoint,
12
+ fetch: fetchApi = fetch
14
13
  } = options;
15
- const data = await $fetch(
16
- packages.join("+"),
17
- {
18
- baseURL: apiEndpoint,
19
- query: {
20
- force: options.force ? true : void 0
21
- }
22
- }
23
- );
14
+ const query = options.force ? "?force=true" : "";
15
+ const data = await fetchApi(new URL(packages.join("+") + query, apiEndpoint)).then((r) => r.json());
24
16
  if (!Array.isArray(data))
25
17
  return [data];
26
18
  return data;
@@ -31,17 +23,16 @@ async function getLatestVersion(name, options = {}) {
31
23
  }
32
24
  async function getVersionsBatch(packages, options = {}) {
33
25
  const {
34
- apiEndpoint = defaultOptions.apiEndpoint
26
+ apiEndpoint = defaultOptions.apiEndpoint,
27
+ fetch: fetchApi = fetch
35
28
  } = options;
36
- const data = await $fetch(
37
- `/versions/${packages.join("+")}`,
38
- {
39
- baseURL: apiEndpoint,
40
- query: {
41
- force: options.force ? true : void 0
42
- }
43
- }
44
- );
29
+ let query = [
30
+ options.force ? "force=true" : "",
31
+ options.loose ? "loose=true" : ""
32
+ ].filter(Boolean).join("&");
33
+ if (query)
34
+ query = `?${query}`;
35
+ const data = await fetchApi(new URL(`/versions/${packages.join("+")}${query}`, apiEndpoint)).then((r) => r.json());
45
36
  if (!Array.isArray(data))
46
37
  return [data];
47
38
  return data;
@@ -53,8 +44,8 @@ async function getVersions(name, options = {}) {
53
44
 
54
45
  const NPM_REGISTRY = "https://registry.npmjs.org/";
55
46
  function pickRegistry(scope, npmConfigs, defaultRegistry = NPM_REGISTRY) {
56
- let registry = scope && npmConfigs[`${scope.replace(/^@?/, "@")}:registry`];
57
- if (!registry && npmConfigs.scope) {
47
+ let registry = scope ? npmConfigs[`${scope.replace(/^@?/, "@")}:registry`] : void 0;
48
+ if (!registry && typeof npmConfigs.scope === "string") {
58
49
  registry = npmConfigs[`${npmConfigs.scope.replace(/^@?/, "@")}:registry`];
59
50
  }
60
51
  if (!registry) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fast-npm-meta",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.2.1",
5
5
  "description": "Get npm package metadata",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -35,9 +35,6 @@
35
35
  "files": [
36
36
  "dist"
37
37
  ],
38
- "dependencies": {
39
- "ofetch": "^1.3.4"
40
- },
41
38
  "scripts": {
42
39
  "build": "unbuild",
43
40
  "dev": "unbuild --stub"