<commit_before>const _     = require('lodash');
const chalk = require('chalk');

const pad = msg => `\n${msg}\n`;

module.exports = ({

    verbose = 0,
    fmtInfo = chalk.grey,
    fmtError = chalk.red,
    fmtBold = chalk.bold,
    fmtSuccess = chalk.green,
    fmtPad = pad,
    raw = false,

} = {}) => (event, info) => { // eslint-disable-line no-unused-vars

    if (raw) return JSON.stringify(event);

    if (event.result) {
        const data = event.result.data;
        if (data === undefined) {
            if (verbose >= 2) return fmtInfo(`${event.result.action} returned undefined`);
        }
        else if (_.isString(data) || _.isNumber(data)) return data;

        // TODO allow the ACTION to specify a custom serializer for the
        // result to the console
        else return JSON.stringify(data, null, 2);
    }

    if (event.error) {
        return fmtError(event.error);
    }

    if (verbose >= 1) {
        if (event.runAction) {
            return fmtBold(fmtPad(event.runAction));
        }
        if (event.done) {
            return fmtSuccess(fmtPad(`✔ [${event.done.action}]`));
        }
    }
};<commit_msg>remove padding in console output<commit_after>const _     = require('lodash');
const chalk = require('chalk');

module.exports = ({

    verbose = 0,
    fmtInfo = chalk.grey,
    fmtError = chalk.red,
    fmtBold = chalk.bold,
    fmtSuccess = chalk.green,
    raw = false,

} = {}) => (event, info) => { // eslint-disable-line no-unused-vars

    if (raw) return JSON.stringify(event);

    if (event.result) {
        const data = event.result.data;
        if (data === undefined) {
            if (verbose >= 2) return fmtInfo(`${event.result.action} returned undefined`);
        }
        else if (_.isString(data) || _.isNumber(data)) return data;

        // TODO allow the ACTION to specify a custom serializer for the
        // result to the console
        else return JSON.stringify(data, null, 2);
    }

    if (event.error) {
        return fmtError(event.error.stack ? event.error.stack : event.error);
    }

    if (verbose >= 1) {
        if (event.runAction) {
            return fmtBold(event.runAction);
        }
        if (event.done) {
            return fmtSuccess(`✔ [${event.done.action}]`);
        }
    }
};
{'fraction_non_alphanumeric': 0.14535137494543868, 'fraction_numerical': 0.003491924923614142, 'mean_word_length': 2.1701244813278007, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '1433704', 'n_tokens_mistral': 729, 'n_tokens_neox': 703, 'n_words': 178}