@jayf0x/npm-exists 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jonatan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # npm-exists
2
+
3
+ > Check if an npm package name is taken. Zero dependencies, uses native `fetch`.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@jayf0x/npm-exists.svg)](https://npmjs.com/package/@jayf0x/npm-exists)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@jayf0x/npm-exists.svg)](https://npmjs.com/package/@jayf0x/npm-exists)
7
+ [![license](https://img.shields.io/npm/l/@jayf0x/npm-exists.svg)](LICENSE)
8
+ [![node](https://img.shields.io/node/v/@jayf0x/npm-exists.svg)](package.json)
9
+
10
+ ## Features
11
+
12
+ - **Zero dependencies** — uses native `fetch` (Node 18+)
13
+ - **Returns full metadata** — not just a boolean; get version, description, author, etc.
14
+ - **Custom registry** — point at any npm-compatible registry
15
+ - **CLI included** — `npm-exists <package-name>`
16
+ - **Dual ESM/CJS** — works in both module systems
17
+ - **TypeScript types** included
18
+
19
+ ## Install
20
+
21
+ ```sh
22
+ npm install @jayf0x/npm-exists
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### API
28
+
29
+ ```js
30
+ import npmExists from '@jayf0x/npm-exists'
31
+
32
+ // Check if a package exists — returns metadata or false
33
+ const details = await npmExists('react')
34
+ if (details) {
35
+ console.log(`react@${details['dist-tags'].latest} exists`)
36
+ } else {
37
+ console.log('Package name is free!')
38
+ }
39
+ ```
40
+
41
+ ```js
42
+ // With a custom registry
43
+ const details = await npmExists('my-pkg', 'https://my.private.registry.io')
44
+ ```
45
+
46
+ ```js
47
+ // Build your own fetch — getNpmUrl lets you use axios, ky, etc.
48
+ import { getNpmUrl } from '@jayf0x/npm-exists'
49
+ import axios from 'axios'
50
+
51
+ const url = getNpmUrl('react')
52
+ const { data } = await axios.get(url)
53
+ ```
54
+
55
+ ### Exports
56
+
57
+ | Export | Description |
58
+ |---|---|
59
+ | `npmExists(pkg, registry?)` | Returns package metadata (`object`) or `false` |
60
+ | `getNpmUrl(pkg, registry?)` | Returns the registry URL for a package |
61
+
62
+ ### CLI
63
+
64
+ ```sh
65
+ # Global install
66
+ npm install -g npm-exists
67
+
68
+ npm-exists react
69
+ # ✓ react@19.1.0 exists on npm
70
+
71
+ npm-exists my-unique-package-name-xyz
72
+ # ✗ my-unique-package-name-xyz is not registered on npm
73
+
74
+ # Exit codes: 0 = exists, 1 = not found, 2 = bad usage
75
+
76
+ # Custom registry
77
+ npm-exists my-pkg https://my.private.registry.io
78
+ ```
79
+
80
+ ### One-off via npx
81
+
82
+ ```sh
83
+ npx @jayf0x/npm-exists react
84
+ ```
85
+
86
+ ## API Reference
87
+
88
+ ### `npmExists(pkg, registry?)`
89
+
90
+ | Param | Type | Default | Description |
91
+ |---|---|---|---|
92
+ | `pkg` | `string` | — | Package name (scoped names like `@scope/pkg` are supported) |
93
+ | `registry` | `string` | `https://registry.npmjs.org` | Registry base URL |
94
+
95
+ **Returns:** `Promise<object \| false>`
96
+ - `object` — full registry metadata (includes `name`, `dist-tags`, `versions`, `description`, …)
97
+ - `false` — package does not exist
98
+
99
+ **Throws** if the registry returns an unexpected non-404 error (network issue, auth failure, etc.).
100
+
101
+ ---
102
+
103
+ ### `getNpmUrl(pkg, registry?)`
104
+
105
+ Returns the full URL used to query the registry. Useful when you want to make the request yourself.
106
+
107
+ ```js
108
+ getNpmUrl('react')
109
+ // → 'https://registry.npmjs.org/react'
110
+
111
+ getNpmUrl('@scope/pkg')
112
+ // → 'https://registry.npmjs.org/%40scope%2Fpkg'
113
+ ```
114
+
115
+ ## Requirements
116
+
117
+ Node 18+ (uses native `fetch`).
118
+
119
+ ## License
120
+
121
+ MIT
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ import { npmExists } from '../dist/index.js'
3
+
4
+ const [pkg, registry] = process.argv.slice(2)
5
+
6
+ if (!pkg) {
7
+ console.error('Usage: npm-exists <package-name> [registry-url]')
8
+ process.exit(2)
9
+ }
10
+
11
+ const result = await npmExists(pkg, registry)
12
+
13
+ if (result) {
14
+ const version = result['dist-tags']?.latest ?? '?'
15
+ console.log(`✓ ${pkg}@${version} exists on npm`)
16
+ process.exit(0)
17
+ } else {
18
+ console.log(`✗ ${pkg} is not registered on npm`)
19
+ process.exit(1)
20
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const DEFAULT_REGISTRY = "https://registry.npmjs.org";
4
+ function getNpmUrl(pkg, registry = DEFAULT_REGISTRY) {
5
+ return `${registry.replace(/\/$/, "")}/${encodeURIComponent(pkg)}`;
6
+ }
7
+ async function npmExists(pkg, registry) {
8
+ const url = getNpmUrl(pkg, registry);
9
+ const res = await fetch(url);
10
+ if (res.status === 404) return false;
11
+ if (!res.ok) throw new Error(`npm registry error: HTTP ${res.status}`);
12
+ return res.json();
13
+ }
14
+ exports.default = npmExists;
15
+ exports.getNpmUrl = getNpmUrl;
16
+ exports.npmExists = npmExists;
@@ -0,0 +1,5 @@
1
+ export declare function getNpmUrl(pkg: string, registry?: string): string
2
+
3
+ export declare function npmExists(pkg: string, registry?: string): Promise<Record<string, unknown> | false>
4
+
5
+ export default npmExists
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ const DEFAULT_REGISTRY = "https://registry.npmjs.org";
2
+ function getNpmUrl(pkg, registry = DEFAULT_REGISTRY) {
3
+ return `${registry.replace(/\/$/, "")}/${encodeURIComponent(pkg)}`;
4
+ }
5
+ async function npmExists(pkg, registry) {
6
+ const url = getNpmUrl(pkg, registry);
7
+ const res = await fetch(url);
8
+ if (res.status === 404) return false;
9
+ if (!res.ok) throw new Error(`npm registry error: HTTP ${res.status}`);
10
+ return res.json();
11
+ }
12
+ export {
13
+ npmExists as default,
14
+ getNpmUrl,
15
+ npmExists
16
+ };
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@jayf0x/npm-exists",
3
+ "version": "2.0.1",
4
+ "description": "Check if an npm package name is taken. Zero dependencies, uses native fetch.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "types": "./dist/index.d.ts",
16
+ "bin": {
17
+ "npm-exists": "bin/npm-exists.js"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "bin",
22
+ "README.md",
23
+ "LICENSE"
24
+ ],
25
+ "scripts": {
26
+ "build": "vite build && node scripts/generate-types.js",
27
+ "test": "vitest run",
28
+ "test:watch": "vitest",
29
+ "release": "bash publish-npm.sh",
30
+ "prepublishOnly": "bun run build && bun test"
31
+ },
32
+ "keywords": [
33
+ "npm",
34
+ "package",
35
+ "exists",
36
+ "check",
37
+ "registry",
38
+ "available",
39
+ "taken",
40
+ "name",
41
+ "lookup",
42
+ "cli",
43
+ "zero-deps",
44
+ "fetch",
45
+ "esm",
46
+ "typescript"
47
+ ],
48
+ "author": {
49
+ "name": "Jay Verstraete",
50
+ "email": "jonatanverstraete@outlook.com"
51
+ },
52
+ "license": "MIT",
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/jayverstraete/npm-exists.git"
56
+ },
57
+ "homepage": "https://github.com/jayverstraete/npm-exists#readme",
58
+ "bugs": {
59
+ "url": "https://github.com/jayverstraete/npm-exists/issues"
60
+ },
61
+ "engines": {
62
+ "node": ">=18"
63
+ },
64
+ "devDependencies": {
65
+ "vite": "^6.0.0",
66
+ "vitest": "^2.0.0"
67
+ }
68
+ }