<commit_before>"use strict";

/**
 * Replace the variables by the keys in replacements surrounded by brackets in data.
 *
 * @param {Object} data
 * @param {String} type
 * @param {Object} replacements
 * @api private
 */

module.exports = function replace (data, type, replacements) {
  var literals = replacements[type];

  // Loop each key replacement combination, wrap in brackets.
  Object.keys(literals).forEach(function loopReplacements (original) {
    data.content = data.content.replace(
        new RegExp('{' + original + '}', 'g')
      , literals[original]
    );
  });

  return data.content;
};<commit_msg>add regex possibilities<commit_after>"use strict";

/**
 * Required modules.
 */

var Logger = require('devnull')
  , logger = new Logger;

/**
 * Replace the variables by the keys in replacements surrounded by brackets in data.
 *
 * @param {Object} data
 * @param {String} type
 * @param {Object} replacements
 * @api private
 */

module.exports = function replace (data, type, replacements) {
  var literals = replacements[type];

  // Loop each key replacement combination, wrap in brackets.
  Object.keys(literals).forEach(function loopReplacements (original) {
    var regex = typeof literals[original] === 'object';

    // Check for requirements.
    if (regex && (!literals[original].regex || !literals[original].value)) {
      return logger.warning(
        'Provide a proper regex and value if your using replace with ' +
        'regular expressions. Value for key `' + original + '` is not replaced.'
      );
    }

    // Regular expression is required to do global replace.
    data.content = data.content.replace(
        new RegExp(regex ? literals[original].regex : original, 'g')
      , regex ? literals[original].value : literals[original]
    );
  });

  return data.content;
};
{'fraction_non_alphanumeric': 0.12554824561403508, 'fraction_numerical': 0.0, 'mean_word_length': 3.429611650485437, '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': '4067433', 'n_tokens_mistral': 530, 'n_tokens_neox': 497, 'n_words': 165}