<commit_before>/**
* Implement core functionalities.
*
* @license   MIT
* @version   1.0.0
* @copyright 2016 Onl'Fait (http://www.onlfait.ch)
* @author    <NAME> (skarab) <<EMAIL>>
* @link      https://github.com/lautr3k/Toys
* @module    Toys
* @submodule ToysCore
*/

/**
* Implement core functionalities shared by Toys and his modules.
*
* @class     ToysCore
* @extends   JSClass
* @uses      lib/lodash
*/
var ToysCore = JSClass(
{
    /**
    * Get property value at 'dotted.path.index'.
    *
    * @method get
    * @param  {String} path
    * @param  {Mixed}  [defaultValue]
    * @return {Mixed}
    */
    get: function(path, defaultValue)
    {
        return _.get(this, path, defaultValue);
    },

    /**
    * Set property value at 'dotted.path.index'.
    *
    * @method set
    * @param  {String} path
    * @param  {Mixed}  value
    * @chainable
    */
    set: function(path, value)
    {
        return _.set(this, path, value);
    },

    /**
    * Return if has property at 'dotted.path.index'.
    *
    * @method has
    * @param  {String} path
    * @return {Boolean}
    */
    has: function(path)
    {
        return _.has(this, path);
    },

    /**
     * Get config value at 'dotted.path.index'.
     *
     * @method getConfig
     * @param  {String} path
     * @param  {Mixed}  [defaultValue]
     * @return {Mixed}
     */
    getConfig: function(path, defaultValue)
    {
        return (this.kernel || this).get('config.' + path, defaultValue);
    },

    /**
     * Get translated and formatted text for current language at 'dotted.path.index'.
     *
     * @method getText
     * @param  {String} path
     * @param  {Mixed}  [data]
     * @param  {String} [lang=en]
     * @throws {Error}
     * @return {String}
     */
    getText: function(path, data, lang)
    {
        var toys = this.kernel || this;

        lang  = lang || this.getConfig('lang', 'en');

        var rootKey  = 'texts.' + lang + '.';
        var localKey = this.name + '.' + path;

        var key  = rootKey + localKey;
        var text = toys.get(key);

        // Local key does not exist
        if (! text)
        {
            // Text fall back in global scope
            text = toys.get(rootKey + path);

            // Do not notify next time
            toys.set(key, text || path);

            if (! text)
            {
                // Text fall back to input path
                text = path;

                // Print a warning message in the console
                this.message('warn', 'ToysKernel.undefinedTextPath',
                {
                    path: localKey,
                    lang: lang
                });
            }
        }

        try
        {
            if (data)
            {
                // Use lodash template to format the text
                text = _.template(text)(data || {});
            }
        }
        catch (error)
        {
            // Throw custom error
            this.error('Toys.parseTextError',
            {
                error: error,
                lang : lang,
                path : localKey,
                text : text
            });
        }

        return text;
    },

    /**
    * Console message wrapper with translation and formatting.
    *
    * @method message
    * @param  {String} type
    * @param  {String} text
    * @param  {Object} [data]
    * @return {String}
    */
    message: function(type, text, data)
    {
        // Get translated/formatted text
        text = this.getText(text, data);

        // Print text in console prefixed with module name
        console[type](this.name + ' >>> ' + text);

        // Return translated/formatted text
        return text;
    },

    /**
    * Warning message with translation and formatting.
    *
    * @method warning
    * @param  {String} text
    * @param  {Object} [data]
    */
    warning: function(text, data)
    {
        this.message('warn', text, data);
    },

    /**
    * Throw and log an error with message translation and formatting.
    *
    * @method error
    * @param  {String} text
    * @param  {Object} [data]
    */
    error: function(text, data)
    {
        throw this.message('error', text, data);<commit_msg>add info message alias<commit_after>/**
* Implement core functionalities.
*
* @license   MIT
* @version   1.0.0
* @copyright 2016 Onl'Fait (http://www.onlfait.ch)
* @author    <NAME> (skarab) <<EMAIL>>
* @link      https://github.com/lautr3k/Toys
* @module    Toys
* @submodule ToysCore
*/

/**
* Implement core functionalities shared by Toys and his modules.
*
* @class     ToysCore
* @extends   JSClass
* @uses      lib/lodash
*/
var ToysCore = JSClass(
{
    /**
    * Get property value at 'dotted.path.index'.
    *
    * @method get
    * @param  {String} path
    * @param  {Mixed}  [defaultValue]
    * @return {Mixed}
    */
    get: function(path, defaultValue)
    {
        return _.get(this, path, defaultValue);
    },

    /**
    * Set property value at 'dotted.path.index'.
    *
    * @method set
    * @param  {String} path
    * @param  {Mixed}  value
    * @chainable
    */
    set: function(path, value)
    {
        return _.set(this, path, value);
    },

    /**
    * Return if has property at 'dotted.path.index'.
    *
    * @method has
    * @param  {String} path
    * @return {Boolean}
    */
    has: function(path)
    {
        return _.has(this, path);
    },

    /**
     * Get config value at 'dotted.path.index'.
     *
     * @method getConfig
     * @param  {String} path
     * @param  {Mixed}  [defaultValue]
     * @return {Mixed}
     */
    getConfig: function(path, defaultValue)
    {
        return (this.kernel || this).get('config.' + path, defaultValue);
    },

    /**
     * Get translated and formatted text for current language at 'dotted.path.index'.
     *
     * @method getText
     * @param  {String} path
     * @param  {Mixed}  [data]
     * @param  {String} [lang=en]
     * @throws {Error}
     * @return {String}
     */
    getText: function(path, data, lang)
    {
        var toys = this.kernel || this;

        lang  = lang || this.getConfig('lang', 'en');

        var rootKey  = 'texts.' + lang + '.';
        var localKey = this.name + '.' + path;

        var key  = rootKey + localKey;
        var text = toys.get(key);

        // Local key does not exist
        if (! text)
        {
            // Text fall back in global scope
            text = toys.get(rootKey + path);

            // Do not notify next time
            toys.set(key, text || path);

            if (! text)
            {
                // Text fall back to input path
                text = path;

                // Print a warning message in the console
                this.message('warn', 'ToysKernel.undefinedTextPath',
                {
                    path: localKey,
                    lang: lang
                });
            }
        }

        try
        {
            if (data)
            {
                // Use lodash template to format the text
                text = _.template(text)(data || {});
            }
        }
        catch (error)
        {
            // Throw custom error
            this.error('Toys.parseTextError',
            {
                error: error,
                lang : lang,
                path : localKey,
                text : text
            });
        }

        return text;
    },

    /**
    * Console message wrapper with translation and formatting.
    *
    * @method message
    * @param  {String} type
    * @param  {String} text
    * @param  {Object} [data]
    * @return {String}
    */
    message: function(type, text, data)
    {
        // Get translated/formatted text
        text = this.getText(text, data);

        // Print text in console prefixed with module name
        console[type](this.name + ' >>> ' + text);

        // Return translated/formatted text
        return text;
    },

    /**
    * Info message with translation and formatting.
    *
    * @method info
    * @param  {String} text
    * @param  {Object} [data]
    */
    info: function(text, data)
    {
        this.message('info', text, data);
    },

    /**
    * Warning message with translation and formatting.
    *
    * @method warning
    * @param  {String} text
    * @param  {Object} [data]
    */
    warning: function(text, data)
    {
        this.message('warn', text, data);
    },

    /**
    * Throw and log an error with message translation and formatting.
    *
    * @method error
    * @param  {String} text
    * @param  {Object} [data]
    */
    error: function(text, data)
    {
        throw this.message('error', text, data);
{'fraction_non_alphanumeric': 0.1288505747126437, 'fraction_numerical': 0.0018390804597701149, 'mean_word_length': 1.5531103286384977, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1516294', 'n_tokens_mistral': 2679, 'n_tokens_neox': 2586, 'n_words': 704}