<commit_before>ST = {};

/**
 * Helper functions to create DOM elements. Call using inputTag(), etc..
 *
 * Accepts any number of jQuery objects as parameters, which will be added
 * as children to the new element.
 *
 * @params {jQuery|DOMElement} children
 * @returns {jQuery} Element
 */
ST.aTag = function()
{
    var element = $(document.createElement('a')).attr('href', 'javascript:;');
    for (var i = 0; i < arguments.length; i++) {
        element.append(arguments[i]);
    }
    return element;
};
$.each(['address', 'area', 'article', 'aside', 'abbr', 'audio', 'b',
    'base', 'bdo', 'blockquote', 'body', 'br', 'button', 'canvas',
    'caption', 'cite', 'code', 'col', 'colgroup', 'command', 'datalist',
    'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em',
    'embed', 'fieldset', 'figure', 'footer', 'form', 'h1', 'h2', 'h3',
    'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i',
    'iframe', 'img', 'input', 'ins', 'kbd', 'keygen', 'label', 'legend',
    'li', 'link', 'map', 'mark', 'menu', 'meta', 'meter', 'nav',
    'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'pre',
    'progress', 'q', 'rp', 'rt', 'ruby', 'samp', 'script', 'section',
    'select', 'small', 'source', 'span', 'strong', 'style', 'sub',
    'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead',
    'time', 'title', 'tr', 'ul', 'var', 'video'], function()
{    
    var tag = this;
    ST[tag + 'Tag'] = function() {
        var element = $(document.createElement(tag));
        for (var i = 0; i < arguments.length; i++) {
            element.append(arguments[i]);
        }
        return element;
    }
});

/**
 * Creates a custom DOM element with specified name.
 *
 * @param {String} name
 * @returns {jQuery} element
 */
ST.customTag = function(name)
{
    return $(document.createElement(name));
};

/**
 * Converts a string to a function returns the named attribute of it's first
 * parameter, or (this) object.
 * 
 * If given attribute is a function, it will be called with any additional
 * arguments provided to stringToProc, and the result returned.
 *
 * @param {String} string String to convert
 * @returns {Function} Function
 */ 
ST.stringToProc = function(string)
{
    if (arguments.length > 1) {
        var passArgs = Array.prototype.slice.call(arguments, 1);
    } else {
        passArgs = [];
    }
    
    return function(o)
    {
        if (this && this[string] !== undefined) {
            if (this[string] && this[string].apply) {
                return this[string].apply(this, passArgs);
            } else {
                return this[string];
            }
        } else if (o && o[string] !== undefined) {
            if (o[string] && o[string].apply) {
                return o[string].apply(o, passArgs);
            } else {
                return o[string];
            }
        } else {
            return null;
        }
    };
};

/**
 * Converts an object to a function.
 * 
 * If the passed object is a string, it will be converted using 
 * ST.stringToProc.
 *
 * @param {Object} object Object to convert
 * @returns {Function} Function
 */
ST.P = ST.toProc = function(object)
{
    if (object.call) {
        return object;
    } else if (typeof object === 'string') {
        return ST.stringToProc(object);
    } else {
        ST.error('Could not convert object to Proc');
    }
};

/**
 * Creates a new STArray
 * 
 * @param {Array} to convert
 * @params {Object} Objects to add to array
 */
ST.A = ST.array = function(array) {
    if (array && array.push) return new STArray().append(array);
    else return new STArray().append(arguments);
};

/**
 * Traverse an object using the given path (delimited by `:`)
 */
ST.navigate = function(hash, path)
{
    var a = path.split(':');
    var o = hash;
    for (var i = 0; i < a.length; i++) {
        if (o && o[a[i]]) {
            o = o[a[i]];
        } else {
            return null;
        }
    }
    return o;
};

/**
 * Returns localization string. If vars are supplied, they will be
 * substituted into string using EJS.
 * 
 * @param {String} key Path to localization string.
 * @param {Object} vars Hash of variables to pass to EJS
 * @returns {String} Localized string
 */
ST.L = ST.locale = function(key, vars) {
    var l;
    if (LANG[key]) {
        l = LANG[key];
    } else {
        l = ST.navigate(LANG, key);
    }
    
    if (vars) {
        return new EJS({text: l}).render(vars);
    } else {
        return l;
    }
};

/* makeClass functions */

/**
 * Used to override an existing method of an STObject. Allows the overriding
 * method to call the overridden method using `this._super`, no matter how
 * many methods are chained together.
 *
 * If the method does not return a value, the STObject the method was called
 * will be returned, to allow chaining of methods
 *
 * @param {Function} oldMethod Method to override
 * @param {Function} newMethod Overriding method
 * @returns {Function} Chained method
 */<commit_msg>Replaced ST.L with simpler, more flexible ST.S<commit_after>ST = {};

