1 # validate-npm-package-name
3 Give me a string and I'll tell you if it's a valid `npm` package name.
5 This package exports a single synchronous function that takes a `string` as
6 input and returns an object with two properties:
8 - `validForNewPackages` :: `Boolean`
9 - `validForOldPackages` :: `Boolean`
13 - [Naming rules](#naming-rules)
14 - [Examples](#examples)
15 + [Valid Names](#valid-names)
16 + [Invalid Names](#invalid-names)
17 - [Legacy Names](#legacy-names)
23 Below is a list of rules that valid `npm` package name should conform to.
25 - package name length should be greater than zero
26 - all the characters in the package name must be lowercase i.e., no uppercase or mixed case names are allowed
27 - package name *can* consist of hyphens
28 - package name must *not* contain any non-url-safe characters (since name ends up being part of a URL)
29 - package name should not start with `.` or `_`
30 - package name should *not* contain any leading or trailing spaces
31 - package name *cannot* be the same as a node.js/io.js core module nor a reserved/blacklisted name. For example, the following names are invalid:
36 - package name length cannot exceed 214
44 var validate = require("validate-npm-package-name")
46 validate("some-package")
47 validate("example.com")
48 validate("under_score")
49 validate("123numeric")
51 validate("@npm/thingy")
52 validate("@jane/foo.js")
55 All of the above names are valid, so you'll get this object back:
59 validForNewPackages: true,
60 validForOldPackages: true
67 validate(" leading-space:and:weirdchars")
70 That was never a valid package name, so you get this:
74 validForNewPackages: false,
75 validForOldPackages: false,
77 'name cannot contain leading or trailing spaces',
78 'name can only contain URL-friendly characters'
85 In the old days of npm, package names were wild. They could have capital
86 letters in them. They could be really long. They could be the name of an
87 existing module in node core.
89 If you give this function a package name that **used to be valid**, you'll see
90 a change in the value of `validForNewPackages` property, and a warnings array
94 validate("cRaZY-paCkAgE-with-mixed-case-and-more-than-214-characters-----------------------------------------------------------------------------------------------------------------------------------------------------------")
101 validForNewPackages: false,
102 validForOldPackages: true,
104 "name can no longer contain capital letters",
105 "name can no longer contain more than 214 characters"