<commit_before>(function($) {
  $.outliner = function($el, options) {
    this.options = $.extend({}, this.defaults, options);
    $el.html('').addClass('outliner');
    this.appendCollection($el, this.options.rootKey, this.options.data);
  }

  $.outliner.fn = $.outliner.prototype = {
    defaults: {
      naturalSort: true,
      rootKey: 'root'
    },
    // determine types
    nodeType: function(value) {
      return (value != null && typeof value === "object")
              ? (Object.prototype.toString.apply(value) === '[object Array]' ? 'list' : 'map')
              : 'leaf';
    },
    leafType: function(value) {
      if (value == null)
        return "null";
      else if (value === "")
        return "empty";
      else
        return typeof value;
    },
    // element creation
    appendCollection: function($el, key, value) {
      var nodeType = this.nodeType(value);
      var container = $('<div>').appendTo($el).addClass('collection');
      
      var i=0, childKeys, childKey, childValue;

      if (nodeType === 'map') {
        childKeys = [];
        for (var childKey in value) {
          if (value.hasOwnProperty(childKey)) {
            childKeys.push(childKey);
          }
        }
        if (this.options.naturalSort === true && $.naturalSort !== 'undefined')
          childKeys.sort($.naturalSort);
        else
          childKeys.sort();
      } else {
        childKeys = value;
      }

      // construct collection row
      var symbol = nodeType == "map" ? "{}" : "[]";
      var collectionItem = $('<div>').appendTo($el).addClass(nodeType).addClass('collectionRow row');
      
      var keyElem;
      if (childKeys.length > 0) {
        keyElem = $('<span>').appendTo(collectionItem).text(key + ' ' + symbol).addClass('collectionKey key');
      } else {
        keyElem = $('<span>').appendTo(collectionItem).text(key).addClass('collectionKey key empty');
        $('<span>').text(symbol).addClass('collectionValue empty').appendTo(collectionItem);
      }

      // construct items
      var items = $('<div>').appendTo($el).addClass('collectionItems');
      
      for (i=0; i < childKeys.length; i++) {
        if (nodeType === 'map')
          childKey = childKeys[i];
        else
          childKey = i;
        childValue = value[childKey];

        if (this.nodeType(childValue) == 'leaf') {
          this.appendLeaf(items, childKey, childValue);
        } else {
          this.appendCollection(items, childKey, childValue);
        }
      }
    },
    appendLeaf: function(items, key, value) {
      var leafType, leafItem, keyDiv, keyElem, valueDiv, valueElem;

      leafType = this.leafType(value);

      leafItem = $('<div>').appendTo(items).addClass('leafRow row');
      keyDiv = $('<div>').appendTo(leafItem).addClass('leafKeyDiv');
      keyElem = $('<span>').appendTo(keyDiv).addClass('leafKey key').text(key);

      if (value == null)
        value = "null";
      else if (value === "")
        value = '""';
      if (leafType == "string" && value.indexOf("\n") != -1) {
        valueDiv = $('<div>').appendTo(leafItem).addClass('leafValueDiv');
        valueElem = $('<pre>').appendTo(valueDiv).text(value).addClass('leafValue string multiline');
      } else {
        valueElem = $('<span>').appendTo(keyDiv).text(value).addClass('leafValue').addClass(leafType);
      }
    }
  };

  $.fn.outliner = function(options) {
    this.data('outliner', new($.outliner)(this, options));
  };

})(jQuery);<commit_msg>structure module like underscore<commit_after>(function() {

  var root = this;

  var Outliner = function($el, options) {
    this.options = $.extend({}, this.defaults, options);
    $el.html('').addClass('outliner');
    this.appendCollection($el, this.options.rootKey, this.options.data);
  }

  // from Underscore.js
  if (typeof module !== 'undefined' && module.exports) {
    module.exports = Outliner;
    Outliner.Outliner = Outliner;
  } else {
    root['Outliner'] = Outliner;
  }

  // from Backbone.js (this depends on Underscore)
  var _ = root._;
  if (!_ && (typeof require !== 'undefined')) _ = require('underscore')._;

  Outliner.prototype = {
    defaults: {
      naturalSort: true,
      rootKey: 'root'
    },
    // determine types
    nodeType: function(value) {
      return (value != null && typeof value === "object")
              ? (Object.prototype.toString.apply(value) === '[object Array]' ? 'list' : 'map')
              : 'leaf';
    },
    leafType: function(value) {
      if (value == null)
        return "null";
      else if (value === "")
        return "empty";
      else
        return typeof value;
    },
    // element creation
    appendCollection: function($el, key, value) {
      var nodeType = this.nodeType(value);
      var container = $('<div>').appendTo($el).addClass('collection');
      
      var i=0, childKeys, childKey, childValue;

      if (nodeType === 'map') {
        childKeys = [];
        for (var childKey in value) {
          if (value.hasOwnProperty(childKey)) {
            childKeys.push(childKey);
          }
        }
        if (this.options.naturalSort === true && $.naturalSort !== 'undefined')
          childKeys.sort($.naturalSort);
        else
          childKeys.sort();
      } else {
        childKeys = value;
      }

      // construct collection row
      var symbol = nodeType == "map" ? "{}" : "[]";
      var collectionItem = $('<div>').appendTo($el).addClass(nodeType).addClass('collectionRow row');
      
      var keyElem;
      if (childKeys.length > 0) {
        keyElem = $('<span>').appendTo(collectionItem).text(key + ' ' + symbol).addClass('collectionKey key');
      } else {
        keyElem = $('<span>').appendTo(collectionItem).text(key).addClass('collectionKey key empty');
        $('<span>').text(symbol).addClass('collectionValue empty').appendTo(collectionItem);
      }

      // construct items
      var items = $('<div>').appendTo($el).addClass('collectionItems');
      
      for (i=0; i < childKeys.length; i++) {
        if (nodeType === 'map')
          childKey = childKeys[i];
        else
          childKey = i;
        childValue = value[childKey];

        if (this.nodeType(childValue) == 'leaf') {
          this.appendLeaf(items, childKey, childValue);
        } else {
          this.appendCollection(items, childKey, childValue);
        }
      }
    },
    appendLeaf: function(items, key, value) {
      var leafType, leafItem, keyDiv, keyElem, valueDiv, valueElem;

      leafType = this.leafType(value);

      leafItem = $('<div>').appendTo(items).addClass('leafRow row');
      keyDiv = $('<div>').appendTo(leafItem).addClass('leafKeyDiv');
      keyElem = $('<span>').appendTo(keyDiv).addClass('leafKey key').text(key);

      if (value == null)
        value = "null";
      else if (value === "")
        value = '""';
      if (leafType == "string" && value.indexOf("\n") != -1) {
        valueDiv = $('<div>').appendTo(leafItem).addClass('leafValueDiv');
        valueElem = $('<pre>').appendTo(valueDiv).text(value).addClass('leafValue string multiline');
      } else {
        valueElem = $('<span>').appendTo(keyDiv).text(value).addClass('leafValue').addClass(leafType);
      }
    }
  };

  // jQuery plugin TODO: make this separate
  if (root.jQuery) {
    (function($) {
      $.outliner = Outliner;
      $.outliner.fn = $.outliner.prototype;

      $.fn.outliner = function(options) {
        this.data('outliner', new($.outliner)(this, options));
      };
    })(root.jQuery);
  }

})(this);
{'fraction_non_alphanumeric': 0.17576882290562035, 'fraction_numerical': 0.0010604453870625664, 'mean_word_length': 2.524054180289584, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '4576566', 'n_tokens_mistral': 2278, 'n_tokens_neox': 2221, 'n_words': 442}