{"size": 6597, "ext": "js", "max_stars_repo_path": "dist/umd.react-log.js", "max_stars_repo_name": "dreipol/react-log", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dist/umd.react-log.js", "max_issues_repo_name": "dreipol/react-log", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dist/umd.react-log.js", "max_forks_repo_name": "dreipol/react-log", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.1804878049, "max_line_length": 122, "alphanum_fraction": 0.525541913}
(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
    typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
    (factory((global.ReactLogger = {}),global.React));
}(this, (function (exports,React) { 'use strict';

    React = React && React.hasOwnProperty('default') ? React['default'] : React;

    /**
     * Apply a color to the part of the console output that is generated by the logger. This concatenates previous output!
     * @param {Array} result - The initial output args
     * @param {object} data - The data object with all necessary runtine information
     * @param {object} data.level - The output's log level object
     * @return {Array} The resulting output args
     */
    function colorize(result, { level }) {
        const { color } = level;
        const styles = color ? `color: ${ color }` : '';

        if (styles) {
            result = [`%c${ result.join(' ') }`, styles];
        }

        return result;
    }

    /**
     * Prepend the log level label to the output
     * @param {Array} result - The initial output args
     * @param {object} data - The data object with all necessary runtine information
     * @param {object} data.level - The output's log level object
     * @return {Array} The resulting output args
     */
    function iconize(result, { level }) {
        const { label } = level;

        if (label) {
            result.unshift(`${ label }`);
        }

        return result;
    }

    /**
     * Prepend a location to the output if available
     * @param {Array} result - The initial output args
     * @param {object} data - The data object with all necessary runtine information
     * @param {object} data.config - The config that the logger was invoked with
     * @return {Array} The resulting output args
     */
    function localize(result, { config }) {
        const { location } = config.context;

        if (location) {
            result.unshift(`[${ location }]`);
        }

        return result;
    }

    const presets = {
        logger: window.console,
        proxy: true,
        context: {},
        filter: () => true,
        levels: [
            {
                name: 'debug',
                fn: window.console.debug,
                label: '🗒',
                color: 'grey',
            },
            {
                name: 'log',
                fn: window.console.log,
                label: '📎',
                color: 'grey',
            },
            {
                name: 'info',
                fn: window.console.info,
                label: '💎️',
                color: '#6060BA',
            },
            {
                name: 'warn',
                fn: window.console.warn,
                label: '',
                color: '#817123',
            },
            {
                name: 'error',
                fn: window.console.error,
                label: '',
                color: '#A16666',
            },
        ],
        middlewares: [localize, iconize, colorize],
    };

    /**
     * Just a noop
     */
    function noop() {
        // NOTE: Intentionally do nothing
    }

    /**
     * Define loggers for vue instances
     * @param {object} target - The host object
     * @param {object} config - A config object for the logger instance
     * @param {object} instance - A vue component instance that is allowed to influence part of the logging string
     * @return {function} The original target object enhanced with a logger instance
     */
    function createLogger(target, config, instance) {
        const { context, filter, levels, logger, middlewares, proxy } = config; // eslint-disable-line no-unused-vars

        return levels.reduce((host, level) => {
            return Object.defineProperty(host, level.name, {
                get() {
                    if (!level.fn || !filter({ config, level, instance })) {
                        return noop;
                    }

                    if (proxy) {
                        const args = middlewares.reduce((acc, m) => m(acc, { level, config, instance }), []);
                        return level.fn.bind(logger, ...args);
                    }

                    return function(...statements) {
                        const args = middlewares.reduce((acc, m) => m(acc, { level, config, instance, statements }), []);
                        level.fn.call(logger, ...args);
                    };
                },
            });
        }, target);
    }

    function createConfig(...cfg) {
        return Object.assign({}, presets, ...cfg);
    }

    /**
     * Create a new logger instance with your custom params and configs
     * @param   {object} target - target object that will be automatically extended with the logger methods
     * @see {@link https://github.com/dreipol/abstract-log#config}
     * @param   {object} config - logger configuration
     * @return {object} logger object
     * @example
     *
     * import { create } from '@dreipol/react-log'
     *
     * const logger = create()
     *
     * logger.warn('This is a warning!')
     */
    const create = (target = {}, config = createConfig()) => createLogger(target, config);

    /**
     * Logger context creation. It's an object containing the `<Provider/>` and the `<Consumer/>`
     * @type { Consumer, Provider }
     * @see {@link https://reactjs.org/docs/context.html#api}
     */
    const Logger = React.createContext(create());

    /**
     * Logger context Provider. It can be used to override the default log methods
     * @type { Provider }
     * @see {@link https://reactjs.org/docs/context.html#provider}
     * @example
     *
     * import { Consumer, Provider } from '@dreipol/react-log'
     *
     * <Provider value={console}>
     *     <Consumer>
     *          { ({log}) => <App log={log}/> }
     *     </Consumer>
     * </Provider>
     */

    const Provider = Logger.Provider;
    /**
     * Logger context consumer
     * @type { Consumer }
     * @see {@link https://reactjs.org/docs/context.html#consumer}
     * @example
     *
     * import { Consumer } from '@dreipol/react-log'
     *
     * <Consumer>
     *     { ({log}) => <App log={log}/> }
     * </Consumer>
     */
    const Consumer = Logger.Consumer;

    exports.create = create;
    exports.Logger = Logger;
    exports.Provider = Provider;
    exports.Consumer = Consumer;
    exports.default = Consumer;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
