<commit_before>/**
 * Does variable substitution on a string.
 * It scans through the string looking for expressions enclosed in {{ }} braces.
 * If an expression is found, use it as a key on the object,
 * and if the key has a string value or number value, it is substituted for the bracket expression and it repeats.
 * @param {String} subjectString  The initial string to substitude its expressions.
 * @param {Object} data The object that acts as our model.
 * @return {String} Returns the result string.
 */
function supplant(subjectString, data) {
    'use strict';

    if (typeof subjectString !== 'string') {
        throw new TypeError('Expected a string');
    }

    return subjectString.replace(/{{([^{{}}]*)}}/g, function (a, b) {
        var p = b.split(/\./), // Split the variable into its dot notation parts.
            c = data,          // The c variable becomes our cursor that will traverse the object.
            i = 0,
            l = p.length;

        // Loop over the steps in the dot notation path.
        for (i; i < l; i += 1) {
            // If the key doesn't exist in the object do not process.
            // Mirrors how the function worked for bad values.
            if (c[p[i]] == null) {
                return a;
            }

            // Move the cursor up to the next step.
            c = c[p[i]];
        }

        // If the data is a string or number return it,
        // otherwise do not process, return the value it was, i.e. {x}<commit_msg>[ci-skip] type checking<commit_after>/**
 * Does variable substitution on a string.
 * It scans through the string looking for expressions enclosed in {{ }} braces.
 * If an expression is found, use it as a key on the object,
 * and if the key has a string value or number value, it is substituted for the bracket expression and it repeats.
 * @param {String} subjectString  The initial string to substitude its expressions.
 * @param {Object} data A plain object that acts as our model.
 * @return {String} Returns the result string.
 */
function supplant(subjectString, data) {
    'use strict';

    if (typeof subjectString !== 'string') {
        throw new TypeError('Expected a string');
    }

    if (data == null) {
        return subjectString;
    }

    if (typeof data !== 'object') {
        throw new TypeError('Expected a plain object');
    }

    return subjectString.replace(/{{([^{{}}]*)}}/g, function (a, b) {
        var p = b.split(/\./), // Split the variable into its dot notation parts.
            c = data,          // The c variable becomes our cursor that will traverse the object.
            i = 0,
            l = p.length;

        // Loop over the steps in the dot notation path.
        for (i; i < l; i += 1) {
            // If the key doesn't exist in the object do not process.
            // Mirrors how the function worked for bad values.
            if (c[p[i]] == null) {
                return a;
            }

            // Move the cursor up to the next step.
            c = c[p[i]];
        }

        // If the data is a string or number return it,
        // otherwise do not process, return the value it was, i.e. {x}
{'fraction_non_alphanumeric': 0.10416666666666667, 'fraction_numerical': 0.0012626262626262627, 'mean_word_length': 2.0529865125240847, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5303240', 'n_tokens_mistral': 872, 'n_tokens_neox': 827, 'n_words': 407}