validate-npm-package-name
Advanced tools
+7
-1
@@ -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} |
+11
-1
| 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 @@ |
+1
-1
| { | ||
| "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", |
+15
-1
@@ -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() | ||
| }) |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
6604
10.77%123
18.27%