<commit_before>var exec, load;

(function(global) {
    'use strict';
    
    if (typeof module !== 'undefined' && module.exports)
        module.exports      = new LoadRemote();
    else
        global.loadRemote   = new LoadRemote();
        
    function LoadRemote() {
        var loadRemote  = function(name, options, callback) {
                var o       = options,
                    prefix  = o.prefix || '/',
                    funcs   = [
                        loadModules,
                        loadOptions
                    ].map(function(fn) {
                        return setPrefix(prefix, fn);
                    });
                
                if (!callback) {
                    callback    = options;
                    o           = {};
                }
                
                if (o.name && global[o.name])
                    callback();
                else
                    exec.parallel(funcs, function(error, modules, config) {
                        var remoteTmpls, local, remote,
                            online, module, isArray, version,
                            
                            funcON      = function() {
                                load.parallel(remote, function(error) {
                                    if (error)
                                        funcOFF();
                                    else
                                        callback();
                                });
                            },
                            
                            funcOFF     = function() {
                                load.parallel(local, callback);
                            };
                        
                        if (error) {
                            if (!module)
                                alert('Error: could not load module!');
                            
                            if (!config)
                                alert('Error: could not load config!');
                        } else {
                            online      = config.online && navigator.onLine,
                            module      = binom(name, modules),
                            
                            isArray     = Array.isArray(module.local),
                            version     = module.version;
                            
                            if (isArray) {
                                remoteTmpls = module.remote;
                                local       = module.local;
                            } else {
                               remoteTmpls  = [module.remote];
                               local        = [module.local];
                            }
                            
                            local   = local.map(function(url) {
                                return o.noPrefix ? url :prefix + url;
                            });
                            
                            remote  = remoteTmpls.map(function(tmpl) {
                                return tmpl.replace(/{{\sversion\s}}/g, version);
                            });
                            
                            exec.if(online, funcON, funcOFF);
                        }
                    });
                };
            
            loadRemote.load         = loadRemote;
            
            function setPrefix(prefix, fn) {
                return fn.bind(null, prefix);
            }
            
            function loadModules(prefix, callback) {
                var url = prefix + '/modules.json';
                
                load.json(url, callback);
            }
            
            function loadOptions(prefix, callback) {<commit_msg>feature(loadremote) add memo, amemo, once<commit_after>var exec, load;

(function(global) {
    'use strict';
    
    if (typeof module !== 'undefined' && module.exports)
        module.exports      = new LoadRemote();
    else
        global.loadRemote   = new LoadRemote();
        
    function LoadRemote() {
        var once = memo(amemo);
        
        var loadRemote  = function(name, options, callback) {
                var o       = options,
                    prefix  = o.prefix || '/',
                    funcs   = [
                        loadModules,
                        loadOptions
                    ].map(function(fn) {
                        return setPrefix(prefix, fn);
                    }).map(function(fn) {
                        return once(fn);
                    });
                
                if (!callback) {
                    callback    = options;
                    o           = {};
                }
                
                if (o.name && global[o.name])
                    callback();
                else
                    exec.parallel(funcs, function(error, modules, config) {
                        var remoteTmpls, local, remote,
                            online, module, isArray, version,
                            
                            funcON      = function() {
                                load.parallel(remote, function(error) {
                                    if (error)
                                        funcOFF();
                                    else
                                        callback();
                                });
                            },
                            
                            funcOFF     = function() {
                                load.parallel(local, callback);
                            };
                        
                        if (error) {
                            if (!module)
                                alert('Error: could not load module!');
                            
                            if (!config)
                                alert('Error: could not load config!');
                        } else {
                            online      = config.online && navigator.onLine,
                            module      = binom(name, modules),
                            
                            isArray     = Array.isArray(module.local),
                            version     = module.version;
                            
                            if (isArray) {
                                remoteTmpls = module.remote;
                                local       = module.local;
                            } else {
                               remoteTmpls  = [module.remote];
                               local        = [module.local];
                            }
                            
                            local   = local.map(function(url) {
                                return o.noPrefix ? url :prefix + url;
                            });
                            
                            remote  = remoteTmpls.map(function(tmpl) {
                                return tmpl.replace(/{{\sversion\s}}/g, version);
                            });
                            
                            exec.if(online, funcON, funcOFF);
                        }
                    });
                };
            
            loadRemote.load         = loadRemote;
            
            function setPrefix(prefix, fn) {
                return fn.bind(null, prefix);
            }
            
            function amemo(fn) {
                var result;
                
                return function(callback) {
                    if (result)
                        callback(null, result);
                    else
                        fn(function(error, data) {
                            if (data)
                                result = data;
                            
                            callback(error, result);
                        });
                };
            }
            
            function memo(fn) {
                var result;
                
                return function() {
                    if (!result)
                        result = fn.apply(null, arguments);
                    
                    return result;
                };
            }
            
            function loadModules(prefix, callback) {
                var url = prefix + '/modules.json';
                
                load.json(url, callback);
            }
            
            function loadOptions(prefix, callback) {
{'fraction_non_alphanumeric': 0.07593444169319656, 'fraction_numerical': 0.0, 'mean_word_length': 0.5955605718585403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5958063', 'n_tokens_mistral': 1705, 'n_tokens_neox': 1607, 'n_words': 332}