<commit_before>'use strict';

const util = require('./util');

const registers = [];

const MATCHER_ID = 'bee-' + String(Math.random()).replace(/\D/, '');

let matcherIndex = 0;

function bee (data, beeConfig) {

    debugger;

    data = util.copy(data);

    registers.forEach((register) => {
        if (util.isFunction(register.before)) {
            register.before.call(null, data, beeConfig);
        }
    });

    processLoop(data, beeConfig, function (dataItem, beeItem, key, currentData, currentBee) {
        if (bee.isCustomKey(key)) {
            return;
        }

        let register = bee.getRegister(beeItem, dataItem);

        return register ?
            register.apply(beeItem, dataItem, key, currentData, currentBee) : {};
    });

    return util.copy(data);
}

function getAllMatchKeys (data) {
    if (!util.isObject(data)) {
        return [];
    }

    return Object.keys(data)
        .filter((key) => bee.isCustomKey(key))
        .map((key) => {
            let info = bee.parseKeyInfo(key);

            return {
                index: info.index,
                keyRegisters: registers.filter((register) => {
                    return register.keyCheck && register.keyCheck(info.info);
                }),
                bee: data[key],
                info: info.info
            };
        })
        .sort((a, b) => a.index - b.index);
}

bee.execute = function (dataItem, beeItem, key, currentData, currentBee) {
    let register = bee.getRegister(beeItem, dataItem);

    return register ?
        register.apply(beeItem, dataItem, key, currentData, currentBee) :
        {};
};

bee.getRegister = function (beeItem, dataItem) {
    return registers.filter((register) => {
        return register.check && register.check(beeItem, dataItem);
    })[0];
};

bee.isCustomKey = function (key) {
    return key.indexOf(MATCHER_ID) === 0;
};

bee.parseKeyInfo = function (key) {
    return JSON.parse(key.replace(MATCHER_ID, ''));
};

bee.register = function (config) {

    if (typeof config === 'function') {
        config = config(bee);
    }

    if (!util.isObject(config)) {
        throw(new Error('Expect config of register to be Object'));
    }

    if (config.hasOwnProperty('check') && !util.isFunction(config.check)) {
        throw(new Error('Expect config.check to be Function'));
    }

    if (config.hasOwnProperty('apply') && !util.isFunction(config.apply)) {<commit_msg>improve parse process of custom key<commit_after>'use strict';

const util = require('./util');

const registers = [];

const MATCHER_ID = 'bee-' + String(Math.random()).replace(/\D/, '');

let matcherIndex = 0;

function bee (data, beeConfig) {

    debugger;

    data = util.copy(data);

    registers.forEach((register) => {
        if (util.isFunction(register.before)) {
            register.before.call(null, data, beeConfig);
        }
    });

    processLoop(data, beeConfig, function (dataItem, beeItem, key, currentData, currentBee) {
        if (bee.isCustomKey(key)) {
            return;
        }

        let register = bee.getRegister(beeItem, dataItem);

        return register ?
            register.apply(beeItem, dataItem, key, currentData, currentBee) : {};
    });

    return util.copy(data);
}

function getAllMatchKeys (data) {
    if (!util.isObject(data)) {
        return [];
    }

    return Object.keys(data)
        .filter((key) => bee.isCustomKey(key))
        .map((key) => {
            let info = bee.parseKeyInfo(key);

            return {
                index: info.index,
                keyRegisters: registers.filter((register) => {
                    return register.keyCheck && register.keyCheck(info.info);
                }),
                bee: data[key],
                info: info.info
            };
        })
        .sort((a, b) => a.index - b.index);
}

bee.execute = function (dataItem, beeItem, key, currentData, currentBee) {
    let register = bee.getRegister(beeItem, dataItem);

    return register ?
        register.apply(beeItem, dataItem, key, currentData, currentBee) :
        {};
};

bee.getRegister = function (beeItem, dataItem) {
    return registers.filter((register) => {
        return register.check && register.check(beeItem, dataItem);
    })[0];
};

bee.isCustomKey = function (key) {
    return key.indexOf(MATCHER_ID) === 0;
};

bee.parseKeyInfo = function (key) {
    if (key.indexOf(MATCHER_ID) !== 0) {
        throw(new Error(`${key} isn't a custom key of object-bee.`));
    }
    return JSON.parse(key.slice(MATCHER_ID.length));
};

bee.register = function (config) {

    if (typeof config === 'function') {
        config = config(bee);
    }

    if (!util.isObject(config)) {
        throw(new Error('Expect config of register to be Object'));
    }

    if (config.hasOwnProperty('check') && !util.isFunction(config.check)) {
        throw(new Error('Expect config.check to be Function'));
    }

    if (config.hasOwnProperty('apply') && !util.isFunction(config.apply)) {
{'fraction_non_alphanumeric': 0.14985994397759103, 'fraction_numerical': 0.0014005602240896359, 'mean_word_length': 2.445210199862164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5779205', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1485, 'n_words': 320}