Check whether a package name is available on npm
JavaScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.editorconfig
.gitattributes Require Node.js 6 Jun 2, 2018
.gitignore
.npmrc Add 10 seconds timeout and meta tweaks Jun 30, 2017
.travis.yml Require Node.js 6 Jun 2, 2018
index.js Throw custom error on invalid package name (#22) Jun 2, 2018
license
package.json 4.0.0 Jun 2, 2018
readme.md Require Node.js 6 Jun 2, 2018
test.js Throw custom error on invalid package name (#22) Jun 2, 2018

readme.md

npm-name Build Status

Check whether a package name is available on npm

Install

$ npm install npm-name

Usage

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
	}
})();

API

npmName(name)

Returns a promise for a boolean.

name

Type: String

Name to check.

npmName.many(names)

Returns a promise for a Map of name/status.

names

Type: Array

Multiple names to check.

Related

License

MIT © Sindre Sorhus