<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const tty = require('tty');

const colors = [6, 2, 3, 4, 5, 1];
var prevColor = 0;

function envDebugColor() {
  try {
    return !!JSON.parse(process.env.DEBUG_COLOR);
  } catch (ex) {
    return false;
  }
}

function environ() {
  var useColor = process.env.DEBUG_COLOR ? envDebugColor() : tty.isatty(2);
  var names = [];
  var skips = [];
  if (process.env.DEBUG) {
    process.env.DEBUG
      .split(/[\s,]+/)
      .forEach(function(name){
        name = name.replace('*', '.*?');
        if (name[0] === '-') {
          skips.push(new RegExp('^' + name.substr(1) + '$'));
        } else {
          names.push(new RegExp('^' + name + '(:.+)?$'));
        }
      });
  }

  return {
    names: names,
    skips: skips,
    useColor: useColor
  };
}


function color() {
  return colors[prevColor++ % colors.length];
}

function coerce(val) {
  if (val instanceof Error) {
    return val.stack || val.message;
  }
  return val;
}

function disable() {
  function disabled() {}
  disabled.enabled = false;
  disabled.log =
  disabled.debug =
  disabled.info =
  disabled.warn =
  disabled.error =
    function noop() {};
  return disabled;
}

function enable(name, useColor) {
  var c;
  var format = useColor ? function colored(level, text) {
    text = coerce(text);
    if (!c) {
      c = color();
    }
    return '  \u001b[9' + c + 'm' + name + '.' + level + ' '
      + '\u001b[3' + c + 'm\u001b[90m'
      + text;
  } : function plain(level, text) {
    text = coerce(text);

    return new Date().toUTCString()
      + ' ' + name + '.' + level + ' ' + text;
  };

  function logAt(level) {
    return function log(text) {
      text = format(level === 'log' ? 'debug' : level, text);
      console[level].apply(console, arguments);
    };
  }
  
  function dbug() {
    dbug.log.apply(this, arguments);
  }
  dbug.enabled = true;
  dbug[format.name] = true;
  dbug.log = logAt('log');
  dbug.debug = dbug.log;

  dbug.info = logAt('info');
  dbug.warn = logAt('warn');
  dbug.error = logAt('error');
  return dbug;
}

module.exports = function dbug(name) {
  var env = environ();
  var match = env.skips.some(function(re){
    return re.test(name);
  });
<commit_msg>wrongly used DEBUG_COLOR instead of DEBUG_COLORS<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const tty = require('tty');

const colors = [6, 2, 3, 4, 5, 1];
var prevColor = 0;

function envDebugColor() {
  try {
    return !!JSON.parse(process.env.DEBUG_COLORS);
  } catch (ex) {
    return false;
  }
}

function environ() {
  var useColor = process.env.DEBUG_COLOR ? envDebugColor() : tty.isatty(2);
  var names = [];
  var skips = [];
  if (process.env.DEBUG) {
    process.env.DEBUG
      .split(/[\s,]+/)
      .forEach(function(name){
        name = name.replace('*', '.*?');
        if (name[0] === '-') {
          skips.push(new RegExp('^' + name.substr(1) + '$'));
        } else {
          names.push(new RegExp('^' + name + '(:.+)?$'));
        }
      });
  }

  return {
    names: names,
    skips: skips,
    useColor: useColor
  };
}


function color() {
  return colors[prevColor++ % colors.length];
}

function coerce(val) {
  if (val instanceof Error) {
    return val.stack || val.message;
  }
  return val;
}

function disable() {
  function disabled() {}
  disabled.enabled = false;
  disabled.log =
  disabled.debug =
  disabled.info =
  disabled.warn =
  disabled.error =
    function noop() {};
  return disabled;
}

function enable(name, useColor) {
  var c;
  var format = useColor ? function colored(level, text) {
    text = coerce(text);
    if (!c) {
      c = color();
    }
    return '  \u001b[9' + c + 'm' + name + '.' + level + ' '
      + '\u001b[3' + c + 'm\u001b[90m'
      + text;
  } : function plain(level, text) {
    text = coerce(text);

    return new Date().toUTCString()
      + ' ' + name + '.' + level + ' ' + text;
  };

  function logAt(level) {
    return function log(text) {
      text = format(level === 'log' ? 'debug' : level, text);
      console[level].apply(console, arguments);
    };
  }

  function dbug() {
    dbug.log.apply(this, arguments);
  }
  dbug.enabled = true;
  dbug[format.name] = true;
  dbug.log = logAt('log');
  dbug.debug = dbug.log;

  dbug.info = logAt('info');
  dbug.warn = logAt('warn');
  dbug.error = logAt('error');
  return dbug;
}

module.exports = function dbug(name) {
  var env = environ();
  var match = env.skips.some(function(re){
    return re.test(name);
  });

{'fraction_non_alphanumeric': 0.17472118959107807, 'fraction_numerical': 0.011152416356877323, 'mean_word_length': 2.6087928464977646, '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': '2036092', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1720, 'n_words': 415}