Front end of the Slack clone application.

normalize.js 1.3KB

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