<commit_before>var datalayer_string = "";

// look for datalayer within DOM
window.addEventListener('message', function(e) {
    if (e.data.type && (e.data.type == 'datalayer_config')) {

      datalayer_string = e.data.text;
      var object = window[datalayer_string];

      //only run extension if data layer object was found.
      console.log('Looking for the (' + e.data.text + ') data layer...');
      if (object) {
        init(object);
      } else {
        console.log(e.data.text + ' was not found on this page.')
      }

    }
});

// display Data Layer (called if dataObject found on page)
function init(datalayer) {

  var dl = datalayer;

  //flatten nested object
  function flatten(ob) {
    var toReturn = {};

  	for (var i in ob) {
  		if (!ob.hasOwnProperty(i)) continue;
  		if ((typeof ob[i]) == 'object') {
  			var flatObject = flatten(ob[i]);
  			for (var x in flatObject) {
  				if (!flatObject.hasOwnProperty(x)) continue;
  				toReturn[i + '.' + x] = flatObject[x];
  			}
  		} else {
  			toReturn[i] = ob[i];
  		}
  	}
  	return toReturn;
  };

  // input a flatted data layer object
  // output a sorted data layer array with hierarchy level
  function format(obj) {
    var flatDL = [];
    var width  = 40; //width of left column in console display

    for (var key in obj) {

      var level = (key.split(".").length - 1); //level in hierarchy
      var keyf = key + ' '.repeat(width - key.length) + ': ';
      var value = obj[key];
      var sortablekey = level + '|' + keyf + '|' + value;

      flatDL.push(sortablekey);
    }

    var output = flatDL.sort(); //sort flattened data Layer
    return output;
  }

  // input a sorted and flattened data layer array
  // output a nested format in console
  function output(array) {

    //array value => level|element|value
    var arrayLength = array.length;

    //delineate objects into groups
    // level 1+ => [Child Object]
    var a = [], b = [], prev;
    for (var i = 0; i < arrayLength; i++) {

      var level = array[i].split('|')[0];

      // level 0  => Base
      if (level == 0) {
        level = 'root';
      }

      // level 1+ => [Child Object]
      if (level >= 1) {
        level = array[i].split('|')[1].split('.')[0];
      }

      if (level !== prev) {
        a.push(level);
        b.push(1);
      } else {
        b[b.length-1]++;
      }
      prev = level;

    }

    var groups = {};
    for (var i = 0; i < a.length; i++) {
      groups[a[i]] = b[i];
    }

    //output elements
    console.group('Data Layer View: ' + datalayer_string);
    var groupCount = 0;
    for (var i = 0; i < arrayLength; i++) {
      //extract group identifier from key, based on level
      var level = array[i].split('|')[0];
      if (level == 0) {
        level = 'root';
      }
      if (level >= 1) {
        level = array[i].split('|')[1].split('.')[0];
      }
      //extract element from second part of key
      var element = array[i].split('|')[1];
      //extract value from third part of key and truncate lengthy values
      var value = array[i].split('|')[2];
      if (value.length > 100) { value = value.substring(0,95) + '...'; }

      // group outputs
      groupCount++;

      if (groupCount == 1) { console.group(level); }

      console.log(element + value);

      if (groupCount == groups[level]) {
        console.groupEnd();
        groupCount = 0;
      }

    }
    console.groupEnd();

  }

  //flatten, format, and output the data layer
  //console.group('Data Layer View: ' + datalayer_string);

  output(format(flatten(dl)));

  //console.groupEnd();
  ////////////////////////////////////

};<commit_msg>fix for long object paths<commit_after>var datalayer_string = "";

// look for datalayer within DOM
window.addEventListener('message', function(e) {
    if (e.data.type && (e.data.type == 'datalayer_config')) {

      datalayer_string = e.data.text;
      var object = window[datalayer_string];

      //only run extension if data layer object was found.
      console.log('Looking for the (' + e.data.text + ') data layer...');
      if (object) {
        init(object);
      } else {
        console.log(e.data.text + ' was not found on this page.')
      }

    }
});

// display Data Layer (called if dataObject found on page)
function init(datalayer) {

  var dl = datalayer;

  //flatten nested object
  function flatten(ob) {
    var toReturn = {};

  	for (var i in ob) {
  		if (!ob.hasOwnProperty(i)) continue;
  		if ((typeof ob[i]) == 'object') {
  			var flatObject = flatten(ob[i]);
  			for (var x in flatObject) {
  				if (!flatObject.hasOwnProperty(x)) continue;
  				toReturn[i + '.' + x] = flatObject[x];
  			}
  		} else {
  			toReturn[i] = ob[i];
  		}
  	}
  	return toReturn;
  };

  // input a flatted data layer object
  // output a sorted data layer array with hierarchy level
  function format(obj) {
    var flatDL = [];
    var width  = 40; //default width of left column in console display

    for (var key in obj) {

      var level = (key.split(".").length - 1); //level in hierarchy

      // output formatting
      var whitespace = Math.abs(width - key.length); // to get alignment
      var keyf = key + ' '.repeat(whitespace) + ': ';

      var value = obj[key];
      var sortablekey = level + '|' + keyf + '|' + value;

      flatDL.push(sortablekey);
    }

    var output = flatDL.sort(); //sort flattened data Layer
    return output;
  }

  // input a sorted and flattened data layer array
  // output a nested format in console
  function output(array) {

    //array value => level|element|value
    var arrayLength = array.length;

    //delineate objects into groups
    // level 1+ => [Child Object]
    var a = [], b = [], prev;
    for (var i = 0; i < arrayLength; i++) {

      var level = array[i].split('|')[0];

      // level 0  => Base
      if (level == 0) {
        level = 'root';
      }

      // level 1+ => [Child Object]
      if (level >= 1) {
        level = array[i].split('|')[1].split('.')[0];
      }

      if (level !== prev) {
        a.push(level);
        b.push(1);
      } else {
        b[b.length-1]++;
      }
      prev = level;

    }

    var groups = {};
    for (var i = 0; i < a.length; i++) {
      groups[a[i]] = b[i];
    }

    //output elements
    var groupCount = 0;
    for (var i = 0; i < arrayLength; i++) {
      //extract group identifier from key, based on level
      var level = array[i].split('|')[0];
      if (level == 0) {
        level = 'root';
      }
      if (level >= 1) {
        level = array[i].split('|')[1].split('.')[0];
      }
      //extract element from second part of key
      var element = array[i].split('|')[1];
      //extract value from third part of key and truncate lengthy values
      var value = array[i].split('|')[2];
      if (value.length > 100) { value = value.substring(0,95) + '...'; }

      // group outputs
      groupCount++;

      if (groupCount == 1) { console.group(level); }

      console.log(element + value);

      if (groupCount == groups[level]) {
        console.groupEnd();
        groupCount = 0;
      }

    }

  }

  //flatten, format, and output the data layer
  //console.group('Data Layer View: ' + datalayer_string);
  console.group('Data Layer View: ' + datalayer_string);
  output(format(flatten(dl)));
  console.groupEnd();
  //console.groupEnd();
  ////////////////////////////////////

};
{'fraction_non_alphanumeric': 0.16648692369911028, 'fraction_numerical': 0.00862766244270693, 'mean_word_length': 2.088676103247294, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '60265', 'n_tokens_mistral': 2520, 'n_tokens_neox': 2382, 'n_words': 685}