/**
 * Helper functions to create DOM elements. Call using inputTag(), etc..
 *
 * Accepts any number of jQuery objects as parameters, which will be added
 * as children to the new element.
 *
 * @params {jQuery|DOMElement} children
 * @returns {jQuery} Element
 */
ST.aTag = function()
{
    var element = $(document.createElement('a')).attr('href', 'javascript:;');
    for (var i = 0; i < arguments.length; i++) {
        element.append(arguments[i]);
    }
    return element;
};
$.each(['address', 'area', 'article', 'aside', 'abbr', 'audio', 'b',
    'base', 'bdo', 'blockquote', 'body', 'br', 'button', 'canvas',
    'caption', 'cite', 'code', 'col', 'colgroup', 'command', 'datalist',
    'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em',
    'embed', 'fieldset', 'figure', 'footer', 'form', 'h1', 'h2', 'h3',
    'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i',
    'iframe', 'img', 'input', 'ins', 'kbd', 'keygen', 'label', 'legend',
    'li', 'link', 'map', 'mark', 'menu', 'meta', 'meter', 'nav',
    'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'pre',
    'progress', 'q', 'rp', 'rt', 'ruby', 'samp', 'script', 'section',
    'select', 'small', 'source', 'span', 'strong', 'style', 'sub',
    'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead',
    'time', 'title', 'tr', 'ul', 'var', 'video'], function()
{    
    var tag = this;
    ST[tag + 'Tag'] = function() {
        var element = $(document.createElement(tag));
        for (var i = 0; i < arguments.length; i++) {
            element.append(arguments[i]);
        }
        return element;
    }
});

/**
 * Creates a custom DOM element with specified name.
 *
 * @param {String} name
 * @returns {jQuery} element
 */
ST.customTag = function(name)
{
    return $(document.createElement(name));
};

/**
 * Converts a string to a function returns the named attribute of it's first
 * parameter, or (this) object.
 * 
 * If given attribute is a function, it will be called with any additional
 * arguments provided to stringToProc, and the result returned.
 *
 * @param {String} string String to convert
 * @returns {Function} Function
 */ 
ST.stringToProc = function(string)
{
    if (arguments.length > 1) {
        var passArgs = Array.prototype.slice.call(arguments, 1);
    } else {
        passArgs = [];
    }
    
    return function(o)
    {
        if (this && this[string] !== undefined) {
            if (this[string] && this[string].apply) {
                return this[string].apply(this, passArgs);
            } else {
                return this[string];
            }
        } else if (o && o[string] !== undefined) {
            if (o[string] && o[string].apply) {
                return o[string].apply(o, passArgs);
            } else {
                return o[string];
            }
        } else {
            return null;
        }
    };
};

/**
 * Converts an object to a function.
 * 
 * If the passed object is a string, it will be converted using 
 * ST.stringToProc.
 *
 * @param {Object} object Object to convert
 * @returns {Function} Function
 */
ST.P = ST.toProc = function(object)
{
    if (object.call) {
        return object;
    } else if (typeof object === 'string') {
        return ST.stringToProc(object);
    } else {
        ST.error('Could not convert object to Proc');
    }
};

/**
 * Creates a new STArray
 * 
 * @param {Array} to convert
 * @params {Object} Objects to add to array
 */
ST.A = ST.array = function(array) {
    if (array && array.push) return new STArray().append(array);
    else return new STArray().append(arguments);
};

/**
 * Traverse an object using the given path (delimited by `:`)
 */
ST.navigate = function(hash, path)
{
    var a = path.split(':');
    var o = hash;
    for (var i = 0; i < a.length; i++) {
        if (o && o[a[i]]) {
            o = o[a[i]];
        } else {
            return null;
        }
    }
    return o;
};

// Substitutes data in hash into template string
ST.S = function(string, data) {
    for (key in data) {
        string = string.replace(':' + key, data[key]);
    }
    return string;
};

/* makeClass functions */

/**
 * Used to override an existing method of an STObject. Allows the overriding
 * method to call the overridden method using `this._super`, no matter how
 * many methods are chained together.
 *
 * If the method does not return a value, the STObject the method was called
 * will be returned, to allow chaining of methods
 *
 * @param {Function} oldMethod Method to override
 * @param {Function} newMethod Overriding method
 * @returns {Function} Chained method
 */
{'fraction_non_alphanumeric': 0.17145505097312327, 'fraction_numerical': 0.0022654721449902175, 'mean_word_length': 2.687167805618831, 'pattern_counts': {'":': 0, '<': 9, '<?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': '7071724', 'n_tokens_mistral': 3079, 'n_tokens_neox': 3018, 'n_words': 1001}