Created
May 11, 2014 03:48
-
-
Save isaacs/42e85b9ceba79d8fdb7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Validation function called by couch vdu | |
function validName (name) { | |
if (!name) return false | |
var n = name.replace(/^\s+|\s+$/g, '') | |
if (!n || n.charAt(0) === "." | |
|| !n.match(/^[a-zA-Z0-9]/) | |
|| n.match(/[\/\(\)&\?#\|<>@:%\s\\\*'"!~`]/) | |
|| n.toLowerCase() === "node_modules" | |
|| n !== encodeURIComponent(n) | |
|| n.toLowerCase() === "favicon.ico") { | |
return false | |
} | |
return n | |
} | |
console.log(validName("foo=bar")) | |
console.log(validName("foo~bar")) | |
// normalize-package-data/lib/fixer.js:293 | |
function ensureValidName (name, strict) { | |
if (name.charAt(0) === "." || | |
name.match(/[\/@\s\+%:]/) || | |
name !== encodeURIComponent(name) || | |
(strict && name !== name.toLowerCase()) || | |
name.toLowerCase() === "node_modules" || | |
name.toLowerCase() === "favicon.ico") { | |
return new Error("Invalid name: " + JSON.stringify(name)) | |
} | |
return name | |
} | |
console.log(ensureValidName("foo=bar")) | |
console.log(ensureValidName("foo~bar")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment