@jayf0x/npm-exists 2.0.3 → 2.0.4

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/README.md CHANGED
@@ -34,6 +34,12 @@ const url = await npmExists('my-pkg', 'https://my.private.registry.io')
34
34
  const url = await npmExists('react', { silent: true })
35
35
  ```
36
36
 
37
+ ```js
38
+ // Full metadata (GET instead of HEAD)
39
+ const meta = await npmExists('react', { full: true })
40
+ // → { name, description, 'dist-tags', versions, ... } | false
41
+ ```
42
+
37
43
  ```js
38
44
  // Build your own fetch
39
45
  import { getNpmUrl } from '@jayf0x/npm-exists'
@@ -58,10 +64,10 @@ Exit codes: `0` exists · `1` not found · `2` bad usage
58
64
  | Param | Type | Description |
59
65
  |---|---|---|
60
66
  | `pkg` | `string` | Package name |
61
- | `registryOrOptions` | `string \| { registry?, silent? }` | Registry URL or options object |
62
- | `options` | `{ silent? }` | When `silent: true`, errors return `false` instead of throwing |
67
+ | `registryOrOptions` | `string \| { registry?, silent?, full? }` | Registry URL or options object |
68
+ | `options` | `{ silent?, full? }` | `silent`: errors `false`; `full`: GET full metadata instead of HEAD |
63
69
 
64
- Returns `Promise<string \| false>` the npm page URL or `false` if not found.
70
+ Returns `Promise<string \| Record<string, unknown> \| false>`
65
71
 
66
72
  ### `getNpmUrl(pkg, registry?)`
67
73
 
package/dist/index.cjs CHANGED
@@ -12,18 +12,23 @@ function getPageUrl(pkg, registry) {
12
12
  async function npmExists(pkg, registryOrOptions, options) {
13
13
  let registry = DEFAULT_REGISTRY;
14
14
  let silent = false;
15
+ let full = false;
15
16
  if (typeof registryOrOptions === "string") {
16
17
  registry = registryOrOptions;
17
18
  silent = options?.silent ?? false;
19
+ full = options?.full ?? false;
18
20
  } else if (registryOrOptions != null) {
19
21
  registry = registryOrOptions.registry ?? DEFAULT_REGISTRY;
20
22
  silent = registryOrOptions.silent ?? false;
23
+ full = registryOrOptions.full ?? false;
21
24
  }
22
25
  try {
23
- const res = await fetch(getNpmUrl(pkg, registry));
26
+ const res = await fetch(getNpmUrl(pkg, registry), {
27
+ method: full ? "GET" : "HEAD"
28
+ });
24
29
  if (res.status === 404) return false;
25
30
  if (!res.ok) throw new Error(`npm registry error: HTTP ${res.status}`);
26
- return getPageUrl(pkg, registry);
31
+ return full ? res.json() : getPageUrl(pkg, registry);
27
32
  } catch (err) {
28
33
  if (silent) return false;
29
34
  throw err;
package/dist/index.d.ts CHANGED
@@ -2,13 +2,20 @@ export declare function getNpmUrl(pkg: string, registry?: string): string
2
2
 
3
3
  export interface NpmExistsOptions {
4
4
  registry?: string
5
+ /** Suppress errors — network/registry failures return false instead of throwing */
5
6
  silent?: boolean
7
+ /** Fetch full registry metadata instead of a lightweight HEAD check */
8
+ full?: boolean
6
9
  }
7
10
 
11
+ /**
12
+ * Checks if an npm package exists.
13
+ * Returns the npm page URL by default, or full registry metadata with `full: true`.
14
+ */
8
15
  export declare function npmExists(
9
16
  pkg: string,
10
17
  registryOrOptions?: string | NpmExistsOptions,
11
- options?: Pick<NpmExistsOptions, 'silent'>
12
- ): Promise<string | false>
18
+ options?: Pick<NpmExistsOptions, 'silent' | 'full'>
19
+ ): Promise<string | Record<string, unknown> | false>
13
20
 
14
21
  export default npmExists
package/dist/index.js CHANGED
@@ -10,18 +10,23 @@ function getPageUrl(pkg, registry) {
10
10
  async function npmExists(pkg, registryOrOptions, options) {
11
11
  let registry = DEFAULT_REGISTRY;
12
12
  let silent = false;
13
+ let full = false;
13
14
  if (typeof registryOrOptions === "string") {
14
15
  registry = registryOrOptions;
15
16
  silent = options?.silent ?? false;
17
+ full = options?.full ?? false;
16
18
  } else if (registryOrOptions != null) {
17
19
  registry = registryOrOptions.registry ?? DEFAULT_REGISTRY;
18
20
  silent = registryOrOptions.silent ?? false;
21
+ full = registryOrOptions.full ?? false;
19
22
  }
20
23
  try {
21
- const res = await fetch(getNpmUrl(pkg, registry));
24
+ const res = await fetch(getNpmUrl(pkg, registry), {
25
+ method: full ? "GET" : "HEAD"
26
+ });
22
27
  if (res.status === 404) return false;
23
28
  if (!res.ok) throw new Error(`npm registry error: HTTP ${res.status}`);
24
- return getPageUrl(pkg, registry);
29
+ return full ? res.json() : getPageUrl(pkg, registry);
25
30
  } catch (err) {
26
31
  if (silent) return false;
27
32
  throw err;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayf0x/npm-exists",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Check if an npm package name is taken. Zero dependencies, uses native fetch.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -46,8 +46,8 @@
46
46
  "typescript"
47
47
  ],
48
48
  "author": {
49
- "name": "Jay Verstraete",
50
- "email": "jonatanverstraete@outlook.com"
49
+ "name": "Jay Fox",
50
+ "email": "jjay56883@gmail.com"
51
51
  },
52
52
  "license": "MIT",
53
53
  "repository": {