audit.js
function getDependencyList(depMap, depLookup) {
  var results = [];
  var lookup = {};
  var keys = Object.keys(depMap);

  for(var i = 0; i < keys.length; i++) {
    var name = keys[i];

    // The value of o depends on the type of structure we are passed
    var o = depMap[name];

    var spec = o.version ? name + "@" + o.version : name + "@" + o;
    var version = o.version ? o.version : o;
    var depPaths = o.depPaths ? o.depPaths : [spec];

    // Only add a dependency once
    // We need both the local and global "auditLookup" tables.
    // The global lookup is used to ensure we only audit a
    // dependency once, but cannot be done at the same level
    // as the local lookup since the sub-dependencies are not
    // available at all locations of the dependency tree (depMap).
    if(lookup[spec] == undefined && auditLookup[spec] == undefined) {
      lookup[spec] = true;
			auditLookup[spec] = true;
			results.push({"pm": config.get("pm"), "name": name, "version": version, "depPaths": depPaths});

      // If there is a possibility of recursive dependencies...
      if (o.version) {
        var dataDeps = getDepsFromDataObject(o, depLookup);
        if(dataDeps) {
          var deps = getDependencyList(dataDeps, depLookup);

          if(deps != undefined) {
            results = results.concat(deps);
          }
        }
      }
    }
  }
  return results;
}
function getDependencyList(depMap, depLookup) {
  var results = [];
  var lookup = {};
  var keys = Object.keys(depMap);

  for(var i = 0; i < keys.length; i++) {
    var name = keys[i];

    // The value of o depends on the type of structure we are passed
    var o = depMap[name];

    var spec = o.version ? name + "@" + o.version : name + "@" + o;
    var version = o.version ? o.version : o;
    var depPaths = o.depPaths ? o.depPaths : [spec];

    // Only add a dependency once
    // We need both the local and global "auditLookup" tables.
    // The global lookup is used to ensure we only audit a
    // dependency once, but cannot be done at the same level
    // as the local lookup since the sub-dependencies are not
    // available at all locations of the dependency tree (depMap).
    if(lookup[spec] == undefined && auditLookup[spec] == undefined) {
      lookup[spec] = true;
			auditLookup[spec] = true;
			results.push({"pm": config.get("pm"), "name": name, "version": version, "depPaths": depPaths});

      // If there is a possibility of recursive dependencies...
      if (o.version) {
        var dataDeps = getDepsFromDataObject(o, depLookup);
        if(dataDeps) {
          var deps = getDependencyList(dataDeps, depLookup);

          if(deps != undefined) {
            results = results.concat(deps);
          }
        }
      }
    }
  }
  return results;
}
function getDependencyList ( depMap , depLookup ) { var results = [ ] ; var lookup = { } ; var keys = Object . keys ( depMap ) ; for ( var i = 0 ; i < keys . length ; i ++ ) { var name = keys [ i ] ; // The value of o depends on the type of structure we are passed var o = depMap [ name ] ; var spec = o . version ? name + "@" + o . version : name + "@" + o ; var version = o . version ? o . version : o ; var depPaths = o . depPaths ? o . depPaths : [ spec ] ; // Only add a dependency once // We need both the local and global "auditLookup" tables. // The global lookup is used to ensure we only audit a // dependency once, but cannot be done at the same level // as the local lookup since the sub-dependencies are not // available at all locations of the dependency tree (depMap). if ( lookup [ spec ] == undefined && auditLookup [ spec ] == undefined ) { lookup [ spec ] = true ; auditLookup [ spec ] = true ; results . push ( { "pm" : config . get ( "pm" ) , "name" : name , "version" : version , "depPaths" : depPaths } ) ; // If there is a possibility of recursive dependencies... if ( o . version ) { var dataDeps = getDepsFromDataObject ( o , depLookup ) ; if ( dataDeps ) { var deps = getDependencyList ( dataDeps , depLookup ) ; if ( deps != undefined ) { results = results . concat ( deps ) ; } } } } } return results ; }
Recursively get a flat list of dependency objects. This is simpler for
subsequent code to handle then a tree of dependencies.

Depending on the command line arguments, the dependencies may includes
a mix of production, development, optional, etc. dependencies.
Recursively get a flat list of dependency objects . This is simpler for subsequent code to handle then a tree of dependencies .