<commit_before>'use strict'

var merge = require('lodash.merge')

var effectsHash = {
  removeLinks: require('./effects/removeLinks'),
  flattenRenderedProps: require('./effects/flattenRenderedProps'),
  liftEmbeddedAuthor: require('./effects/liftEmbeddedAuthor'),
  liftEmbeddedFeaturedMedia: require('./effects/liftEmbeddedFeaturedMedia'),
  // Perform last so effects always handle raw property names
  camelize: require('./effects/camelize')
}

var allEffects = Object.keys(effectsHash).reduce(function (allEffects, key) {
  allEffects.push(effectsHash[key])
  return allEffects
}, [])

/**
 * Make a WP API response JSON sensible.
 * @param {Object} response Reponse JSON
 * @param {Array|Function} [effects] Effect or effects to apply to the response, default all effects
 * @returns {Object} Modified response JSON
 */
module.exports = function modify (response, effects) {
  if (effects && (typeof effects !== 'function' && !(effects instanceof Array))) {
    throw new Error('Expecting effects to be an array or function, got ' + typeof effects + '.')
  }

  effects = effects
    ? !(effects instanceof Array) ? [effects] : effects
    : allEffects

  effects.forEach(function (effect, i) {
    if (typeof effect !== 'function') {
      throw new Error('Effect at index ' + i + ' is not a function, got ' + typeof effect + '.')
    }
  })

  if (response instanceof Array) {
    return response.map((response) => modify(response, effects)
  }

  return effects.reduce(function (flattened, effect) {
    return effect(response, flattened)
  }, merge({}, response))<commit_msg>fix syntax err<commit_after>'use strict'

var merge = require('lodash.merge')

var effectsHash = {
  removeLinks: require('./effects/removeLinks'),
  flattenRenderedProps: require('./effects/flattenRenderedProps'),
  liftEmbeddedAuthor: require('./effects/liftEmbeddedAuthor'),
  liftEmbeddedFeaturedMedia: require('./effects/liftEmbeddedFeaturedMedia'),
  // Perform last so effects always handle raw property names
  camelize: require('./effects/camelize')
}

var allEffects = Object.keys(effectsHash).reduce(function (allEffects, key) {
  allEffects.push(effectsHash[key])
  return allEffects
}, [])

/**
 * Make a WP API response JSON sensible.
 * @param {Object} response Reponse JSON
 * @param {Array|Function} [effects] Effect or effects to apply to the response, default all effects
 * @returns {Object} Modified response JSON
 */
module.exports = function modify (response, effects) {
  if (effects && (typeof effects !== 'function' && !(effects instanceof Array))) {
    throw new Error('Expecting effects to be an array or function, got ' + typeof effects + '.')
  }

  effects = effects
    ? !(effects instanceof Array) ? [effects] : effects
    : allEffects

  effects.forEach(function (effect, i) {
    if (typeof effect !== 'function') {
      throw new Error('Effect at index ' + i + ' is not a function, got ' + typeof effect + '.')
    }
  })

  if (response instanceof Array) {
    return response.map((response) => modify(response, effects))
  }

  return effects.reduce(function (flattened, effect) {
    return effect(response, flattened)
  }, merge({}, response))
{'fraction_non_alphanumeric': 0.13146279949558637, 'fraction_numerical': 0.0, 'mean_word_length': 4.350758853288364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2300444', 'n_tokens_mistral': 919, 'n_tokens_neox': 872, 'n_words': 273}