<commit_before>// adopted from map-config <https://github.com/doowb/map-config>
// Copyright (c) 2015, <NAME>

var stampit  = require('../object/stampit')
var kindOf   = require('../lang/kindOf')
var flatten  = require('../array/flatten')
var slice    = require('../array/slice')
var forEach  = require('../collection/forEach')

module.exports = stampit()
  .methods({
    register: map,
    alias: alias,
    process: process,
    addKey: addKey
  })
  .init([
    function () {
      define(this, 'isQConfig', true)
      this.tasks = {}
      this.keys = []
      this.aliases = {}
      this.queue = {}
    }
  ])

function map (key, val) {
  // allow passing another map-config object in as a value
  if (isQConfig(val)) {
    this.register(key, function(cfg) {
      return val.process(cfg);
    })
    return this.addKey(key, val.keys)
  }

  if (typeof val !== 'function') {
    val = this.tasks[key] || this.aliases[key]
  }

  this.queue[key] = val
  this.addKey(key)
  return this
}

function alias (alias, key) {
  this.aliases[alias] = key
  this.addKey(alias)
  return this
}

function process (args) {
  args = args || {}
  var key

  forEach(this.aliases, (val, key) => {
    var alias = this.aliases[key]
    this.register(key, chk(this.queue[alias]) || this.tasks[alias])
  })

  forEach(args, (val, key) => {
    if (typeof this.queue[key] === 'function') {
      this.queue[key].call(this, args[key])
    }
    if (Array.isArray(this.queue[key])) {
      var len = this.queue[key].length
      var i = -1
      while (++i < len) this.queue[key][i].call(this, args[key][i])
    }
  })

  function chk (value) {
    return typeof value === 'function'
      ? value
      : undefined
  }
}

function addKey (key, arr) {
  var idx = this.keys.indexOf(key)

  if (Array.isArray(arr)) {
    if (idx === -1) {
      this.keys = this.keys.concat(arr.map(function(val) {
        return [key, val].join('.')
      }))
    } else {
      this.keys.splice(idx, 1)
      var vals = arr.map(function(val) {
        return [key, val].join('.')
      })
      .filter(function(val) {
        return this.keys.indexOf(val) === -1
      }.bind(this))

      this.keys.push.apply(this.keys, vals)
    }
  } else if (idx === -1) {
    this.keys.push(key)
  }

  return this
}

function isQConfig (val) {
  return val
    && typeof val === 'object'
    && val.isQConfig === true
}

function define (obj, prop, val) {
  Object.defineProperty(obj, prop, {
    enumerable: false,
    configurable: true,
    value: val
  })
}
<commit_msg>update cache/queue -- minor edits<commit_after>// adopted from map-config <https://github.com/doowb/map-config>
// Copyright (c) 2015, <NAME>

var stampit  = require('../object/stampit')
var kindOf   = require('../lang/kindOf')
var flatten  = require('../array/flatten')
var slice    = require('../array/slice')
var forEach  = require('../collection/forEach')

// process-queue for the primary way I use this: bot.process(bot.queue)

module.exports = stampit()
  .methods({
    register: map,
    alias: alias,
    process: processq,
    addKey: addKey
  })
  .init([
    function () {
      define(this, 'isProcessQueue', true)
      this.tasks = {}
      this.keys = []
      this.aliases = {}
      this.queue = {}
    }
  ])

function map (key, val) {
  // allow passing another map-config object in as a value
  if (isProcessQueue(val)) {
    this.register(key, function(cfg) {
      return val.process(cfg);
    })
    return this.addKey(key, val.keys)
  }

  if (typeof val !== 'function') {
    val = this.tasks[key] || this.aliases[key]
  }

  this.queue[key] = val
  this.addKey(key)
  return this
}

function alias (alias, key) {
  this.aliases[alias] = key
  this.addKey(alias)
  return this
}

function processq (args) {
  args = args || {}
  var key

  forEach(this.aliases, (val, key) => {
    var alias = this.aliases[key]
    this.register(key, chk(this.queue[alias]) || this.tasks[alias])
  })

  forEach(args, (val, key) => {
    if (typeof this.queue[key] === 'function') {
      this.queue[key].call(this, args[key])
    }
    if (Array.isArray(this.queue[key])) {
      var len = this.queue[key].length
      var i = -1
      while (++i < len) this.queue[key][i].call(this, args[key][i])
    }
  })

  function chk (value) {
    return typeof value === 'function'
      ? value
      : undefined
  }
}

function addKey (key, arr) {
  var idx = this.keys.indexOf(key)

  if (Array.isArray(arr)) {
    if (idx === -1) {
      this.keys = this.keys.concat(arr.map(function(val) {
        return [key, val].join('.')
      }))
    } else {
      this.keys.splice(idx, 1)
      var vals = arr.map(function(val) {
        return [key, val].join('.')
      })
      .filter(function(val) {
        return this.keys.indexOf(val) === -1
      }.bind(this))

      this.keys.push.apply(this.keys, vals)
    }
  } else if (idx === -1) {
    this.keys.push(key)
  }

  return this
}

function isProcessQueue (val) {
  return val
    && typeof val === 'object'
    && val.isProcessQueue === true
}

function define (obj, prop, val) {
  Object.defineProperty(obj, prop, {
    enumerable: false,
    configurable: true,
    value: val
  })
}

{'fraction_non_alphanumeric': 0.1719081612965464, 'fraction_numerical': 0.003472892147404978, 'mean_word_length': 2.545827633378933, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '1412699', 'n_tokens_mistral': 1850, 'n_tokens_neox': 1823, 'n_words': 406}