<commit_before>/**
 * Generate a replacing function given a table of patterns. Inspired by:
 * http://code.google.com/p/jslibs/wiki/JavascriptTips#String_converter
 * The order of elements is significant. Longer elements should be listed first.
 * @see Speed test http://jsperf.com/build-a-regexp-table
 *
 * @param {Object.<string, string>} translationTable The translation table of key value.
 * @return {function(string): string} A translating function.
 */
var replacer = function (translationTable) {
    // An array of translationTable keys.
    var pattern = [];

    for (let key in translationTable) {
        // Escaping regexp special chars.
        // @see Speed test for type casting to string http://jsperf.com/string-type-casting/2
        // @see http://closure-library.googlecode.com/svn/docs/closure_goog_string_string.js.source.html#line956
        key = ('' + key).replace(/([-()\[\]{}+?*.$\^|,:#<!\\\/])/g, '\\$1').
        replace(/\x08/g, '\\x08');

        pattern.push(key);
    }


    /**
     * @param {string} str Input string.
     * @return {string} The string replaced.
     */
    return function (str) {
        // The regular expression doing the replacement job.
        var regExp = new RegExp(pattern.join('|'), 'g');
        return str.replace(regExp, function (str) {
            return translationTable[str];
        });
    };
}

module.exports = replacer;<commit_msg>fix es6 syntax error<commit_after>/**
 * Generate a replacing function given a table of patterns. Inspired by:
 * http://code.google.com/p/jslibs/wiki/JavascriptTips#String_converter
 * The order of elements is significant. Longer elements should be listed first.
 * @see Speed test http://jsperf.com/build-a-regexp-table
 *
 * @param {Object.<string, string>} translationTable The translation table of key value.
 * @return {function(string): string} A translating function.
 */
var replacer = function (translationTable) {
    // An array of translationTable keys.
    var pattern = [];

    for (var key in translationTable) {
        // Escaping regexp special chars.
        // @see Speed test for type casting to string http://jsperf.com/string-type-casting/2
        // @see http://closure-library.googlecode.com/svn/docs/closure_goog_string_string.js.source.html#line956
        key = ('' + key).replace(/([-()\[\]{}+?*.$\^|,:#<!\\\/])/g, '\\$1').
        replace(/\x08/g, '\\x08');

        pattern.push(key);
    }


    /**
     * @param {string} str Input string.
     * @return {string} The string replaced.
     */
    return function (str) {
        // The regular expression doing the replacement job.
        var regExp = new RegExp(pattern.join('|'), 'g');
        return str.replace(regExp, function (str) {
            return translationTable[str];
        });
    };
}

module.exports = replacer;
{'fraction_non_alphanumeric': 0.15068977714892112, 'fraction_numerical': 0.0067209055535903785, 'mean_word_length': 2.7308707124010554, 'pattern_counts': {'":': 0, '<': 7, '<?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': '311905', 'n_tokens_mistral': 861, 'n_tokens_neox': 829, 'n_words': 232}