lyxaira.glass 74ca844f42 Actualizacion cambios generados: seccion #12, #14 y #15. | 4 vuotta sitten | |
---|---|---|
.. | ||
.nyc_output | 4 vuotta sitten | |
test | 4 vuotta sitten | |
.npmignore | 4 vuotta sitten | |
.travis.yml | 4 vuotta sitten | |
LICENSE | 4 vuotta sitten | |
README.md | 4 vuotta sitten | |
index.js | 4 vuotta sitten | |
package.json | 4 vuotta sitten |
Give me a string and I’ll tell you if it’s a valid npm
package name.
This package exports a single synchronous function that takes a string
as
input and returns an object with two properties:
validForNewPackages
:: Boolean
validForOldPackages
:: Boolean
Below is a list of rules that valid npm
package name should conform to.
.
or _
~)('!*
var validate = require("validate-npm-package-name")
validate("some-package")
validate("example.com")
validate("under_score")
validate("123numeric")
validate("excited!")
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
}
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'
]
}
In the old days of npm, package names were wild. They could have capital letters in them. They could be really long. They could be the name of an existing module in node core.
If you give this function a package name that used to be valid, you’ll see
a change in the value of validForNewPackages
property, and a warnings array
will 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"
]
}
npm install
npm test
ISC