<commit_before>// # util_shim
// Kinda replicates some of the most oft-used methods of the `util`
// built-in node module.

// Dependencies and [strict mode](http://mzl.la/1fRhnam)
define(function() {

  'use strict';

  return {
    /*
    `inspect` gives you a way better representation of an object
    than `JSON.stringify`. You can provide a higher `maxDepth` to
    go deeper into an object. Strings returned look like this:

        {
          left: "yes",
          right: {
            left: "yes",
            right: 'no'
          }
        }

    or, special-cased output for Error objects:

        [error: You can't do that!]
    */
    inspect: function inspect(obj, maxDepth, depth) {
      /*jshint maxcomplexity: 16 */

      if (typeof maxDepth === 'undefined') {
        maxDepth = 2;
        depth = 1;
      }

      if (obj === null) {
        return 'null';
      }
      else if (typeof obj === 'undefined') {
        return 'undefined';
      }

      if (typeof obj.inspect === 'function') {
        return obj.inspect();
      }

      var indentation = this.repeat('  ', depth);
      var indentMinusOne = this.repeat('  ', depth - 1);
      var properties = this.getProperties(obj, maxDepth, depth);

      if (obj.constructor && obj.constructor.name === 'Error') {
        if (properties.length) {
          var filtered = [];
          for (var i = 0, max = properties.length; i < max; i += 1) {
            var property = properties[i];
            if (!/^message:/.exec(property)) {
              filtered.push(property);
            }
          }

          if (filtered.length) {
            return '{ [Error: ' + obj.message + ']\n  ' +
              filtered.join(',\n' + indentation) +
              '\n}';
          }
        }

        return '[Error: ' + obj.message + ']';
      }
      else if (obj instanceof RegExp) {
        return obj.toString();
      }
      else if (typeof obj === 'string' || obj instanceof String) {
        return '"' + obj + '"';
      }
      else if (obj instanceof Date) {
        return '"' + obj.toJSON() + '"';
      }
      else if (typeof obj !== 'object') {
        return String(obj);
      }

      if (properties.length) {
        return '{\n' + indentation + properties.join(',\n' + indentation) + '\n' +
          indentMinusOne + '}';
      }
      else {
        return obj.toString();
      }
    },

    // `getProperties` recursively pulls properties out of an object, returning an array
    // of full rendered keys, ready for the final string.
    getProperties: function getProperties(obj, maxDepth, depth) {
      var properties = [];
      if (maxDepth <= 0) {
        return properties;
      }

      for (var key in obj) {
        if (obj.hasOwnProperty(key)) {
          properties.push(key + ': ' + this.inspect(obj[key], maxDepth - 1, depth + 1));
        }
      }
      return properties;
    },

    // `repeat` repeats the first parameter `n` times. This method is
    // duplicated here because when this module is pulled in with 'util'
    // (as a shim for the 'util' node module), we can't use relative pathing
    // to pull in string. Boo.
    repeat: function repeat(target, n) {
      var result = '';
      if (n <= 0) {
        return result;
      }

      for (var i = 0, max = n; i < max; i += 1) {
        result += target;
      }
      return result;
    },

    // `inherits` does "proper" inheritance. For reference:
    // [node's util.inherits](http://bit.ly/1fRjdYX)
    inherits: function inherits(Child, Parent) {
      Child.prototype = Object.create(Parent.prototype, {
        constructor: {
          value: Child,
          enumerable: false,
          writable: true,
          configurable: true
        }
      });
    }
  };

});
<commit_msg>Add some logic for downlevel browsers, phantomjs<commit_after>// # util_shim
// Kinda replicates some of the most oft-used methods of the `util`
// built-in node module.

// Dependencies and [strict mode](http://mzl.la/1fRhnam)
define(function() {

  'use strict';

  return {
    /*
    `inspect` gives you a way better representation of an object
    than `JSON.stringify`. You can provide a higher `maxDepth` to
    go deeper into an object. Strings returned look like this:

        {
          left: "yes",
          right: {
            left: "yes",
            right: 'no'
          }
        }

    or, special-cased output for Error objects:

        [error: You can't do that!]
    */
    inspect: function inspect(obj, maxDepth, depth) {
      /*jshint maxcomplexity: 16 */

      if (typeof maxDepth === 'undefined') {
        maxDepth = 2;
        depth = 1;
      }

      if (obj === null) {
        return 'null';
      }
      else if (typeof obj === 'undefined') {
        return 'undefined';
      }

      if (typeof obj.inspect === 'function') {
        return obj.inspect();
      }

      var indentation = this.repeat('  ', depth);
      var indentMinusOne = this.repeat('  ', depth - 1);
      var properties = this.getProperties(obj, maxDepth, depth);

      if (obj instanceof Error) {
        if (properties.length) {
          var filtered = [];
          for (var i = 0, max = properties.length; i < max; i += 1) {
            var property = properties[i];

            if (!/^message:/.exec(property) &&
              !/^description:/.exec(property) &&
              !/^stack/.exec(property) &&
              !/^sourceURL:/.exec(property)) {

              filtered.push(property);
            }
          }

          if (filtered.length) {
            return '{ [Error: ' + obj.message + ']\n  ' +
              filtered.join(',\n' + indentation) +
              '\n}';
          }
        }

        return '[Error: ' + obj.message + ']';
      }
      else if (obj instanceof RegExp) {
        return obj.toString();
      }
      else if (typeof obj === 'string' || obj instanceof String) {
        return '"' + obj + '"';
      }
      else if (obj instanceof Date) {
        return '"' + obj.toJSON() + '"';
      }
      else if (typeof obj !== 'object') {
        return String(obj);
      }

      if (properties.length) {
        return '{\n' + indentation + properties.join(',\n' + indentation) + '\n' +
          indentMinusOne + '}';
      }
      else {
        return obj.toString();
      }
    },

    // `getProperties` recursively pulls properties out of an object, returning an array
    // of full rendered keys, ready for the final string.
    getProperties: function getProperties(obj, maxDepth, depth) {
      var properties = [];
      if (maxDepth <= 0) {
        return properties;
      }

      for (var key in obj) {
        if (obj.hasOwnProperty(key)) {
          properties.push(key + ': ' + this.inspect(obj[key], maxDepth - 1, depth + 1));
        }
      }
      return properties;
    },

    // `repeat` repeats the first parameter `n` times. This method is
    // duplicated here because when this module is pulled in with 'util'
    // (as a shim for the 'util' node module), we can't use relative pathing
    // to pull in string. Boo.
    repeat: function repeat(target, n) {
      var result = '';
      if (n <= 0) {
        return result;
      }

      for (var i = 0, max = n; i < max; i += 1) {
        result += target;
      }
      return result;
    },

    // `inherits` does "proper" inheritance. For reference:
    // [node's util.inherits](http://bit.ly/1fRjdYX)
    inherits: function inherits(Child, Parent) {
      Child.prototype = Object.create(Parent.prototype, {
        constructor: {
          value: Child,
          enumerable: false,
          writable: true,
          configurable: true
        }
      });
    }
  };

});

{'fraction_non_alphanumeric': 0.1362574617181417, 'fraction_numerical': 0.003893070334804049, 'mean_word_length': 1.7613758509494806, 'pattern_counts': {'":': 0, '<': 11, '<?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': '2949427', 'n_tokens_mistral': 2319, 'n_tokens_neox': 2218, 'n_words': 673}