-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (33 loc) · 974 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
exports.__esModule = true;
exports.debug = function(prefix, options = {}) {
var prefixString = `[${prefix}]`;
function log() {
var args = Array.prototype.slice.call(arguments);
args.unshift(prefixString);
console.log.apply(console, args);
}
function error() {
var args = Array.prototype.slice.call(arguments);
args.unshift(prefixString);
console.error.apply(console, args);
}
function trace() {
console.log(`${prefixString} Trace`);
console.trace.apply(args);
}
return { log, error, trace };
}
module.exports = function(type = console.log) {
if (typeof type !== 'function') {
throw Error(`Output handler must be a function, you provided ${typeof type}.`);
}
return function(variable) {
var prefix = typeof variable;
if (typeof variable !== 'object' && typeof variable.name !== 'undefined') {
prefix = variable.name;
}
type(`[${prefix}]`, variable);
return variable;
}
}