• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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) {
22    warn = null
23    strict = true
24  }
25  if (!strict) {
26    strict = false
27  }
28  if (!warn || data.private) {
29    warn = function (msg) { /* noop */ }
30  }
31
32  if (data.scripts &&
33      data.scripts.install === 'node-gyp rebuild' &&
34      !data.scripts.preinstall) {
35    data.gypfile = true
36  }
37  fixer.warn = function () {
38    warn(makeWarning.apply(null, arguments))
39  }
40  thingsToFix.forEach(function (thingName) {
41    fixer['fix' + ucFirst(thingName)](data, strict)
42  })
43  data._id = data.name + '@' + data.version
44}
45
46function ucFirst (string) {
47  return string.charAt(0).toUpperCase() + string.slice(1)
48}
49