<commit_before>'use strict';

var datamapInterfacePrototype, isOwnProperty;

isOwnProperty = Object.prototype.hasOwnProperty;

function DatamapInterface(values) {
    this.map = {};
    this.add(values);
}

datamapInterfacePrototype = DatamapInterface.prototype;

function has(object, property) {
    return isOwnProperty.call(object, property) &&
        object[property] !== undefined;
}

function forPropertyInObject(object, callback) {
    var property;

    for (property in object) {
        if (has(object, property)) {
            callback(property, object[property]);
        }
    }
}

function forValueInArray(array, callback) {
    var iterator = -1,
        length = array.length;

    while (++iterator < length) {
        callback(array[iterator], iterator);
    }
}

function add(object, property, value) {
    object[property] = value;
}

function addAll(object, values) {
    forPropertyInObject(values, function (property, value) {
        add(object, property, value);
    });
}

function remove(object, property) {
    object[property] = undefined;
}

function removeAll(object, array) {
    forValueInArray(array, function (property) {
        remove(object, property);
    });
}

function getProperty(object, property) {
    return has(object, property) ? object[property] : null;
}

datamapInterfacePrototype.add = function (values, value) {
    if (value) {
        add(this.map, values, value);
    } else {
        addAll(this.map, values);
    }
};

datamapInterfacePrototype.remove = function (values) {
    (typeof values === 'string' ? remove : removeAll)(this.map, values);
};

datamapInterfacePrototype.all = function () {
    var values = {};

    addAll(values, this.map);

    return values;
};

datamapInterfacePrototype.get = function (property) {
    return getProperty(this.map, property);
};

datamapInterfacePrototype.has = function (property) {
    return has(this.map, property);
};

exports = module.exports = DatamapInterface;<commit_msg>Refactor `index.js`<commit_after>'use strict';

/**
 * Cache.
 */

var isOwnProperty;

isOwnProperty = Object.prototype.hasOwnProperty;

/**
 * An interface for a map of items.
 *
 * @constructor
 * @param {Object.<string, *>} values
 */

function DatamapInterface(values) {
    this.map = {};

    this.add(values);
}

/**
 * Detect if a key is defined on an object.
 *
 * @param {Object.<string, *>} object
 * @param {string} key
 * @return {boolean}
 */

function has(object, key) {
    return isOwnProperty.call(object, key) && object[key] !== undefined;
}

/**
 * Loop over an `Object`.
 *
 * @param {Object.<string, *>} object
 * @param {function(string, *)} callback
 */

function forPropertyInObject(object, callback) {
    var key;

    for (key in object) {
        if (has(object, key)) {
            callback(object[key], key);
        }
    }
}

/**
 * Loop over an `Array`.
 *
 * @param {Array.<*>} array
 * @param {function(*, number)} callback
 */

function forValueInArray(array, callback) {
    var index,
        length;

    index = -1;
    length = array.length;

    while (++index < length) {
        callback(array[index], index);
    }
}

/**
 * Add all `values` to `object`.
 *
 * @param {Object.<string, *>} object
 * @param {Object.<string, *>} values
 */

function addAll(object, values) {
    forPropertyInObject(values, function (value, key) {
        object[key] = value;
    });
}

/**
 * Remove every key in `keys` from `object`.
 *
 * @param {Object.<string, *>} object
 * @param {Array.<string>} keys
 */

function removeAll(object, keys) {
    forValueInArray(keys, function (key) {
        object[key] = undefined;
    });
}

/**
 * Add values to map.
 *
 * When the second argument is passed, it is treated as
 * a single value and the first parameter as a key.
 * Otherwise, every value in the first argument is added.
 *
 * @this DatamapInterface
 * @param {Object.<string, *>|string} values
 * @param {*} value
 */

function add(values, value) {
    if (value) {
        this.map[values] = value;
    } else {
        addAll(this.map, values);
    }
}

/**
 * Remove keys from map.
 *
 * When the second argument is passed, it is treated as
 * a single value and the first parameter as a key.
 * Otherwise, every value in the first argument is added.
 *
 * @this DatamapInterface
 * @param {Array.<string>|string} keys
 */

function remove(values) {
    if (typeof values === 'string') {
        this.map[values] = undefined;
    } else {
        removeAll(this.map, values);
    }
}

/**
 * Get all values.
 *
 * @this DatamapInterface
 * @return {Object.<string, *>}
 */

function all() {
    var values;

    values = {};

    addAll(values, this.map);

    return values;
}

/**
 * Get a value.
 *
 * @this DatamapInterface
 * @param {string} key
 * @return {*}
 */

function get(key) {
    return has(this.map, key) ? this.map[key] : null;
}

/**
 * Whether or not `value` is in context.
 *
 * @this DatamapInterface
 * @param {*} value
 * @return {boolean}
 */

function datamapHas(key) {
    return has(this.map, key);
}

/**
 * Expose methods on prototype.
 */

var datamapInterfacePrototype;

datamapInterfacePrototype = DatamapInterface.prototype;

datamapInterfacePrototype.add = add;

datamapInterfacePrototype.remove = remove;

datamapInterfacePrototype.all = all;

datamapInterfacePrototype.get = get;

datamapInterfacePrototype.has = datamapHas;

/**
 * Expose `DatamapInterface`.
 */

module.exports = DatamapInterface;
{'fraction_non_alphanumeric': 0.14301409998168835, 'fraction_numerical': 0.0003662332906061161, 'mean_word_length': 3.234108527131783, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 14, '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': '5114234', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1731, 'n_words': 439}