{"size": 825, "ext": "js", "max_stars_repo_path": "node_modules/install-if-needed/lib/filter-package-deps.js", "max_stars_repo_name": "adventurejeff/generative-art", "max_stars_repo_stars_event_min_datetime": "2021-01-05T16:45:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-05T16:45:07.000Z", "max_issues_repo_path": "lib/filter-package-deps.js", "max_issues_repo_name": "zeke/install-if-needed", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/filter-package-deps.js", "max_forks_repo_name": "zeke/install-if-needed", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.78125, "max_line_length": 57, "alphanum_fraction": 0.6375757576}
var types = [
  'dependencies', 
  'devDependencies', 
  'optionalDependencies'
]

// Given a package.json and list of deps,
// will filter down to those that haven't yet
// been installed
module.exports = function (package, opt) {
  opt = opt || {}

  return types.reduce(function (dict, type) {
    var actualDeps = package[type] || {}
    var actualNames = Object.keys(actualDeps)
    var desired = [].concat(opt[type]).filter(Boolean)

    // only installs packages that aren't in package.json
    var needed = desired.filter(function (pkgName) {
      // split scoped package names
      var parts = pkgName.split(/(.+)@/).filter(Boolean)
      var name = parts[0]
      var exists = actualNames.indexOf(name) >= 0
      return !exists
    })

    if (needed.length)
      dict[type] = needed
    return dict
  }, {})
}
