Check whether a package or organization name is available on npm

Overview

npm-name

Check whether a package or organization name is available on npm

Install

$ npm install npm-name

Usage

import npmName from 'npm-name';

// Check a package name
console.log(await npmName('chalk'));
//=> false

// Check an organization name
console.log(await npmName('@ava'));
//=> false

console.log(await npmName('@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, options?)

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.

Returns a Promise<boolean> of whether the given name is available.

name

Type: string

Name to check.

options

Type: object

registryUrl

Default: User's configured npm registry URL.

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.

npmNameMany(names, options?)

Check whether multiple package/organization names are available (not registered) on npm.

Returns a Promise<Map> of name and status.

import {npmNameMany} from 'npm-name';

const result = await npmNameMany(['chalk', '@sindresorhus/is', 'abc123']);

console.log(result.get('chalk'));
//=> false

console.log(result.get('@sindresorhus/is'));
//=> false

console.log(result.get('abc123'));
//=> true

names

Type: string[]

Multiple names to check.

options

Type: object

Same as npmName().

Related

Comments
  • Update to reflect new registry typosquat restrictions

    Update to reflect new registry typosquat restrictions

    Issuehunt badges

    recently the npm registry was updated to restrict available pkg names based on the presence of a pkg with a similar name whose diff is only punctuation. this is an awesome tool that helps people find pkg names, i'd like to make a PR to help account for this new registry restriction. if welcome, PR incoming.

    for more details on the change, see this blog post: http://blog.npmjs.org/post/168978377570/new-package-moniker-rules


    IssueHunt Summary

    bconnorwhite bconnorwhite has been rewarded.

    Backers (Total: $80.00)

    Submitted pull Requests


    Tips

    enhancement help wanted :gift: Rewarded on Issuehunt 
    opened by ashleygwilliams 8
  • Handle typosquat restrictions

    Handle typosquat restrictions

    Fixes https://github.com/sindresorhus/npm-name/issues/15

    This solution should account for punctuation using is-name-taken, which caches the bulk of npm package names so that only the last few need to be fetched.

    One thing to note is that npmName.many is kinda slow as it causes multiple requests to sync the list of packages. Instead, the list of names should really all be sent off to is-name-taken together. If anyone wants, I can add this as well.


    IssueHunt Summary

    Referenced issues

    This pull request has been submitted to:


    opened by bconnorwhite 7
  • Allow overriding the registry URL

    Allow overriding the registry URL

    In some cases (e.g. in np - see sindresorhus/np#350 and sindresorhus/np#317) you want to resolve a package name for a given registry that wasn't configured to be the user's default registry. I think that npm-name should still use the registry URL returned by registry-url as the default one, but also accept an optional registry URL as the second argument, i.e. npmName(name, [registryUrl]) and npmName.many(names, [registryUrl]).

    // cc @weekens @jdziat

    opened by itaisteinherz 5
  • Support for organization

    Support for organization

    NPM has organization which work along with the scoped package features. Therefore, I think it would be handy to do:

    npm-name @elemental
    

    The @ to detect an org instead of a package name.

    enhancement help wanted 
    opened by rmariuzzo 5
  • 404 code break npm-name behavior

    404 code break npm-name behavior

    Reproduced with node v0.10.35 and v0.12.2

    ➜  ~  npm i -g npm-name
    /usr/local/bin/npm-name -> /usr/local/lib/node_modules/npm-name/cli.js
    [email protected] /usr/local/lib/node_modules/npm-name
    ├── [email protected] ([email protected])
    ├── [email protected] ([email protected])
    └── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
    
    ➜  ~  npm-name aaabbbccc
    
    events.js:72
            throw er; // Unhandled 'error' event
                  ^
    GotError: https://registry.npmjs.org/aaabbbccc response code is 404 (Not Found)
        at /usr/local/lib/node_modules/npm-name/node_modules/got/index.js:120:12
        at BufferStream.<anonymous> (/usr/local/lib/node_modules/npm-name/node_modules/got/node_modules/read-all-stream/index.js:52:3)
        at BufferStream.emit (events.js:117:20)
        at finishMaybe (/usr/local/lib/node_modules/npm-name/node_modules/got/node_modules/read-all-stream/node_modules/readable-stream/lib/_stream_writable.js:460:14)
        at endWritable (/usr/local/lib/node_modules/npm-name/node_modules/got/node_modules/read-all-stream/node_modules/readable-stream/lib/_stream_writable.js:469:3)
        at BufferStream.Writable.end (/usr/local/lib/node_modules/npm-name/node_modules/got/node_modules/read-all-stream/node_modules/readable-stream/lib/_stream_writable.js:436:5)
        at IncomingMessage.onend (_stream_readable.js:502:10)
        at IncomingMessage.g (events.js:180:16)
        at IncomingMessage.emit (events.js:117:20)
        at _stream_readable.js:944:16
    
    opened by ghoullier 5
  • Revert moniker replacements

    Revert moniker replacements

    We cannot do replacements in the requested name as the npm API does not support the shortened names so the only way to check if a name would be rejected for typosquatting is to try every combination of characters in every position which seems impractical and would perform really bad.

    So until npm exposes an API to check names, we're just checking the name as-is.

    Fixes #25

    opened by silverwind 4
  • Flaky results, especially with `pinto`

    Flaky results, especially with `pinto`

    pinto - at time of writing - isn't take on npm. The results for this specific word are super flaky though, and I don't know why. It fails about 80% of the time, returning false when it should obviously return true since it's available. There don't seem to be any errors.

    You can run the below code in this RunKit notebook.

    const isAvailable = require('npm-name')
    const partition = require('lodash.partition')
    
    const fetch = word => {
      const array = new Array(100).fill(word)
      return Promise.all(array.map(isAvailable))
        .then(names => partition(names, Boolean))
    }
    
    const test = async word => {
      const [avail, not] = await fetch(word)
      console.log(`${word}: ${avail.length} / ${not.length}`)
    }
    
    await test('pinto')
    
    bug help wanted 
    opened by haltcase 3
  • TypeError: Cannot destructure property 'statusCode' of 'error.response' as it is undefined.

    TypeError: Cannot destructure property 'statusCode' of 'error.response' as it is undefined.

    Seems like you don't handle case when there is no response from "got". But I can't figure out why does it happen inside got. Npm registry url is available. Help pls.

    npm-name: 6.0.1 System: Linux Node: 12.18

    It is thrown in this part of code:

    try {
    if (isOrganization) {
    	await got.head(npmOrganizationUrl + name.toLowerCase(), {timeout: 10000});
    } else {
    	await got.head(registryUrl + name.toLowerCase(), {timeout: 10000, headers});
    }
    
    return false;
    } catch (error) {
    const {statusCode} = error.response;
    
    if (statusCode === 404) {
    	return true;
    }
    
    if (isScopedPackage && statusCode === 401) {
    	return true;
    }
    
    throw error;
    }
    
    opened by VintorezVS 2
  • Support for scoped packages

    Support for scoped packages

    I was just searching names for my project when I saw that this package does not support scoped packages.

    Check https://runkit.com/embed/mzsivagq3l35 for a demo.

    enhancement 
    opened by ghost 2
  • Dependency `electron` not found (in `got`) when used in Next project

    Dependency `electron` not found (in `got`) when used in Next project

    Ran into an interesting issue using this module in a nextjs project.

    This dependency was not found:  
    * electron in ./node_modules/npm-name/node_modules/got/index.js  
    To install it, you can run: npm install --save electron
    

    I don't want to introduce electron to the project obviously, and looking through the source of got, I'm not sure why it's being required.

    Any insight into this?

    opened by lacymorrow 2
  • Proxy support

    Proxy support

    Hi, I work on a government company that uses proxies, so this npm-name module was preventing me to use the generator-node from the yeoman team because of the lack of proxy support. As this is a utility for npm name discovery I believe that it makes sense to depend on the configurations from the npmrc file. Firstly it looks for the npmrc file, then for a https-proxy entry and then passes the url of the proxy to got. I had to use proxy-agent because tunnel was giving me a "Parse Error" error. Hope it helps :-)

    Alex

    opened by alexsantos 2
Releases(v7.1.0)
  • v7.1.0(Sep 20, 2022)

  • v7.0.1(May 2, 2022)

  • v7.0.0(Apr 17, 2021)

    Breaking

    • Require Node.js 12 59517d7
    • This package is now pure ESM. Please read this.
    • npmName.many moved to a named export npmNameMany

    Improvements

    • Handle typosquat restrictions (#42) 8a86ee6

    https://github.com/sindresorhus/npm-name/compare/v6.0.1...v7.0.0

    Source code(tar.gz)
    Source code(zip)
  • v6.0.1(Jun 26, 2020)

  • v6.0.0(Feb 22, 2020)

    Breaking

    • Require Node.js 10 053eb8a

    Enhancements

    • Throw aggregate error for npmName.many() (#38) 6fb0e67

    https://github.com/sindresorhus/npm-name/compare/v5.5.0...v6.0.0

    Source code(tar.gz)
    Source code(zip)
  • v5.5.0(Jun 30, 2019)

    Enhancements:

    • Add support for checking availability of organization names (#36) dc699a0

    https://github.com/sindresorhus/npm-name/compare/v5.4.0...v5.5.0

    Source code(tar.gz)
    Source code(zip)
  • v5.4.0(Jun 10, 2019)

  • v5.3.0(Mar 31, 2019)

    • Refactor TypeScript definition to CommonJS compatible export (#34) 7b1a6b8

    https://github.com/sindresorhus/npm-name/compare/v5.2.0...v5.3.0

    Source code(tar.gz)
    Source code(zip)
  • v5.2.0(Mar 10, 2019)

  • v5.1.0(Feb 4, 2019)

Owner
Sindre Sorhus
Full-Time Open-Sourcerer. Wants more empathy & kindness in open source. Focuses on Swift & JavaScript. Makes macOS apps, CLI tools, npm packages. Likes unicorns
Sindre Sorhus
Check NPM package licenses

NPM License Checker As of v17.0.0 the failOn and onlyAllow arguments take semicolons as delimeters instead of commas. Some license names contain comma

Dav Glass 1.5k Dec 29, 2022
Check ipo allotment result from CLI. [WIP for bulk check]

# Check your ipo allotment result via CLI Install node js and run these commands > clone the repo > cd checkipo-cli > npm

Yaman Sarabariya 4 Oct 12, 2022
:eyeglasses: Node.js module that tells you when your package npm dependencies are out of date.

Node.js module that tells you when your package npm dependencies are out of date. Getting Started Install Node.js. Install david: cd /your/project/dir

Alan Shaw 953 Dec 25, 2022
Open the npm page, Yarn page, or GitHub repo of a package

npm-home Open the npm page, Yarn page, or GitHub repo of a package Install $ npm install --global npm-home Usage $ npm-home --help Usage $ npm

Sindre Sorhus 180 Dec 18, 2022
Package manager faster than NPM

Pine Script holder that runs faster than NPM and yarn Pine is a npm and yarn run like module, that allows you to organize your scripts and run them FA

Darkling 4 Jul 10, 2021
Check if the internet connection is up

is-online Check if the internet connection is up Works in Node.js and the browser (with a bundler). In the browser you have navigator.onLine, but it's

Sindre Sorhus 1.1k Jan 1, 2023
NodeJS built CLI, allows to spell check in 14 languages, get Coleman-Liau Index and build hash Pyramids

Magic CLI ?? ?? NodeJS built CLI, allows to spell check in 14 languages, get Coleman-Liau Index and build hash Pyramids Installing Install dependencie

Lucas 3 Sep 27, 2022
A better `npm publish`

np A better npm publish Why Interactive UI Ensures you are publishing from your release branch (main and master by default) Ensures the working direct

Sindre Sorhus 6.9k Jan 2, 2023
Uses marked-terminal to render a README.md for any npm module in the terminal.

modhelp Uses marked-terminal to render a README.md for any npm module in the terminal. Now with built-in pager! Page up/down, arrow keys to scroll lin

Jason Livesay 23 Feb 8, 2022
Add a hungry turtle to your terminal and feed it every time you mistype 'npm' as 'nom'

Nom Does this ever happen to you? You happily code away on a project, navigating the command line like a pro, testing, error logging, installing packa

Meike Hankewicz 5 Apr 26, 2022
An npm module to run Snowflake in a headless browser to help censored users connect to the Tor network.

snowflake-cli An npm module to run Snowflake in a headless browser to help censored users connect to the Tor network. Note: depending on your environm

yan 8 Mar 24, 2022
Translations with speech synthesis in your terminal as a node package

Normit Normit is an easy way to translate stuff in your terminal. You can check out its Ruby gem version termit. Installation npm install normit -g Us

Paweł Urbanek 234 Jan 1, 2023
Check whether a website is up or down

is-up Check whether a website is up or down using the isitup.org API Install $ npm install is-up Usage const isUp = require('is-up'); (async () => {

Sindre Sorhus 384 Dec 7, 2022
Check in, check the weather, Check out.

☀️ Just-Weather ??️ Hi, Welcome! Just Weather is a Web App designed for Fast Real-Time Weather queries in combination with well Thought Out Visual Des

Miguel Ángel 6 Aug 7, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
Detect npm packages by author name in your package-lock.json or yarn.lock.

detect-package-by-author Detect npm packages by author name in your package-lock.json or yarn.lock. Install Install with npm: # Not Yet Publish # npm

azu 2 Jan 11, 2022
npm i uuid, npm i nodemon, npm i commander

goit-nodejs-hw-01 Получаем и выводим весь список контактов в виде таблицы (console.table) node index.js --action list Получаем контакт по id node inde

Oksana Banshchykova 3 Jul 5, 2022
You can detect requested client full IP details with this package. (isp, organization, location, residential/data center, proxy, etc)

requested client ip details Install the package npm npm install @sarequl/client-ip-details yarn yarn add @sarequl/client-ip-details example with expr

Sarequl Basar 8 Oct 13, 2022
Check NPM package licenses

NPM License Checker As of v17.0.0 the failOn and onlyAllow arguments take semicolons as delimeters instead of commas. Some license names contain comma

Dav Glass 1.5k Dec 29, 2022