<commit_before>var q = require('q');
var fs = require('fs');
var path = require('path');
var util = require('util');
var semver = require('semver');
var child_process = require('child_process');
var concat = require('concat-stream');

exports.name = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8')).name;

var nvmCommand = function(command) {
  var deferred = q.defer();
  var stdout, stderr;
  var cmd = child_process.spawn('bash',
    ['-c', 'source ~/.nvm/nvm.sh; nvm ' + command]);

  cmd.stdout.pipe(concat(function(data) {
    stdout = data;
  }));

  cmd.stderr.pipe(concat(function(data) {
    stderr = data;
  }));

  cmd.on('close', function(code) {
    if (code === 0) { deferred.resolve({ stdout: stdout, stderr: stderr }); }
    else { deferred.reject('nvm exited with status: ' + code); }
  });

  return deferred.promise;
};

var parseVersions = function(output) {
  var string = output.stdout.toString()
    .replace(/\x1b[^m]*m/g, '')
    .replace(/^->/gm, '');
  return string.split('\n')
  .map(function(line) { return line.trim(); })
  .filter(function(line) { return line && !line.match(/current|system|->/); });
};

var listVersions = function() {
  // find all of the versions of node installed by nvm.
  return q()
  .then(function() { return nvmCommand('list'); })
  .then(parseVersions);
};

var installedVersion = function(matching) {
  return q()
  .then(function() { return listVersions(); })
  .then(function(versions) {
    var version = null;
    versions.forEach(function(v) {
      if (semver.satisfies(v, matching)) {
        if (!version || semver.gt(v, version)) {
          version = v;
        }
      }
    });
    return version;
  });
};

var match = function(version) {
  return q()
  .then(function() { return installedVersion(version); })
  .then(function(use) {
    var command = util.format('nvm use %s > /dev/null;', use);
    var result = { version: use, command: command };
    return use ? result : q.reject('no version matching ' + version);
  });
};

module.exports = {
  match: match,
  _parseVersions: parseVersions<commit_msg>Fixed name export.<commit_after>var q = require('q');
var fs = require('fs');
var path = require('path');
var util = require('util');
var semver = require('semver');
var child_process = require('child_process');
var concat = require('concat-stream');

var name = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8')).name;

var nvmCommand = function(command) {
  var deferred = q.defer();
  var stdout, stderr;
  var cmd = child_process.spawn('bash',
    ['-c', 'source ~/.nvm/nvm.sh; nvm ' + command]);

  cmd.stdout.pipe(concat(function(data) {
    stdout = data;
  }));

  cmd.stderr.pipe(concat(function(data) {
    stderr = data;
  }));

  cmd.on('close', function(code) {
    if (code === 0) { deferred.resolve({ stdout: stdout, stderr: stderr }); }
    else { deferred.reject('nvm exited with status: ' + code); }
  });

  return deferred.promise;
};

var parseVersions = function(output) {
  var string = output.stdout.toString()
    .replace(/\x1b[^m]*m/g, '')
    .replace(/^->/gm, '');
  return string.split('\n')
  .map(function(line) { return line.trim(); })
  .filter(function(line) { return line && !line.match(/current|system|->/); });
};

var listVersions = function() {
  // find all of the versions of node installed by nvm.
  return q()
  .then(function() { return nvmCommand('list'); })
  .then(parseVersions);
};

var installedVersion = function(matching) {
  return q()
  .then(function() { return listVersions(); })
  .then(function(versions) {
    var version = null;
    versions.forEach(function(v) {
      if (semver.satisfies(v, matching)) {
        if (!version || semver.gt(v, version)) {
          version = v;
        }
      }
    });
    return version;
  });
};

var match = function(version) {
  return q()
  .then(function() { return installedVersion(version); })
  .then(function(use) {
    var command = util.format('nvm use %s > /dev/null;', use);
    var result = { version: use, command: command };
    return use ? result : q.reject('no version matching ' + version);
  });
};

module.exports = {
  name: name,
  match: match,
  _parseVersions: parseVersions
{'fraction_non_alphanumeric': 0.1833293754452624, 'fraction_numerical': 0.0014248397055331276, 'mean_word_length': 3.529032258064516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5636034', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1391, 'n_words': 324}