<commit_before>/**
 * Information about what the website considers to be an out of date or up to date dependency
 */

var david = require('david');
var semver = require('semver');
var cache = require('memory-cache');
var registry = require('./registry');
var config = require('config');

// When a user publishes a package, delete cached david info
registry.on('change', function(change) {
  cache.del(change.doc.name);
});

function isPinned (version) {
  if (version === '*' || version === 'latest') {
    return false;
  }

  var range = semver.validRange(version, true);

  if (range && range.indexOf('>=') === 0) {
    return false;
  }

  return true;
}

function normaliseDeps (deps) {
  if (Array.isArray(deps)) {
    deps = deps.reduce(function(d, depName) {
      d[depName] = '*';
      return d;
    }, {});
  }
  return deps;
}

function getCachedDependencies (manifest, opts) {
  var pkgs = {};
  var deps = normaliseDeps(manifest[opts.dev ? 'devDependencies' : 'dependencies'] || {});
  var depNames = Object.keys(deps);

  if (!depNames.length) {
    return pkgs;
  }
<commit_msg>Fix non object package.json dependencies/devDependencies<commit_after>/**
 * Information about what the website considers to be an out of date or up to date dependency
 */

var david = require('david');
var semver = require('semver');
var cache = require('memory-cache');
var registry = require('./registry');
var config = require('config');

// When a user publishes a package, delete cached david info
registry.on('change', function(change) {
  cache.del(change.doc.name);
});

function isPinned (version) {
  if (version === '*' || version === 'latest') {
    return false;
  }

  var range = semver.validRange(version, true);

  if (range && range.indexOf('>=') === 0) {
    return false;
  }

  return true;
}

function normaliseDeps (deps) {
  if (Array.isArray(deps)) {
    deps = deps.reduce(function(d, depName) {
      d[depName] = '*';
      return d;
    }, {});
  } else if (Object.prototype.toString.call(deps) == "[object String]") {
    var depName = deps;
    deps = {};
    deps[depName] = "*";
  } else if (!(deps instanceof Object)) {
    deps = {};
  }
  return deps;
}

function getCachedDependencies (manifest, opts) {
  var pkgs = {};
  var deps = normaliseDeps(manifest[opts.dev ? 'devDependencies' : 'dependencies'] || {});
  var depNames = Object.keys(deps);

  if (!depNames.length) {
    return pkgs;
  }

{'fraction_non_alphanumeric': 0.1633744855967078, 'fraction_numerical': 0.0008230452674897119, 'mean_word_length': 3.6393129770992365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6732550', 'n_tokens_mistral': 813, 'n_tokens_neox': 783, 'n_words': 216}