<commit_before>export class Configuration
{
    // ...
}<commit_msg>Implemented configuration, needs some checking.<commit_after>///<reference path="../../typings/main.d.ts" />

import * as _ from "lodash";

/**
 * Configuration container used to store data on runtime
 * @todo Throwing an exception when calling Configuration#get() if the key is not found would be smarter, as it's instantly clear a key doesn't exist
 * @todo Proposal to make Configuration#set() read-only, so it can't be overwritten once set
 */
export class Configuration
{
    /**
     * Container holding all configuration keys
     * @type {Object}
     */
    private data: {[s: string]: any} = {};

    /**
     * Fetch a key from the configuration data
     * @param {string} key
     * @returns {*}
     */
    get(key: string): any
    {
        var keyParts = key.split('.');
        return _.reduce(keyParts, (data, key) => !!data ? data[key] : undefined, this.data);
    }

    /**
     * Set a key in the configuration
     * @todo Why are we splitting the key exactly, can't we just store it as is? ~@Paradoxis
     * @param {string} key
     * @param {*} value
     * @returns {void}
     */
    set(key: string, value: any)
    {
        // Split the key into parts
        var keyParts = key.split('.');
        var data = this.data;

        // Loop over all the data
        _.forEach(keyParts, (key) => {
            if (key == _.last(keyParts)) {
                data[key] = value;
            } else {
                data[key] = typeof data[key] == 'object' ? data[key] : {};
            }

            data = data[key];
        });
    }
}
{'fraction_non_alphanumeric': 0.13655848132271892, 'fraction_numerical': 0.0, 'mean_word_length': 2.106463878326996, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '5429795', 'n_tokens_mistral': 483, 'n_tokens_neox': 469, 'n_words': 162}