summaryrefslogtreecommitdiff
path: root/lib/internal/consoleFunc.js
blob: eb2e886789b49a04b15c37cf3fae02281e5537e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import arrayEach from 'lodash/_arrayEach';
import slice from './slice';
import wrapAsync from './wrapAsync';

export default function consoleFunc(name) {
    return function (fn/*, ...args*/) {
        var args = slice(arguments, 1);
        args.push(function (err/*, ...args*/) {
            var args = slice(arguments, 1);
            if (typeof console === 'object') {
                if (err) {
                    if (console.error) {
                        console.error(err);
                    }
                } else if (console[name]) {
                    arrayEach(args, function (x) {
                        console[name](x);
                    });
                }
            }
        })
        wrapAsync(fn).apply(null, args);
    };
}