<commit_before>(function($){
  var Panel = function(data){
    this.data = data;
    this.$selected = null;
    this.childPanel = null;
  };

  Panel.prototype.render = function(){
    var data = this.data;

    if ($.isArray(data)){
      $list = $('<ol class="list" start="0">');
    } else {
      $list = $('<ul class="list">');
    }

    var self = this;
    $.each(data, function(key, val){
      var $li = self.createListItem(key, val);
      $list.append($li);
    });

    // handle expand/collapse
    $list.on('click', '.expandable', $.proxy(this.onKeyClicked, this));
    var $listWrap = $('<div class="panel">');
    $listWrap.html($list);

    this.$el = $listWrap;
    return this;
  };

  // private
  Panel.prototype.createListItem = function(key, val){
    var $li = $('<li>'),
      isObj = $.isPlainObject(val),
      valStr = JSON.stringify(val),
      $key, valType, $val;

    if (isObj || $.isArray(val)){
      // nested data
      var $expandable = $('<a class="expandable" href="#">');
      $expandable.data('obj', val);
      $key = $('<span class="key">' + key + '</span>');
      valType = isObj ? 'object' : 'array';

      // truncate the array/object preview
      var valMatch = valStr.match(/^([\{\[])(.{0,30})(?:.*)([\}\]])$/);
      $val = $('<span class="val ' + valType + '">' + valMatch[1] + '<span class="val-inner">' + valMatch[2] +'…</span>' + valMatch[3] + '</span>');

      $expandable.append($key, ': ', $val);
      $li.append($expandable);

    } else {
      // normal key-value
      $key = $('<span class="key">' + key + '</span>');
      valType = typeof val;
      $val = $('<span class="val ' + valType + '">' + Autolinker.link( valStr ) + '</span>');

      $li.append($key, ': ', $val);
    }

    return $li;
  };

  // private
  Panel.prototype.onKeyClicked = function(e){
    var $expandable = $(e.currentTarget),
      nestedData = $expandable.data('obj'),
      oldChildPanel = this.removeChildPanel();

    // only open if an existing panel wasn't being toggled off
    if (!oldChildPanel || oldChildPanel.data !== nestedData){
      var $selected = $expandable.closest('li');
      this.addChildPanel($selected, nestedData);
    }
<commit_msg>remove duplication around key/val injection<commit_after>(function($){
  var Panel = function(data){
    this.data = data;
    this.$selected = null;
    this.childPanel = null;
  };

  Panel.prototype.render = function(){
    var data = this.data;

    if ($.isArray(data)){
      $list = $('<ol class="list" start="0">');
    } else {
      $list = $('<ul class="list">');
    }

    var self = this;
    $.each(data, function(key, val){
      var $li = self.createListItem(key, val);
      $list.append($li);
    });

    // handle expand/collapse
    $list.on('click', '.expandable', $.proxy(this.onKeyClicked, this));
    var $listWrap = $('<div class="panel">');
    $listWrap.html($list);

    this.$el = $listWrap;
    return this;
  };

  // private
  Panel.prototype.createListItem = function(key, val){
    var $li = $('<li>'),
      isObj = $.isPlainObject(val),
      valStr = JSON.stringify(val),
      $rowContainer, $key, valType, valMarkup;

    if (isObj || $.isArray(val)){
      // nested data
      var $expandable = $('<a class="expandable" href="#">');
      $expandable.data('obj', val);
      $li.append($expandable);
      $rowContainer = $expandable;

      $key = $('<span class="key">' + key + '</span>');
      valType = isObj ? 'object' : 'array';

      // truncate the array/object preview
      var valMatch = valStr.match(/^([\{\[])(.{0,30})(?:.*)([\}\]])$/);
      valMarkup = valMatch[1] + '<span class="val-inner">' + valMatch[2] +'…</span>' + valMatch[3];

    } else {
      // normal key-value
      $rowContainer = $li;

      $key = $('<span class="key">' + key + '</span>');
      valType = typeof val;
      valMarkup = Autolinker.link( valStr );
    }

    $rowContainer.append($key, ': <span class="val ' + valType + '">' + valMarkup + '</span>');
    return $li;
  };

  // private
  Panel.prototype.onKeyClicked = function(e){
    var $expandable = $(e.currentTarget),
      nestedData = $expandable.data('obj'),
      oldChildPanel = this.removeChildPanel();

    // only open if an existing panel wasn't being toggled off
    if (!oldChildPanel || oldChildPanel.data !== nestedData){
      var $selected = $expandable.closest('li');
      this.addChildPanel($selected, nestedData);
    }

{'fraction_non_alphanumeric': 0.20818345323741008, 'fraction_numerical': 0.003147482014388489, 'mean_word_length': 2.7831632653061225, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '2207446', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1464, 'n_words': 319}