<commit_before>// Load in dependencies
var ValueMapper = require('value-mapper'),
    mergeObjects = require('./mergeObjects');

// Set up and export our function
module.exports = function mapContent (contentArr) {
  // If there are any global hooks in the contents, pull them out
  var globalBefore = [],
      globalBeforeEach = [],
      globalAfterEach = [],
      globalAfter = [];
  contentArr.forEach(function pluckGlobalHooks (content) {
    // Pluck out and flatten hooks
    // DEV: Flattening is performed by concat, which coerces arrays of arrays to arrays
    if (content.before) { globalBefore = globalBefore.concat(content.before); }
    if (content.beforeEach) { globalBeforeEach = globalBeforeEach.concat(content.beforeEach); }
    if (content.afterEach) { globalAfterEach = globalAfterEach.concat(content.afterEach); }
    if (content.after) { globalAfter = globalAfter.concat(content.after); }

    // Delete the hooks
    delete content.before;
    delete content.beforeEach;
    delete content.afterEach;
    delete content.after;
  });

  // Combine all content into an single object
  var content = mergeObjects(contentArr);

  // Temporarily save global hooks back to object for mapping
  content.before = globalBefore;
  content.beforeEach = globalBeforeEach;
  content.after = globalAfter;
  content.afterEach = globalAfterEach;

  // Create a value mapper and placeholders for keys used/not found
  var valMapper = new ValueMapper(content),
      keysUsed = [],
      keysNotFound = [];

  // Create helper function for finding the values and saving keys used/not found
  function getValue(key) {
    // Lookup the value by its key
    var valObj = valMapper.lookup(key, {
      alias: true,
      map: true,
      flatten: true,
      middlewares: [function resolveObjectAliases (val) {
        // Prepare return info
        var retVal = val,
            aliasesUsed = [],
            aliasesNotFound = [];

        // If the value is an object, upcast it to an array
        if (typeof val === 'object' && !Array.isArray(val)) {
          val = [val];
        }
console.log(val);
        // If the value is an array
        if (Array.isArray(val)) {
          // Map each value
          retVal = val.map(function (val) {
            // For each of the key types
            // ANTI-PATTERN: We lose a per-item stacktrace by using a forEach loop
            var obj = val;
            ['before', 'beforeEach', 'afterEach', 'after'].forEach(function resolveBeforeEtcAliases (hookName) {
              // If hooks exists
              var hooks = obj[hookName];
              if (hooks !== undefined) {
                // Resolve their value
                content.__doubleshot_tmp = hooks;
                var _key = this.key,<commit_msg>Adding notes for self<commit_after>// Load in dependencies
var ValueMapper = require('value-mapper'),
    mergeObjects = require('./mergeObjects');

// Set up and export our function
module.exports = function mapContent (contentArr) {
  // If there are any global hooks in the contents, pull them out
  var globalBefore = [],
      globalBeforeEach = [],
      globalAfterEach = [],
      globalAfter = [];
  contentArr.forEach(function pluckGlobalHooks (content) {
    // Pluck out and flatten hooks
    // DEV: Flattening is performed by concat, which coerces arrays of arrays to arrays
    if (content.before) { globalBefore = globalBefore.concat(content.before); }
    if (content.beforeEach) { globalBeforeEach = globalBeforeEach.concat(content.beforeEach); }
    if (content.afterEach) { globalAfterEach = globalAfterEach.concat(content.afterEach); }
    if (content.after) { globalAfter = globalAfter.concat(content.after); }

    // Delete the hooks
    delete content.before;
    delete content.beforeEach;
    delete content.afterEach;
    delete content.after;
  });

  // Combine all content into an single object
  var content = mergeObjects(contentArr);

  // Temporarily save global hooks back to object for mapping
  content.before = globalBefore;
  content.beforeEach = globalBeforeEach;
  content.after = globalAfter;
  content.afterEach = globalAfterEach;

  // Create a value mapper and placeholders for keys used/not found
  var valMapper = new ValueMapper(content),
      keysUsed = [],
      keysNotFound = [];

  // Create helper function for finding the values and saving keys used/not found
  function getValue(key) {
    /**
      Cases are hard. Here are some commons and rares:

      {
        'Aliasing': 'a',
        'a': 'b'
      }

      {
        'Object based aliasing': {
          before: 'a'
        },
        'a': 'b'
      }

      {
        'Object based chaining': [{
          before: 'c'
        }, {
          before: 'd'
        }]
      }

      Current strategy:
        If the value is an array
          Lookup each item
          If any value is an object
            Collect them into a super-object {before[], after[], ...}
          TODO: Is there any secondary expansion needed here?
        Otherwise
          Lookup the item
     */
    // Lookup the value by its key
    var valObj = valMapper.lookup(key, {
      alias: true,
      map: true,
      flatten: true,
      middlewares: [function resolveObjectAliases (val) {
        // Prepare return info
        var retVal = val,
            aliasesUsed = [],
            aliasesNotFound = [];

        // If the value is an object, upcast it to an array
        if (typeof val === 'object' && !Array.isArray(val)) {
          val = [val];
        }
console.log(val);
        // If the value is an array
        if (Array.isArray(val)) {
          // Map each value
          retVal = val.map(function (val) {
            // For each of the key types
            // ANTI-PATTERN: We lose a per-item stacktrace by using a forEach loop
            var obj = val;
            ['before', 'beforeEach', 'afterEach', 'after'].forEach(function resolveBeforeEtcAliases (hookName) {
              // If hooks exists
              var hooks = obj[hookName];
              if (hooks !== undefined) {
                // Resolve their value
                content.__doubleshot_tmp = hooks;
                var _key = this.key,
{'fraction_non_alphanumeric': 0.0996125282531482, 'fraction_numerical': 0.0, 'mean_word_length': 2.2708553326293557, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3346250', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1646, 'n_words': 553}