validate-npm-package-name
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -5,3 +5,2 @@ var valid = require("./") | ||
validate("example.com") // => {valid: true} | ||
validate("CAPITALS") // => {valid: true} | ||
validate("under_score") // => {valid: true} | ||
@@ -16,1 +15,8 @@ validate("123numeric") // => {valid: true} | ||
validate("_flodash") // => {valid: false, errors:["name cannot start with an underscore"]} | ||
validate("CAPITALS") // => {valid: false, errors:["name must be lowercase"]} | ||
// Nowadays, package names have to be lowercase | ||
// To validate older packages, do this: | ||
validate("CAPITALS", | ||
{allowMixedCase: true}) // => {valid: true} |
12
index.js
var scopedPackagePattern = new RegExp("^(?:@([^/]+?)[/])?([^/]+?)$") | ||
var validate = module.exports = function(name) { | ||
var validate = module.exports = function(name, options) { | ||
var errors = [] | ||
if (!options) { | ||
options = { | ||
allowMixedCase: false | ||
} | ||
} | ||
if (name === null) { | ||
@@ -42,2 +48,6 @@ errors.push("name cannot be null") | ||
if (name.toLowerCase() !== name && !options.allowMixedCase) { | ||
errors.push("name must be lowercase") | ||
} | ||
if (encodeURIComponent(name) !== name) { | ||
@@ -44,0 +54,0 @@ |
{ | ||
"name": "validate-npm-package-name", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Give me a string and I'll tell you if it's a valid npm package name", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,3 +9,2 @@ var valid = require("..") | ||
t.deepEqual(valid("example.com"), {valid: true}) | ||
t.deepEqual(valid("CAPITAL-LETTERS"), {valid: true}) | ||
t.deepEqual(valid("under_score"), {valid: true}) | ||
@@ -22,2 +21,6 @@ t.deepEqual(valid("period.js"), {valid: true}) | ||
t.deepEqual(valid(""), { | ||
valid: false, | ||
errors: ["name length must be greater than zero"]}) | ||
t.deepEqual(valid(".start-with-period"), { | ||
@@ -51,3 +54,14 @@ valid: false, | ||
// Legacy Mixed-Case | ||
t.deepEqual(valid("CAPITAL-LETTERS", {allowMixedCase: true}), {valid: true}) | ||
t.deepEqual(valid("CAPITAL-LETTERS"), { | ||
valid: false, | ||
errors: ["name must be lowercase"]}) | ||
t.end() | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6604
123