<commit_before>var q = require('q'),
    exec  = require('child_process').exec,
    fs    = require('fs'),
    utils = require('./Utils');

// A library/module is already installed if its folder exists
// within node_modules
// TODO: Why not just use require.resolve?
module.exports.isLibInstalled = function (lib) {
  var installDir = './node_modules/' + lib,
      deferred = q.defer();

  fs.exists(installDir, function (exists) {
    deferred.resolve(exists);
  });

  return deferred.promise;
};

// Installs the given library as a dev dependency
// and resolve when done or if the lib was already installed
module.exports.installLib = function (lib) {
  var deferred = q.defer(),
      // Get the grunt package to install
      installCmd = 'npm install --save-dev ' + lib;<commit_msg>Helper to install if a lib is needed<commit_after>var q = require('q'),
    exec  = require('child_process').exec,
    fs    = require('fs'),
    utils = require('./Utils');

// Resolves if the lib is already installed or when it's done
// installing, if missing
module.exports.installIfNecessary = function (lib) {
  return this.isLibInstalled(lib)
    .when(function (isInstalled) {
      if (isInstalled) return;

      return this.installLib(lib);
    }.bind(this));
};

// A library/module is already installed if its folder exists
// within node_modules
// TODO: Why not just use require.resolve?
module.exports.isLibInstalled = function (lib) {
  var installDir = './node_modules/' + lib,
      deferred = q.defer();

  fs.exists(installDir, function (exists) {
    deferred.resolve(exists);
  });

  return deferred.promise;
};

// Installs the given library as a dev dependency
// and resolve when done or if the lib was already installed
module.exports.installLib = function (lib) {
  var deferred = q.defer(),
      // Get the grunt package to install
      installCmd = 'npm install --save-dev ' + lib;
{'fraction_non_alphanumeric': 0.12440944881889764, 'fraction_numerical': 0.0, 'mean_word_length': 3.3024830699774266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '72943', 'n_tokens_mistral': 562, 'n_tokens_neox': 545, 'n_words': 187}