audit.js
function buildDependencyObjectLookup(data, lookup, parentPath) {
  if (lookup == undefined) {
    lookup = {};
  }

  parentPath = parentPath || '';

  for(var k in data.dependencies) {
    var dep = data.dependencies[k];
    depPath = parentPath + '/' + dep.name;

    var lookupKey = 'UNKNOWN'; //If we can't find a key below, something's wrong.
    var depToStore = dep;
    if (dep.name) {
      lookupKey = dep.name + '@' + dep.version
    } else if (dep._from) {
      lookupKey = dep._from;
    } else if (dep.requiredBy) {
      // If we can't find the node_modules folder, we'll get 'requiredBy' instead.
      lookupKey = k + "@" + dep.requiredBy;
      depToStore = extractDep(data.dependencies[k]);
    }

    var existing = lookup[lookupKey];
    if (existing) {
      existing.depPaths.push(depPath);
    } else {
      lookup[lookupKey] = depToStore;
      lookup[lookupKey].depPaths = [depPath];
    }

    buildDependencyObjectLookup(dep, lookup, depPath);
  }
  return lookup;
}
function buildDependencyObjectLookup(data, lookup, parentPath) {
  if (lookup == undefined) {
    lookup = {};
  }

  parentPath = parentPath || '';

  for(var k in data.dependencies) {
    var dep = data.dependencies[k];
    depPath = parentPath + '/' + dep.name;

    var lookupKey = 'UNKNOWN'; //If we can't find a key below, something's wrong.
    var depToStore = dep;
    if (dep.name) {
      lookupKey = dep.name + '@' + dep.version
    } else if (dep._from) {
      lookupKey = dep._from;
    } else if (dep.requiredBy) {
      // If we can't find the node_modules folder, we'll get 'requiredBy' instead.
      lookupKey = k + "@" + dep.requiredBy;
      depToStore = extractDep(data.dependencies[k]);
    }

    var existing = lookup[lookupKey];
    if (existing) {
      existing.depPaths.push(depPath);
    } else {
      lookup[lookupKey] = depToStore;
      lookup[lookupKey].depPaths = [depPath];
    }

    buildDependencyObjectLookup(dep, lookup, depPath);
  }
  return lookup;
}
function buildDependencyObjectLookup ( data , lookup , parentPath ) { if ( lookup == undefined ) { lookup = { } ; } parentPath = parentPath || '' ; for ( var k in data . dependencies ) { var dep = data . dependencies [ k ] ; depPath = parentPath + '/' + dep . name ; var lookupKey = 'UNKNOWN' ; //If we can't find a key below, something's wrong. var depToStore = dep ; if ( dep . name ) { lookupKey = dep . name + '@' + dep . version } else if ( dep . _from ) { lookupKey = dep . _from ; } else if ( dep . requiredBy ) { // If we can't find the node_modules folder, we'll get 'requiredBy' instead. lookupKey = k + "@" + dep . requiredBy ; depToStore = extractDep ( data . dependencies [ k ] ) ; } var existing = lookup [ lookupKey ] ; if ( existing ) { existing . depPaths . push ( depPath ) ; } else { lookup [ lookupKey ] = depToStore ; lookup [ lookupKey ] . depPaths = [ depPath ] ; } buildDependencyObjectLookup ( dep , lookup , depPath ) ; } return lookup ; }
Each specific package@version is only represented with the complete
dependency definitions once in the tree, but might not be where we need it.
Therefore we make a special lookup table
of package@version = [Object] which will be referenced later.
Each specific package