Movatterモバイル変換


[0]ホーム

URL:


validate-npm-package-name
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/validate-npm-package-name package

6.0.2 • Public • Published

Give me a string and I'll tell you if it's a validnpm package name.

This package exports a single synchronous function that takes astring asinput and returns an object with two properties:

  • validForNewPackages ::Boolean
  • validForOldPackages ::Boolean

Contents

Naming Rules

Below is a list of rules that validnpm package name should conform to.

  • package name length should be greater than zero
  • all the characters in the package name must be lowercase i.e., no uppercase or mixed case names are allowed
  • package namecan consist of hyphens
  • package name mustnot contain any non-url-safe characters (since name ends up being part of a URL)
  • package name should not start with. or_
  • package name shouldnot contain any spaces
  • package name shouldnot contain any of the following characters:~)('!*
  • package namecannot be the same as a node.js/io.js core module nor a reserved/excluded name. For example, the following names are invalid:
    • http
    • stream
    • node_modules
    • favicon.ico
  • package name length cannot exceed 214

Examples

Valid Names

varvalidate=require("validate-npm-package-name")validate("some-package")validate("example.com")validate("under_score")validate("123numeric")validate("@npm/thingy")validate("@jane/foo.js")

All of the above names are valid, so you'll get this object back:

{validForNewPackages:true,validForOldPackages:true}

Invalid Names

validate("excited!")validate(" leading-space:and:weirdchars")

That was never a valid package name, so you get this:

{validForNewPackages:false,validForOldPackages:false,errors:['name cannot contain leading or trailing spaces','name can only contain URL-friendly characters']}

Legacy Names

In the old days of npm, package names were wild. They could have capitalletters in them. They could be really long. They could be the name of anexisting module in node core.

If you give this function a package name thatused to be valid, you'll seea change in the value ofvalidForNewPackages property, and a warnings arraywill be present:

validate("eLaBorAtE-paCkAgE-with-mixed-case-and-more-than-214-characters-----------------------------------------------------------------------------------------------------------------------------------------------------------")

returns:

{validForNewPackages:false,validForOldPackages:true,warnings:["name can no longer contain capital letters","name can no longer contain more than 214 characters"]}

Tests

npm installnpmtest

License

ISC

Provenance

Share feedback

Package Sidebar

Install

npm i validate-npm-package-name

Weekly Downloads

16,729,911

Version

6.0.2

License

ISC

Unpacked Size

7.89 kB

Total Files

4

Last publish

Collaborators

  • gar
  • saquibkhan
  • npm-cli-ops
  • reggi
  • hashtagchris
  • owlstronaut

[8]ページ先頭

©2009-2025 Movatter.jp