1module.exports = normalize 2 3var fixer = require("./fixer") 4normalize.fixer = fixer 5 6var makeWarning = require("./make_warning") 7 8var fieldsToFix = ['name','version','description','repository','modules','scripts' 9 ,'files','bin','man','bugs','keywords','readme','homepage','license'] 10var otherThingsToFix = ['dependencies','people', 'typos'] 11 12var thingsToFix = fieldsToFix.map(function(fieldName) { 13 return ucFirst(fieldName) + "Field" 14}) 15// two ways to do this in CoffeeScript on only one line, sub-70 chars: 16// thingsToFix = fieldsToFix.map (name) -> ucFirst(name) + "Field" 17// thingsToFix = (ucFirst(name) + "Field" for name in fieldsToFix) 18thingsToFix = thingsToFix.concat(otherThingsToFix) 19 20function normalize (data, warn, strict) { 21 if(warn === true) warn = null, strict = true 22 if(!strict) strict = false 23 if(!warn || data.private) warn = function(msg) { /* noop */ } 24 25 if (data.scripts && 26 data.scripts.install === "node-gyp rebuild" && 27 !data.scripts.preinstall) { 28 data.gypfile = true 29 } 30 fixer.warn = function() { warn(makeWarning.apply(null, arguments)) } 31 thingsToFix.forEach(function(thingName) { 32 fixer["fix" + ucFirst(thingName)](data, strict) 33 }) 34 data._id = data.name + "@" + data.version 35} 36 37function ucFirst (string) { 38 return string.charAt(0).toUpperCase() + string.slice(1); 39} 40