<commit_before>import PropTypes from './PropTypes';
import {isArray,toArray,isFunction, isString, isRegExp} from './tutils';
import warning from './warning';

const concat = Function.apply.bind(Array.prototype.concat, []);

export default function loaderFactory(loaders = []) {
    const types = {load, list, add},
        api = {

            addLoader(loader){
                if (isArray(loader)) {
                    return loader.map(function (v) {
                        return this.addLoader(v);
                    }, this)
                }
                Object.keys(loader).forEach(function (key) {
                    if (!(key in this)) {
                        var parts = /^(load|list)(.*)/.exec(key);
                        if (parts && parts.length > 2 && parts[1] in types) {
                            this[key] = types[parts[1]](parts[2]);
                        } else {
                            console.log('do not understand ' + key);
                        }
                    }
                }, this);

                loaders.unshift(loader);
                return loader;
            },
            removeLoader(loader){
                var idx = loaders.indexOf(loader);
                if (0 > idx) {
                    return;
                }
                var ret = loaders.splice(idx, 1)[0];
                if (ret && ret && ret.removeLoader) {
                    ret.removeLoader();
                }
                return ret;
            },

            clearLoaders(){
                var ret = loaders.concat();
                loaders.length = 0;
                return ret;
            }
        };


    function list(method) {
        var type = 'list' + method + 's';
        return function loader$list() {
            return concat(loaders.filter(function (v) {
                return typeof v[type] === 'function'
            }).map(function (v) {
                return v[type]();
            }));
        }
    }

    function load(method) {
        method = 'load' + method;
        return function load$load(load) {
            var i = 0, l = loaders.length, ret = null, scope;
            for (; i < l; i++) {
                var ret = loaders[i][method] && loaders[i][method].apply(this, arguments);
                if (ret != null) {
                    return ret;
                }
            }
        }
    }

    function add(type) {<commit_msg>Made it easy to extend loaderFactory<commit_after>import PropTypes from './PropTypes';
import {isArray,toArray,isFunction, isString, isRegExp} from './tutils';
import warning from './warning';

const concat = Function.apply.bind(Array.prototype.concat, []);

export default function loaderFactory(loaders = []) {
    const types = {load, list, add},
        api = {

            addLoader(loader){
                if (isArray(loader)) {
                    return loader.map(function (v) {
                        return this.addLoader(v);
                    }, this)
                }
                Object.keys(loader).forEach(function (key) {
                    if (!(key in this)) {
                        var parts = /^(load|list)(.*)/.exec(key);
                        if (parts && parts.length > 2 && parts[1] in types) {
                            this[key] = types[parts[1]](parts[2]);
                        } else {
                            console.log('do not understand ' + key);
                        }
                    }
                }, this);

                loaders.unshift(loader);
                return loader;
            },
            removeLoader(loader){
                var idx = loaders.indexOf(loader);
                if (0 > idx) {
                    return;
                }
                var ret = loaders.splice(idx, 1)[0];
                if (ret && ret && ret.removeLoader) {
                    ret.removeLoader();
                }
                return ret;
            },

            clearLoaders(){
                var ret = loaders.concat();
                loaders.length = 0;
                return ret;
            },
            loaderType
        };


    function list(method) {
        var type = 'list' + method + 's';
        return function loader$list() {
            return concat(loaders.filter(function (v) {
                return typeof v[type] === 'function'
            }).map(function (v) {
                return v[type]();
            }));
        }
    }

    function load(method) {
        method = 'load' + method;
        return function load$load(load) {
            var i = 0, l = loaders.length, ret = null, scope;
            for (; i < l; i++) {
                var ret = loaders[i][method] && loaders[i][method].apply(this, arguments);
                if (ret != null) {
                    return ret;
                }
            }
        }
    }

    function add(type) {
{'fraction_non_alphanumeric': 0.1226280350948786, 'fraction_numerical': 0.003672719853091206, 'mean_word_length': 1.1359477124183006, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4970869', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1212, 'n_words': 292}