<commit_before>var Promise = require('es6-promise').Promise;


module.exports.promisify = function (func) {
  return function () {
    var args = Array.prototype.slice.apply(arguments);

    return new Promise(function (resolve, reject) {
      func.apply({}, args.concat(function (err, value) {
        if (err) {
          reject(err);
        } else {
          resolve(value);
        }
      }));
    });
  };
};


module.exports.getType = function (ct, url) {
  ct = ct.toLowerCase();
  if (ct.substr(0, 8) === 'text/css') {
    return 'css';
  }
  if (/javascript/.test(ct)) {
    return 'js';
  }
  if (/\/json/.test(ct)) {
    return 'json';
  }
  if (/flash/.test(ct)) {
    return 'flash';
  }
  if (ct.substr(0, 6) === 'image/') {
    return 'cssimage';
  }
  if (ct.substr(0, 6) === 'audio/') {
    return 'audio';
  }
  if (ct.substr(0, 6) === 'video/') {
    return 'video';
  }
  if (/(\/|-)font-/.test(ct) || /\/font/.test(ct) ||
      ct.substr(0, 5) === 'font/' ||
      /\.((eot)|(otf)|(ttf)|(woff))($|\?)/i.test(url)) {
    return 'font';
  }
  if (/\.((gif)|(png)|(jpe)|(jpeg)|(jpg)|(tiff))($|\?)/i.test(url)) {
    return 'cssimage';
  }
  if (/\.((flac)|(ogg)|(opus)|(mp3)|(wav)|(weba))($|\?)/i.test(url)) {
    return 'audio';
  }
  if (/\.((mp4)|(webm))($|\?)/i.test(url)) {
    return 'video';
  }
  if (ct.substr(0, 9) === 'text/html' ||
      ct.substr(0, 10) === 'text/plain') {
    return 'doc';
  }
  return null;
};


module.exports.getErrorString = function (error) {
  // According to http://qt-project.org/doc/qt-4.8/qnetworkreply.html
  switch (error.errorCode) {
    case 1:
      return '(refused)';
    case 2:
      return '(closed)';
    case 3:
      return '(host not found)';
    case 4:
      return '(timeout)';
    case 5:
      return '(canceled)';
    case 6:
      return '(ssl failure)';
    case 7:
      return '(net failure)';
    default:
      return '(unknown error)';
  }
};
<commit_msg>in `utils.promisify` bail if passed a Promise<commit_after>var Promise = require('es6-promise').Promise;


module.exports.promisify = function (func) {
  // Already a Promise.
  if (func && typeof func.then === 'function') {
    return func;
  }

  return function () {
    var args = Array.prototype.slice.apply(arguments);

    return new Promise(function (resolve, reject) {
      func.apply({}, args.concat(function (err, value) {
        if (err) {
          reject(err);
        } else {
          resolve(value);
        }
      }));
    });
  };
};


module.exports.getType = function (ct, url) {
  ct = ct.toLowerCase();
  if (ct.substr(0, 8) === 'text/css') {
    return 'css';
  }
  if (/javascript/.test(ct)) {
    return 'js';
  }
  if (/\/json/.test(ct)) {
    return 'json';
  }
  if (/flash/.test(ct)) {
    return 'flash';
  }
  if (ct.substr(0, 6) === 'image/') {
    return 'cssimage';
  }
  if (ct.substr(0, 6) === 'audio/') {
    return 'audio';
  }
  if (ct.substr(0, 6) === 'video/') {
    return 'video';
  }
  if (/(\/|-)font-/.test(ct) || /\/font/.test(ct) ||
      ct.substr(0, 5) === 'font/' ||
      /\.((eot)|(otf)|(ttf)|(woff))($|\?)/i.test(url)) {
    return 'font';
  }
  if (/\.((gif)|(png)|(jpe)|(jpeg)|(jpg)|(tiff))($|\?)/i.test(url)) {
    return 'cssimage';
  }
  if (/\.((flac)|(ogg)|(opus)|(mp3)|(wav)|(weba))($|\?)/i.test(url)) {
    return 'audio';
  }
  if (/\.((mp4)|(webm))($|\?)/i.test(url)) {
    return 'video';
  }
  if (ct.substr(0, 9) === 'text/html' ||
      ct.substr(0, 10) === 'text/plain') {
    return 'doc';
  }
  return null;
};


module.exports.getErrorString = function (error) {
  // According to http://qt-project.org/doc/qt-4.8/qnetworkreply.html
  switch (error.errorCode) {
    case 1:
      return '(refused)';
    case 2:
      return '(closed)';
    case 3:
      return '(host not found)';
    case 4:
      return '(timeout)';
    case 5:
      return '(canceled)';
    case 6:
      return '(ssl failure)';
    case 7:
      return '(net failure)';
    default:
      return '(unknown error)';
  }
};

{'fraction_non_alphanumeric': 0.2351331176909679, 'fraction_numerical': 0.013436178153769594, 'mean_word_length': 2.3838383838383836, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1244074', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1550, 'n_words': 302}