Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 10, 2024
1 parent 6dd7c4c commit 16ad804
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Expand Up @@ -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.
*/
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions package.json
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Expand Up @@ -4,8 +4,8 @@
## Install

```
$ npm install npm-name
```sh
npm install npm-name
```

## Usage
Expand Down Expand Up @@ -48,7 +48,7 @@ Returns a `Promise<boolean>` of whether the given name is available.

Type: `string`

Name to check.
The name to check.

#### options

Expand All @@ -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.

Expand Down
1 change: 0 additions & 1 deletion 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/';
Expand Down

0 comments on commit 16ad804

Please sign in to comment.