<commit_before>/*global */
/*jslint browser: true*/
/**
 * TODO
 * If canny knows his own URL than canny could load none registered modules afterwords from his own
 * modules folder (can also build as configurable extension adapted to the body).
 * E.g.: canny-mod="moduleLoader" canny-var={'cannyPath':URL_FROM_CANNY, 'unknownMods':LOAD_FROM_OTHER_URL}
 *
 *
 * canny-var is deprecated: please use just the module name instead like:
 * E.g.: canny-mod="mod1 mod2" canny-mod1={'foo':'123456', 'bar':'654321'} canny-mod2="mod2Property"
 *
 * ---------------------------------------------------------------------------- eightyfour
 */
(function (global) {
    "use strict";
    var canny = (function () {
        var readyQueue = [],
            readyQueueInit = false,
            moduleQueue = [], // save modules to call the ready method once
            callMethQueue = function (queue) {
                (function reduce() {
                    var fc = queue.pop();
                    if (fc) {
                        fc();
                        reduce();
                    } else {
                        queue = [];
                    }
                }());
            },
            parseNode = function (node, name, cb) {
                var that = this, gdModuleChildren = [].slice.call(node.querySelectorAll('[' + name + '-mod]')), prepareReadyQueue = {};

                gdModuleChildren.forEach(function (node) {
                    var attribute = node.getAttribute(name + '-mod'), attr, viewPart, attributes, cannyVar;

                    attributes = attribute.split(' ');

                    attributes.forEach(function (eachAttr) {
                        if (that[eachAttr]) {
                            if (node.getAttribute(name + '-mod')) {
                                if (node.getAttribute(name + '-' + eachAttr)) {
                                    cannyVar = node.getAttribute(name + '-' + eachAttr);
                                } else {
                                    cannyVar = node.getAttribute(name + '-var');
                                }
                                if (cannyVar) {
                                    attr = cannyVar.split("\'").join('\"');
                                    if (/:/.test(attr)) {
                                        // could be a JSON
                                        try {
                                            viewPart = JSON.parse(attr);
                                        } catch (ex) {
                                            console.error("canny can't parse passed JSON for module: " + eachAttr, node);
                                        }
                                    } else {
                                        viewPart = attr;
                                    }
                                }
                            }
                            // has module a ready function than save it for calling
                            if (that[eachAttr].hasOwnProperty('ready')) {
                                // TODO or call it immediately?
                                prepareReadyQueue[eachAttr] = that[eachAttr].ready;
                            }
                            if (that.hasOwnProperty(eachAttr)) {
                                that[eachAttr].add(node, viewPart);
                            }
                        } else {
                            console.warn('canny parse: module with name ´' + eachAttr + '´ is not registered');
                        }
                    });
                });
                // add ready callback to moduleQueue
                Object.keys(prepareReadyQueue).forEach(function (name) {
                    moduleQueue.push(prepareReadyQueue[name]);
                });
                cb && cb();
            };

        document.addEventListener('DOMContentLoaded', function cannyDomLoad() {
            document.removeEventListener('DOMContentLoaded', cannyDomLoad);

            parseNode.apply(canny, [document, 'canny']);

            callMethQueue(moduleQueue);
            // call registered ready functions
            readyQueueInit = true;
            callMethQueue(readyQueue);
        }, false);

        return {
            add : function (name, module) {
                if (!this.hasOwnProperty(name)) {
                    this[name] = module;
                } else {
                    console.error('canny: Try to register module with name ' + name + ' twice');
                }
            },
            ready : function (fc) {
                if (!readyQueueInit) {
                    readyQueue.push(fc);
                } else {
                    fc();
                }
            },
            cannyParse : function (node, name, cb) {
                // TODO needs a callback
                if (typeof name === 'function') {
                    cb = name;
                    name = "canny";
                }
                parseNode.apply(this || canny, [node, name || 'canny', function () {
                    callMethQueue(moduleQueue);
                    cb && cb();
                }]);
            }
        };
    }());
    // export as module or bind to global
    if (typeof exports !== 'undefined') { exports = canny; } else {global.canny = canny; }
}(this));<commit_msg>fix issues that canny runs still with browserify and grunt<commit_after>/*global */
/*jslint browser: true*/
/**
 * TODO
 * If canny knows his own URL than canny could load none registered modules afterwords from his own
 * modules folder (can also build as configurable extension adapted to the body).
 * E.g.: canny-mod="moduleLoader" canny-var={'cannyPath':URL_FROM_CANNY, 'unknownMods':LOAD_FROM_OTHER_URL}
 *
 *
 * canny-var is deprecated: please use just the module name instead like:
 * E.g.: canny-mod="mod1 mod2" canny-mod1={'foo':'123456', 'bar':'654321'} canny-mod2="mod2Property"
 *
 * ---------------------------------------------------------------------------- eightyfour
 */
