https://github.com/lassjs/is-valid-npm-name
Checks if a given string is a valid npm package name adhering to npm rules and best practice
https://github.com/lassjs/is-valid-npm-name
check checker name node npm package pkg rules valid validator yarn
Last synced: 10 months ago
JSON representation
Checks if a given string is a valid npm package name adhering to npm rules and best practice
- Host: GitHub
- URL: https://github.com/lassjs/is-valid-npm-name
- Owner: lassjs
- License: mit
- Created: 2017-09-08T05:13:04.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-20T17:19:20.000Z (over 6 years ago)
- Last Synced: 2025-04-14T03:13:25.093Z (about 1 year ago)
- Topics: check, checker, name, node, npm, package, pkg, rules, valid, validator, yarn
- Language: JavaScript
- Homepage: https://lass.js.org
- Size: 180 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# is-valid-npm-name
[](https://semaphoreci.com/niftylettuce/is-valid-npm-name)
[](https://codecov.io/gh/lassjs/is-valid-npm-name)
[](https://github.com/sindresorhus/xo)
[](https://github.com/prettier/prettier)
[](https://lass.js.org)
[](<>)
> Checks if a given string is a valid npm package name adhering to [npm rules](https://docs.npmjs.com/files/package.json#name) and best practice
## Table of Contents
* [Install](#install)
* [Usage](#usage)
* [Error Strings](#error-strings)
* [Rule Exemption](#rule-exemption)
* [Contributors](#contributors)
* [License](#license)
## Install
[npm][]:
```sh
npm install is-valid-npm-name
```
[yarn][]:
```sh
yarn add is-valid-npm-name
```
## Usage
```js
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** | |
## License
[MIT](LICENSE) © [Nick Baugh](http://niftylettuce.com/)
##
[npm]: https://www.npmjs.com/
[yarn]: https://yarnpkg.com/