Check whether a package name is available on npm
$ npm install npm-name
const npmName = require('npm-name');
(async () => {
console.log(await npmName('chalk'));
//=> false
const result = await npmName.many(['chalk', '@sindresorhus/is', 'abc123']);
console.log(result.get('chalk'));
//=> false
console.log(result.get('@sindresorhus/is'));
//=> false
console.log(result.get('abc123'));
//=> true
try {
await npmName('_ABC');
} catch (error) {
console.log(error.message);
// Invalid package name: _ABC
// - name cannot start with an underscore
// - name can no longer contain capital letters
}
})();
Returns a Promise<boolean>
of whether the given name is available.
Type: string
Name to check.
Returns a Promise<Map>
of name and status.
Type: string[]
Multiple names to check.
- npm-name-cli - CLI for this module
MIT © Sindre Sorhus