<commit_before>/************************************************
*  Library: KickStart - Minimalistic Framework
*   - Dependencies: jQuery
**/

var kickStart = (function () {
    // public scope

    var app = {
        _conf   : {
            name    : 'unnamed',
            baseURL : '',
            cache   : false,
            modules : {},
            verbose : true
        },
        define    : define,
        require   : require,
        register  : register
    };
    if (!window.app) window.app = app;
    return app;

    // ===========================================
    // -- Define modules

    function define(mod, callBack) {
        // if string - it is path to the file
        if (typeof mod == 'string') {
            $.ajax({
                url      : app._conf.baseURL + mod,
                dataType : 'text',
                cache    : app._conf.cache,
                success : function (data, success, xhr) {
                    if (success != 'success') {
                        if (app._conf.verbose) console.log('ERROR: error while loading module definition from "'+ mod +'".');
                        return;
                    }
                    try {
                        mod = JSON.parse(data);
                    } catch (e) {
                        if (app._conf.verbose) console.log('ERROR: not valid JSON file  "'+ mod +'".\n'+ e);
                        return;
                    }
                    _process(mod);
                    if (typeof callBack == 'function') callBack();

                },
                error : function (data, err, errData) {
                    if (app._conf.verbose) console.log('ERROR: error while loading module definition from "'+ mod +'".');
                }
            });
        } else {
            _process(mod);
            if (typeof callBack == 'function') callBack();
        }

        function _process(mod) {
            for (var m in mod) {
                if (Array.isArray(mod[m].assets)) {
                    if (app._conf.modules.hasOwnProperty(m)) {
                        if (app._conf.verbose) console.log('ERROR: module ' + m + ' is already registered.');
                    }
                    app._conf.modules[m] = $.extend({ assets: {} }, mod[m], { ready: false, files: {} });
                } else {
                    _process(mod[m]);
                }
            }
        }
    }

    // ===========================================
    // -- Register module

    function register(name, moduleFunction) {
        // check if modules id defined
        if (app.hasOwnProperty(name)) {
            if (app._conf.verbose) console.log('ERROR: Namespace '+ name +' is already registered');
            return false;
        }
        if (!app._conf.modules.hasOwnProperty(name)) {
            if (app._conf.verbose) console.log('ERROR: Namespace '+ name +' is not defined, first define it with kickStart.define');
            return false;
        }
        // register module
        var mod = app._conf.modules[name];
        // init module
        app[name] = moduleFunction(mod.files, mod);
        app._conf.modules[name].ready = true;
        return;
    }

    // ===========================================
    // -- Load Modules

    function require(names, callBack) { // returns promise
        if (!$.isArray(names)) names = [names];
        var modCount = names.length;
        var failed  = false;
        var promise = {
            ready: function (callBack) {     // a module loaded
                promise._ready = callBack;
                return promise;
            },
            fail: function (callBack) {     // a module loading failed
                promise._fail = callBack;
                return promise;
            },
            done: function (callBack) {        // all loaded
                promise._done = callBack;
                return promise;
            },
            always: function (callBack) {
                promise._always = callBack;
                return promise;
            }
        };
        setTimeout(function () {
            for (var n in names) {
                var name = names[n];
                // already loaded ?
                if (typeof app[name] != 'undefined') {
                    modCount--;
                    isFinished();
                } else if (typeof app._conf.modules[name] == 'undefined') {
                    if (app._conf.verbose) console.log('ERROR: module ' + name + ' is not defined.');
                } else {
                    (function (name) { // need closure
                        // load dependencies
                        getFiles(app._conf.modules[name].assets.concat([app._conf.modules[name].start]), function (files) {
                            var start = files[app._conf.modules[name].start];
                            delete files[app._conf.modules[name].start];
                            // register assets
                            app._conf.modules[name].files  = files;
                            app._conf.modules[name].ready  = true;
                            // execute start file
                            try {
                                eval(start);
                            } catch (e) {
                                failed = true;
                                // find error line
                                var err = e.stack.split('\n');
                                var tmp = err[1].match(/<anonymous>:([\d]){1,10}:([\d]{1,10})/gi);
                                if (tmp) tmp = tmp[0].split(':');
                                if (tmp) {
                                    // display error
                                    if (app._conf.verbose) {
                                        console.error('ERROR: ' + err[0] + ' ==> ' + app._conf.modules[name].start + ', line: '+ tmp[1] + ', character: '+ tmp[2]);
                                        console.log(e.stack);
                                    }
                                } else {
                                    if (app._conf.verbose) {
                                        console.error('ERROR: ' + app._conf.modules[name].start);
                                        console.log(e.stack);
                                    }
                                }
                                // if (typeof app.conf.fail == 'function') app.conf.fail(app._conf.modules[name]);
                                if (typeof promise._fail == 'function') promise._fail(app._conf.modules[name]);
                            }
                            // check ready
                            // if (typeof app.conf.ready == 'function') app.conf.ready(app._conf.modules[name]);
                            if (typeof promise._ready == 'function') promise._ready(app._conf.modules[name]);
                            modCount--;
                            isFinished();<commit_msg>Update ks-core.js<commit_after>/************************************************
*  Library: KickStart - Minimalistic Framework
*   - Dependencies: jQuery
**/

var kickStart = (function () {
    // public scope

    var app = {
        _conf   : {
            name    : 'unnamed',
            baseURL : '',
            cache   : false,
            modules : {},
            verbose : true
        },
        define    : define,
        require   : require,
        register  : register
    };
    if (!window.app) window.app = app;
    return app;

    // ===========================================
    // -- Define modules

    function define(mod, callBack) {
        // if string - it is path to the file
        if (typeof mod == 'string') {
            $.ajax({
                url      : app._conf.baseURL + mod,
                dataType : 'text',
                cache    : app._conf.cache,
                success : function (data, success, xhr) {
                    if (success != 'success') {
                        if (app._conf.verbose) console.log('ERROR: error while loading module definition from "'+ mod +'".');
                        return;
                    }
                    try {
                        mod = JSON.parse(data);
                    } catch (e) {
                        if (app._conf.verbose) console.log('ERROR: not valid JSON file  "'+ mod +'".\n'+ e);
                        return;
                    }
                    _process(mod);
                    if (typeof callBack == 'function') callBack();

                },
                error : function (data, err, errData) {
                    if (app._conf.verbose) console.log('ERROR: error while loading module definition from "'+ mod +'".');
                }
            });
        } else {
            _process(mod);
            if (typeof callBack == 'function') callBack();
        }

        function _process(mod) {
            for (var m in mod) {
                if (Array.isArray(mod[m].assets)) {
                    if (app._conf.modules.hasOwnProperty(m)) {
                        if (app._conf.verbose) console.log('ERROR: module ' + m + ' is already registered.');
                    }
                    app._conf.modules[m] = $.extend({ assets: {} }, mod[m], { ready: false, files: {} });
                } else {
                    _process(mod[m]);
                }
            }
        }
    }

    // ===========================================
    // -- Register module

    function register(name, moduleFunction) {
        // check if modules id defined
        if (app.hasOwnProperty(name)) {
            if (app._conf.verbose) console.log('ERROR: Namespace '+ name +' is already registered');
            return false;
        }
        if (!app._conf.modules.hasOwnProperty(name)) {
            if (app._conf.verbose) console.log('ERROR: Namespace '+ name +' is not defined, first define it with kickStart.define');
            return false;
        }
        // register module
        var mod = app._conf.modules[name];
        // init module
        app[name] = moduleFunction(mod.files, mod);
        app._conf.modules[name].ready = true;
        return;
    }

    // ===========================================
    // -- Load Modules

    function require(names, callBack) { // returns promise
        if (!$.isArray(names)) names = [names];
        var modCount = names.length;
        var failed  = false;
        var promise = {
            ready: function (callBack) {     // a module loaded
                promise._ready = callBack;
                return promise;
            },
            fail: function (callBack) {     // a module loading failed
                promise._fail = callBack;
                return promise;
            },
            done: function (callBack) {        // all loaded
                promise._done = callBack;
                return promise;
            },
            always: function (callBack) {
                promise._always = callBack;
                return promise;
            }
        };
        setTimeout(function () {
            for (var n in names) {
                var name = names[n];
                // already loaded ?
                if (typeof app[name] != 'undefined') {
                    modCount--;
                    isFinished();
                } else if (typeof app._conf.modules[name] == 'undefined') {
                    if (app._conf.verbose) console.log('ERROR: module ' + name + ' is not defined.');
                } else {
                    (function (name) { // need closure
                        // load dependencies
                        getFiles(app._conf.modules[name].assets.concat([app._conf.modules[name].start]), function (files) {
                            var start = files[app._conf.modules[name].start];
                            delete files[app._conf.modules[name].start];
                            // register assets
                            app._conf.modules[name].files  = files;
                            app._conf.modules[name].ready  = true;
                            // execute start file
                            eval(start); // if in try block, it would not show errors properly
                            // check ready
                            if (typeof promise._ready == 'function') promise._ready(app._conf.modules[name]);
                            modCount--;
                            isFinished();
{'fraction_non_alphanumeric': 0.14182518661208765, 'fraction_numerical': 0.000882895898547235, 'mean_word_length': 1.1427343078245915, 'pattern_counts': {'":': 0, '<': 4, '<?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': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6167465', 'n_tokens_mistral': 3001, 'n_tokens_neox': 2874, 'n_words': 709}