fast-npm-meta 0.1.0 → 0.1.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,11 @@ 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
+ const query = options.force ? "?force=true" : "";
32
+ const data = await fetchApi(new URL(`/versions/${packages.join("+")}${query}`, apiEndpoint)).then((r) => r.json());
47
33
  if (!Array.isArray(data))
48
34
  return [data];
49
35
  return data;
@@ -55,8 +41,8 @@ async function getVersions(name, options = {}) {
55
41
 
56
42
  const NPM_REGISTRY = "https://registry.npmjs.org/";
57
43
  function pickRegistry(scope, npmConfigs, defaultRegistry = NPM_REGISTRY) {
58
- let registry = scope && npmConfigs[`${scope.replace(/^@?/, "@")}:registry`];
59
- if (!registry && npmConfigs.scope) {
44
+ let registry = scope ? npmConfigs[`${scope.replace(/^@?/, "@")}:registry`] : void 0;
45
+ if (!registry && typeof npmConfigs.scope === "string") {
60
46
  registry = npmConfigs[`${npmConfigs.scope.replace(/^@?/, "@")}:registry`];
61
47
  }
62
48
  if (!registry) {
package/dist/index.d.cts CHANGED
@@ -16,6 +16,10 @@ interface ResolvedPackageVersion {
16
16
  interface ApiOptions {
17
17
  force?: boolean;
18
18
  apiEndpoint?: string;
19
+ /**
20
+ * Fetch function
21
+ */
22
+ fetch?: typeof fetch;
19
23
  }
20
24
  declare const defaultOptions: {
21
25
  /**
@@ -34,9 +38,10 @@ declare const NPM_REGISTRY = "https://registry.npmjs.org/";
34
38
  /**
35
39
  * Lightweight replacement of `npm-registry-fetch` function `pickRegistry`'
36
40
  *
37
- * @param scope - npm scope
41
+ * @param scope - scope of package, get from 'npm-package-arg'
38
42
  * @param npmConfigs - npm configs, read from `.npmrc` file
43
+ * @param defaultRegistry - default registry, default to 'https://registry.npmjs.org/'
39
44
  */
40
- declare function pickRegistry(scope: string, npmConfigs: Record<string, string>, defaultRegistry?: string): string;
45
+ declare function pickRegistry(scope: string | null | undefined, npmConfigs: Record<string, unknown>, defaultRegistry?: string): string;
41
46
 
42
47
  export { type ApiOptions, NPM_REGISTRY, type PackageManifest, type ResolvedPackageVersion, defaultOptions, getLatestVersion, getLatestVersionBatch, getVersions, getVersionsBatch, pickRegistry };
package/dist/index.d.mts CHANGED
@@ -16,6 +16,10 @@ interface ResolvedPackageVersion {
16
16
  interface ApiOptions {
17
17
  force?: boolean;
18
18
  apiEndpoint?: string;
19
+ /**
20
+ * Fetch function
21
+ */
22
+ fetch?: typeof fetch;
19
23
  }
20
24
  declare const defaultOptions: {
21
25
  /**
@@ -34,9 +38,10 @@ declare const NPM_REGISTRY = "https://registry.npmjs.org/";
34
38
  /**
35
39
  * Lightweight replacement of `npm-registry-fetch` function `pickRegistry`'
36
40
  *
37
- * @param scope - npm scope
41
+ * @param scope - scope of package, get from 'npm-package-arg'
38
42
  * @param npmConfigs - npm configs, read from `.npmrc` file
43
+ * @param defaultRegistry - default registry, default to 'https://registry.npmjs.org/'
39
44
  */
40
- declare function pickRegistry(scope: string, npmConfigs: Record<string, string>, defaultRegistry?: string): string;
45
+ declare function pickRegistry(scope: string | null | undefined, npmConfigs: Record<string, unknown>, defaultRegistry?: string): string;
41
46
 
42
47
  export { type ApiOptions, NPM_REGISTRY, type PackageManifest, type ResolvedPackageVersion, defaultOptions, getLatestVersion, getLatestVersionBatch, getVersions, getVersionsBatch, pickRegistry };
package/dist/index.d.ts CHANGED
@@ -16,6 +16,10 @@ interface ResolvedPackageVersion {
16
16
  interface ApiOptions {
17
17
  force?: boolean;
18
18
  apiEndpoint?: string;
19
+ /**
20
+ * Fetch function
21
+ */
22
+ fetch?: typeof fetch;
19
23
  }
20
24
  declare const defaultOptions: {
21
25
  /**
@@ -34,9 +38,10 @@ declare const NPM_REGISTRY = "https://registry.npmjs.org/";
34
38
  /**
35
39
  * Lightweight replacement of `npm-registry-fetch` function `pickRegistry`'
36
40
  *
37
- * @param scope - npm scope
41
+ * @param scope - scope of package, get from 'npm-package-arg'
38
42
  * @param npmConfigs - npm configs, read from `.npmrc` file
43
+ * @param defaultRegistry - default registry, default to 'https://registry.npmjs.org/'
39
44
  */
40
- declare function pickRegistry(scope: string, npmConfigs: Record<string, string>, defaultRegistry?: string): string;
45
+ declare function pickRegistry(scope: string | null | undefined, npmConfigs: Record<string, unknown>, defaultRegistry?: string): string;
41
46
 
42
47
  export { type ApiOptions, 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,11 @@ 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
+ const query = options.force ? "?force=true" : "";
30
+ const data = await fetchApi(new URL(`/versions/${packages.join("+")}${query}`, apiEndpoint)).then((r) => r.json());
45
31
  if (!Array.isArray(data))
46
32
  return [data];
47
33
  return data;
@@ -53,8 +39,8 @@ async function getVersions(name, options = {}) {
53
39
 
54
40
  const NPM_REGISTRY = "https://registry.npmjs.org/";
55
41
  function pickRegistry(scope, npmConfigs, defaultRegistry = NPM_REGISTRY) {
56
- let registry = scope && npmConfigs[`${scope.replace(/^@?/, "@")}:registry`];
57
- if (!registry && npmConfigs.scope) {
42
+ let registry = scope ? npmConfigs[`${scope.replace(/^@?/, "@")}:registry`] : void 0;
43
+ if (!registry && typeof npmConfigs.scope === "string") {
58
44
  registry = npmConfigs[`${npmConfigs.scope.replace(/^@?/, "@")}:registry`];
59
45
  }
60
46
  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.1.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"