<commit_before>(function() {

  var root = this;

  // Export Outliner for CommonJS and non-CommonJS environments.
  var Outliner;
  if (typeof exports !== 'undefined') {
    Outliner = exports;
  } else {
    Outliner = this.Outliner = {};
  }

  // Get a reference to Underscore.js and Backbone.js, from the root object or through require().
  var _ = root._;
  if (!_ && (typeof require !== 'undefined')) _ = require('underscore')._;

  var Backbone = root.Backbone;
  if (!_ && (typeof require !== 'undefined')) Backbone = require('backbone');

  var Traverse = require('traverse');

  Outliner.Leaf = function(attr) {
    this._attr = attr;
    this.key = attr.key;
    this.value = attr.value;
    this.resource = attr.resource;
    this.parent = attr.parent;
    var value = this.value;
    if (value == null)
      this.leafType = "null";
    else if (value === "")
      this.leafType = "empty";
    else
      this.leafType = typeof value;
  };

  _.extend(Outliner.Leaf.prototype, {
    type: 'leaf',

    // The underscore templates.
    templates: {
      link: '<a href="<%= url %>" class="leafValue <%= leafType %>"><%= value %></a>',
      str: '<span class="leafValue <%= leafType %>"><%= value %></span>',
      text: [
        '<div class="leafValueDiv">',
        '  <pre class="leafValue string multiline"><%= value %></pre>',
        '</div>'
      ].join("\n"),
      leaf: [
        '<div class="leafRow row">',
        '  <div class="leafKeyDiv leaf">',
        '    <span class="leafKey key"><%= key %></span>',
        '    <%= valueSpan %>',
        '  </div>',
        '  <%= valueBlock %>',
        '</div>'
      ].join("\n")
    },

    escape: function(attr) {
      return escapeHTML(String(this[attr]));
    },

    leafType: function() {
      
    },

    renderValue: function() {
      var value = this.value, leafType = this.leafType;
      var tpl = this.templates.str, ctx = {leafType: this.escape('leafType'), value: this.escape('value')};
      var div = false;
      if (value == null) {
        ctx.value = 'null';
      } else if (value === "") {
        ctx.value = '""';
      } else if (leafType == "string" && value.indexOf("\n") != -1) {
        tpl = this.templates.text;
      } else if (/^(?:https?|mailto):/.test(value)) {
        tpl = this.templates.link;
        ctx.url = ctx.value;
      }

      var html = _.template(tpl, ctx);
      if (leafType == "string" && value.indexOf("\n") != -1) {
        return { block: html };
      } else {
        return { span: html }
      }
    },
    render: function() {
      var rendered = this.renderValue();
      var ctx = {
        key: this.escape('key'),
        valueBlock: rendered.block || '',
        valueSpan: rendered.span || ''
      }
      return _.template(this.templates.leaf, ctx);
    }
  });

  Outliner.ResourceModel = Backbone.Model.extend({
    defaults: {
      naturalSort: true,
      rootKey: 'root'
    },
    type: 'resource',
    initialize: function(attributes, options) {
      this.lastId = 0;
      this.bind('change:data', this.build, this);
      this.build();
    },
    build: function() {
      var resource = this;
      this.attributes.root = Traverse(this.attributes.data).map(function(value) {
        this.after(function(value) {
          var node;
          if (this.isLeaf) {
            node = {
              value:    value,
              type:     typeof value,
              resource: resource
            };
          } else {
            var keys = Object.keys(value);
            node = {
              type:     Array.isArray(value) ? 'array' : 'object',
              empty:    keys.length === 0,
              keys:     keys,
              children: value,
              resource: resource
            };
          }

          this.update(node);
        });
      });

      Traverse(this.attributes.root).forEach(function(node) {
        this.before(function() {
          if ((node.children || node.value) && this.parents.length !== 0) {
            // skip a node
            node.parent = this.parents[1].node;
          }

          if (node.children) {
            // descend right into the children
            this.keys = ['children'];
          }
          if (node.value) {
            this.block();
          }
        });
      });
    },
    render: function($el) {
      $el.html('').addClass('outliner');
      this.appendCollection($el, this.get('rootKey'), this.get('data'));
    },
    // determine types
    nodeType: function(value) {
      return (value != null && typeof value === "object")
              ? (Object.prototype.toString.apply(value) === '[object Array]' ? 'list' : 'map')
              : 'leaf';
    },
    // element creation
    appendCollection: function($el, key, value) {<commit_msg>check depth, not just keys<commit_after>(function() {

  var root = this;

  // Export Outliner for CommonJS and non-CommonJS environments.
  var Outliner;
  if (typeof exports !== 'undefined') {
    Outliner = exports;
  } else {
    Outliner = this.Outliner = {};
  }

  // Get a reference to Underscore.js and Backbone.js, from the root object or through require().
  var _ = root._;
  if (!_ && (typeof require !== 'undefined')) _ = require('underscore')._;

  var Backbone = root.Backbone;
  if (!_ && (typeof require !== 'undefined')) Backbone = require('backbone');

  var Traverse = require('traverse');

  Outliner.Leaf = function(attr) {
    this._attr = attr;
    this.key = attr.key;
    this.value = attr.value;
    this.resource = attr.resource;
    this.parent = attr.parent;
    var value = this.value;
    if (value == null)
      this.leafType = "null";
    else if (value === "")
      this.leafType = "empty";
    else
      this.leafType = typeof value;
  };

  _.extend(Outliner.Leaf.prototype, {
    type: 'leaf',

    // The underscore templates.
    templates: {
      link: '<a href="<%= url %>" class="leafValue <%= leafType %>"><%= value %></a>',
      str: '<span class="leafValue <%= leafType %>"><%= value %></span>',
      text: [
        '<div class="leafValueDiv">',
        '  <pre class="leafValue string multiline"><%= value %></pre>',
        '</div>'
      ].join("\n"),
      leaf: [
        '<div class="leafRow row">',
        '  <div class="leafKeyDiv leaf">',
        '    <span class="leafKey key"><%= key %></span>',
        '    <%= valueSpan %>',
        '  </div>',
        '  <%= valueBlock %>',
        '</div>'
      ].join("\n")
    },

    escape: function(attr) {
      return escapeHTML(String(this[attr]));
    },

    leafType: function() {
      
    },

    renderValue: function() {
      var value = this.value, leafType = this.leafType;
      var tpl = this.templates.str, ctx = {leafType: this.escape('leafType'), value: this.escape('value')};
      var div = false;
      if (value == null) {
        ctx.value = 'null';
      } else if (value === "") {
        ctx.value = '""';
      } else if (leafType == "string" && value.indexOf("\n") != -1) {
        tpl = this.templates.text;
      } else if (/^(?:https?|mailto):/.test(value)) {
        tpl = this.templates.link;
        ctx.url = ctx.value;
      }

      var html = _.template(tpl, ctx);
      if (leafType == "string" && value.indexOf("\n") != -1) {
        return { block: html };
      } else {
        return { span: html }
      }
    },
    render: function() {
      var rendered = this.renderValue();
      var ctx = {
        key: this.escape('key'),
        valueBlock: rendered.block || '',
        valueSpan: rendered.span || ''
      }
      return _.template(this.templates.leaf, ctx);
    }
  });

  Outliner.ResourceModel = Backbone.Model.extend({
    defaults: {
      naturalSort: true,
      rootKey: 'root'
    },
    type: 'resource',
    initialize: function(attributes, options) {
      this.lastId = 0;
      this.bind('change:data', this.build, this);
      this.build();
    },
    build: function() {
      var resource = this;
      this.attributes.root = Traverse(this.attributes.data).map(function(value) {
        this.after(function(value) {
          var node;
          if (this.isLeaf) {
            node = {
              value:    value,
              type:     typeof value,
              resource: resource
            };
          } else {
            var keys = Object.keys(value);
            node = {
              type:     Array.isArray(value) ? 'array' : 'object',
              empty:    keys.length === 0,
              keys:     keys,
              children: value,
              resource: resource
            };
          }

          this.update(node);
        });
      });

      Traverse(this.attributes.root).forEach(function(node) {
        this.before(function() {
          if (this.depth % 2 === 0) {
            if ((node.children || node.value) && this.parents.length !== 0) {
              // skip a node
              node.parent = this.parents[1].node;
            }
            if (node.children) {
              // descend right into the children
              this.keys = ['children'];
            }
            if (node.value) {
              this.block();
            }
          }
        });
      });
    },
    render: function($el) {
      $el.html('').addClass('outliner');
      this.appendCollection($el, this.get('rootKey'), this.get('data'));
    },
    // determine types
    nodeType: function(value) {
      return (value != null && typeof value === "object")
              ? (Object.prototype.toString.apply(value) === '[object Array]' ? 'list' : 'map')
              : 'leaf';
    },
    // element creation
    appendCollection: function($el, key, value) {
{'fraction_non_alphanumeric': 0.16859983429991715, 'fraction_numerical': 0.0014498757249378626, 'mean_word_length': 1.8783904619970193, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, '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': '4524026', 'n_tokens_mistral': 2925, 'n_tokens_neox': 2855, 'n_words': 652}