diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 981d57a..346585c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,11 +10,11 @@ jobs: fail-fast: false matrix: node-version: - - 18 - 20 + - 18 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.d.ts b/index.d.ts index e124673..b69cbd7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,7 +2,7 @@ export class InvalidNameError extends Error {} export type Options = { /** - Registry URL to check name availability against. + The registry URL to check name availability against. Default: User's configured npm registry URL. */ @@ -14,7 +14,7 @@ Check whether a package/organization name is available (not registered) on npm. An organization name should start with `@` and should not be a scoped package. -@param name - Name to check. +@param name - The name to check. @returns Whether the given name is available. @example diff --git a/index.js b/index.js index aaf3416..c624187 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ const normalizeUrl = url => url.replace(/\/$/, '') + '/'; const npmOrganizationUrl = 'https://www.npmjs.com/org/'; const request = async (name, options) => { - const registryUrl = normalizeUrl(options.registryUrl || configuredRegistryUrl); + const registryUrl = normalizeUrl(options.registryUrl ?? configuredRegistryUrl); const isOrganization = organizationRegex.test(name); if (isOrganization) { @@ -27,7 +27,7 @@ const request = async (name, options) => { const isValid = validate(name); if (!isValid.validForNewPackages) { - const notices = [...isValid.warnings || [], ...isValid.errors || []].map(v => `- ${v}`); + const notices = [...isValid.warnings ?? [], ...isValid.errors ?? []].map(v => `- ${v}`); notices.unshift(`Invalid package name: ${name}`); const error = new InvalidNameError(notices.join('\n')); error.warnings = isValid.warnings; @@ -56,7 +56,7 @@ const request = async (name, options) => { await ky.head(packageUrl, {timeout: 10_000, headers}); return false; } catch (error) { - const statusCode = (error.response || {status: 500}).status; + const statusCode = error.response?.status ?? 500; if (statusCode === 404) { // Disabled as it's often way too slow: https://github.com/sindresorhus/npm-name-cli/issues/30 diff --git a/package.json b/package.json index 7c47d85..e3dd3e2 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,11 @@ "url": "https://sindresorhus.com" }, "type": "module", - "exports": "./index.js", + "exports": { + "types": "./index.d.ts", + "default": "./index.js" + }, + "sideEffects": false, "engines": { "node": ">=18" }, @@ -39,13 +43,12 @@ "ky": "^1.2.0", "lodash.zip": "^4.2.0", "org-regex": "^1.0.0", - "p-map": "^5.5.0", - "registry-auth-token": "^4.2.2", + "p-map": "^7.0.1", + "registry-auth-token": "^5.0.2", "registry-url": "^6.0.1", - "validate-npm-package-name": "^3.0.0" + "validate-npm-package-name": "^5.0.0" }, "devDependencies": { - "aggregate-error": "^4.0.0", "ava": "^6.1.1", "tsd": "^0.30.4", "unique-string": "^3.0.0", diff --git a/readme.md b/readme.md index df797a7..4731391 100644 --- a/readme.md +++ b/readme.md @@ -4,8 +4,8 @@ ## Install -``` -$ npm install npm-name +```sh +npm install npm-name ``` ## Usage @@ -48,7 +48,7 @@ Returns a `Promise` of whether the given name is available. Type: `string` -Name to check. +The name to check. #### options @@ -58,7 +58,7 @@ Type: `object` Default: User's configured npm registry URL. -Registry URL to check name availability against. +THe registry URL to check name availability against. **Note:** You're unlikely to need this option. Most use-cases are best solved by using the default. You should only use this option if you need to check a package name against a specific registry. diff --git a/test.js b/test.js index dc769f3..b77c53f 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,5 @@ import test from 'ava'; import uniqueString from 'unique-string'; -import AggregateError from 'aggregate-error'; import npmName, {npmNameMany, InvalidNameError} from './index.js'; const registryUrl = 'https://registry.yarnpkg.com/';