(function (global) {
    "use strict";
    var canny = (function () {
        var readyQueue = [],
            readyQueueInit = false,
            moduleQueue = [], // save modules to call the ready method once
            callMethQueue = function (queue) {
                (function reduce() {
                    var fc = queue.pop();
                    if (fc) {
                        fc();
                        reduce();
                    } else {
                        queue = [];
                    }
                }());
            },
            parseNode = function (node, name, cb) {
                var that = this, gdModuleChildren = [].slice.call(node.querySelectorAll('[' + name + '-mod]')), prepareReadyQueue = {};

                gdModuleChildren.forEach(function (node) {
                    var attribute = node.getAttribute(name + '-mod'), attr, viewPart, attributes, cannyVar;

                    attributes = attribute.split(' ');

                    attributes.forEach(function (eachAttr) {
                        if (that[eachAttr]) {
                            if (node.getAttribute(name + '-mod')) {
                                if (node.getAttribute(name + '-' + eachAttr)) {
                                    cannyVar = node.getAttribute(name + '-' + eachAttr);
                                } else {
                                    cannyVar = node.getAttribute(name + '-var');
                                }
                                if (cannyVar) {
                                    attr = cannyVar.split("\'").join('\"');
                                    if (/:/.test(attr)) {
                                        // could be a JSON
                                        try {
                                            viewPart = JSON.parse(attr);
                                        } catch (ex) {
                                            console.error("canny can't parse passed JSON for module: " + eachAttr, node);
                                        }
                                    } else {
                                        viewPart = attr;
                                    }
                                }
                            }
                            // has module a ready function than save it for calling
                            if (that[eachAttr].hasOwnProperty('ready')) {
                                // TODO or call it immediately?
                                prepareReadyQueue[eachAttr] = that[eachAttr].ready;
                            }
                            if (that.hasOwnProperty(eachAttr)) {
                                that[eachAttr].add(node, viewPart);
                            }
                        } else {
                            console.warn('canny parse: module with name ´' + eachAttr + '´ is not registered');
                        }
                    });
                });
                // add ready callback to moduleQueue
                Object.keys(prepareReadyQueue).forEach(function (name) {
                    moduleQueue.push(prepareReadyQueue[name]);
                });
                cb && cb();
            };

        document.addEventListener('DOMContentLoaded', function cannyDomLoad() {
            document.removeEventListener('DOMContentLoaded', cannyDomLoad);

            parseNode.apply(canny, [document, 'canny']);

            callMethQueue(moduleQueue);
            // call registered ready functions
            readyQueueInit = true;
            callMethQueue(readyQueue);
        }, false);

        return {
            add : function (name, module) {
                if (!this.hasOwnProperty(name)) {
                    this[name] = module;
                } else {
                    console.error('canny: Try to register module with name ' + name + ' twice');
                }
            },
            ready : function (fc) {
                if (!readyQueueInit) {
                    readyQueue.push(fc);
                } else {
                    fc();
                }
            },
            cannyParse : function (node, name, cb) {
                // TODO needs a callback
                if (typeof name === 'function') {
                    cb = name;
                    name = "canny";
                }
                parseNode.apply(this || canny, [node, name || 'canny', function () {
                    callMethQueue(moduleQueue);
                    cb && cb();
                }]);
            }
        };
    }());
    // export as module or bind to global
    if (typeof module !== 'undefined' && module.hasOwnProperty('exports')) { module.exports = canny; } else {global.canny = canny; }
}(this));
{'fraction_non_alphanumeric': 0.11904100712764973, 'fraction_numerical': 0.003147273905396649, 'mean_word_length': 1.0149198060425215, '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': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2662392', 'n_tokens_mistral': 2473, 'n_tokens_neox': 2333, 'n_words': 591}