The Wayback Machine - https://web.archive.org/web/20221027172346/https://github.com/lassjs/is-valid-npm-name
Skip to content

lassjs/is-valid-npm-name

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

is-valid-npm-name

build status code coverage code style styled with prettier made with lass license

Checks if a given string is a valid npm package name adhering to npm rules and best practice

Table of Contents

Install

npm:

npm install is-valid-npm-name

yarn:

yarn add is-valid-npm-name

Usage

const isValidNpmName = require('is-valid-npm-name');

const check = isValidNpmName('fs');

// `check` is `true` or a String (e.g. why it was not a valid npm name)
if (check !== true) {
  console.error(check);
  // 'package name cannot use built-in core Node module name'
}

Error Strings

  • package name must be a String
  • remove trailing spaces from start and end of package name
  • package name cannot be more than 214 characters
  • package name cannot start with a dot nor underscore
  • package name cannot have uppercase letters
  • scoped package name must start with "@" character
  • scoped package name has an extra "@" character
  • scoped package name must be in the format of @myorg/package
  • scoped package name has an extra "/" character
  • package name cannot use built-in core Node module name
  • package name had non-URL-safe characters

Rule Exemption

We ignore a single npm rule, which is:

don't put "js" or "node" in the name

This is due to the sheer number of npm package name squatters.

Sometimes it's absolutely necessary to affix with js or node.

Contributors

Name Website
Nick Baugh http://niftylettuce.com/

License

MIT © Nick Baugh

About

Checks if a given string is a valid npm package name adhering to npm rules and best practice

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published