<commit_before>var INHERIT = require('inherit');

module.exports = function(json, plugins, pluginsEngine) {

    var engine = new (pluginsEngine || PluginsEngine)();

    json = engine.pass(json, plugins.directPass);
    json = engine.pass(json, plugins.reversePass, true);

    return json;

};

var PluginsEngine = exports.PluginsEngine = INHERIT({

    _makePluginsList: function(arr) {

        return arr.map(function(plugin) {
            plugin.fn = require('../plugins/' + plugin.name)[plugin.name];

            return plugin;
        });

    },

    pass: function(json, plugins, reverse) {

        plugins = this._makePluginsList(plugins);

        function monkeys(data) {

            data.content = data.content.filter(function(item) {

                if (reverse && item.content) {
                    monkeys.call(this, item);
                }

                var filter = true;

                plugins.forEach(function(plugin) {
                    if (plugin.active && plugin.fn(item, plugin.params) === false) {
                        filter = false;
                    }
                });

                if (!reverse && item.content) {
                    monkeys.call(this, item);
                }

                return filter;

            }, this);
<commit_msg>lib/plugins: main filter function optimization<commit_after>var INHERIT = require('inherit');

module.exports = function(json, plugins, pluginsEngine) {

    var engine = new (pluginsEngine || PluginsEngine)();

    json = engine.pass(json, plugins.directPass);
    json = engine.pass(json, plugins.reversePass, true);

    return json;

};

var PluginsEngine = exports.PluginsEngine = INHERIT({

    _makePluginsList: function(arr) {

        return arr.map(function(plugin) {
            plugin.fn = require('../plugins/' + plugin.name)[plugin.name];

            return plugin;
        });

    },

    pass: function(json, plugins, reverse) {

        plugins = this._makePluginsList(plugins);

        function monkeys(data) {

            data.content = data.content.filter(function(item) {

                if (reverse && item.content) {
                    monkeys.call(this, item);
                }

                var filter = plugins.some(function(plugin) {
                    return plugin.active && plugin.fn(item, plugin.params) === false;
                });

                if (!reverse && item.content) {
                    monkeys.call(this, item);
                }

                return !filter;

            }, this);

{'fraction_non_alphanumeric': 0.12220039292730844, 'fraction_numerical': 0.0, 'mean_word_length': 1.7704026115342764, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5646300', 'n_tokens_mistral': 702, 'n_tokens_neox': 643, 'n_words': 137}