Comparing version 0.0.13 to 0.0.14
@@ -45,3 +45,3 @@ /// <reference types="node" /> | ||
export declare namespace Debug { | ||
var formatArgs: (this: any, fun: any, timer: string, args: any[]) => void; | ||
var formatArgs: (this: any, fun: any, timer: string, trace: string, args: any[]) => void; | ||
var humanize: (ms: any) => string; | ||
@@ -66,12 +66,21 @@ var times: Record<string, [number, number]>; | ||
var fatal: (...args: any[]) => boolean; | ||
var fatalIcon: string; | ||
var error: (...args: any[]) => boolean; | ||
var errorIcon: string; | ||
var info: (...args: any[]) => boolean; | ||
var infoIcon: string; | ||
var warn: (...args: any[]) => boolean; | ||
var warnIcon: string; | ||
var debug: (...args: any[]) => boolean; | ||
var debugIcon: string; | ||
var trace: (...args: any[]) => boolean; | ||
var traceIcon: string; | ||
var time: (...args: any[]) => boolean; | ||
var timeIcon: string; | ||
var end: (...args: any[]) => boolean; | ||
var endIcon: string; | ||
var timeEnd: (...args: any[]) => boolean; | ||
var timeEndIcon: string; | ||
var now: () => [number, number]; | ||
var millis: (start: [number, number], offset?: number) => string; | ||
} |
@@ -30,3 +30,7 @@ "use strict"; | ||
let timer = ''; | ||
if (this && this.name === Debug.time.name) { | ||
let stack = ''; | ||
if (this === Debug.trace) { | ||
stack = new Error().stack.replace('Error', 'Trace'); | ||
} | ||
else if (this === Debug.time) { | ||
const label = args.shift() || 'default'; | ||
@@ -38,3 +42,3 @@ if (Debug.times[label]) | ||
} | ||
else if (this && this.name === Debug.timeEnd.name) { | ||
else if (this === Debug.timeEnd || this === Debug.end) { | ||
const label = args.shift() || 'default'; | ||
@@ -54,3 +58,3 @@ if (!Debug.times[label]) | ||
} | ||
args[0] = Debug.coerce(args[0]); | ||
args[0] = args.length ? Debug.coerce(args[0]) : ''; | ||
if (typeof args[0] !== 'string') { | ||
@@ -77,3 +81,3 @@ // Anything else let's inspect with %O | ||
}); // Apply env-specific formatting (colors, etc.) | ||
Debug.formatArgs.call(self, this, timer, args); | ||
Debug.formatArgs.call(self, this, timer, stack, args); | ||
const logFn = this || Debug.log; | ||
@@ -114,9 +118,9 @@ logFn.apply(self, args); | ||
*/ | ||
Debug.formatArgs = function formatArgs(fun, timer, args) { | ||
Debug.formatArgs = function formatArgs(fun, timer, trace, args) { | ||
const useColors = this.useColors; | ||
let level = ''; | ||
let z = 'log'; | ||
if (fun && fun.name !== 'log') { | ||
// TODO: Color code per level | ||
// fun.color | ||
let z = (fun.label || fun.name); | ||
z = (fun.label || fun.name); | ||
if (z === 'timeEnd') | ||
@@ -126,5 +130,10 @@ z = 'time'; | ||
z = 'debug'; | ||
level = `${z.toUpperCase()} `; | ||
} | ||
let level = `${z} `; | ||
if (this.useColors) { | ||
z = Debug[`${z}Icon`]; | ||
level = z ? (z + ' ') : level; | ||
} | ||
const name = `[${this.namespace}]`; | ||
const msg = trace ? trace.replace('Trace', args[0] !== '' ? 'Trace: ' + args[0] : 'Trace') : args[0]; | ||
if (useColors) { | ||
@@ -134,7 +143,7 @@ const c = this.color; | ||
const prefix = "".concat(colorCode, ";1m").concat(name, " \x1B[0m"); | ||
args[0] = level + prefix + timer + args[0].split('\n').join('\n' + prefix); | ||
args[0] = level + prefix + timer + msg.split('\n').join('\n' + level + prefix); | ||
args.push(colorCode + 'm+' + Debug.humanize(this.diff) + "\x1B[0m"); | ||
} | ||
else { | ||
args[0] = getDate() + level + name + ' ' + timer + args[0]; | ||
args[0] = getDate() + level + name + ' ' + timer + (args.length ? msg : ''); | ||
} | ||
@@ -352,17 +361,23 @@ }; | ||
}; | ||
Debug.fatalIcon = '🛑'; | ||
Debug.error = function error(...args) { | ||
return process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.errorIcon = '❗'; | ||
Debug.info = function info(...args) { | ||
return process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.infoIcon = 'ℹ️'; | ||
Debug.warn = function warn(...args) { | ||
return process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.warnIcon = '⚠️'; | ||
Debug.debug = function detail(...args) { | ||
return process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.debugIcon = '🔹'; | ||
Debug.trace = function trace(...args) { | ||
return process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.traceIcon = '🔻'; | ||
// TODO: Implement time/end | ||
@@ -372,8 +387,11 @@ Debug.time = function time(...args) { | ||
}; | ||
Debug.timeIcon = '🕛'; | ||
Debug.end = function end(...args) { | ||
return process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.endIcon = '🕗'; | ||
Debug.timeEnd = function timeEnd(...args) { | ||
return process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.timeEndIcon = '🕗'; | ||
Debug.now = function now() { | ||
@@ -380,0 +398,0 @@ return process.hrtime(); |
{ | ||
"name": "exer", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "Utils in TypeScript, Debug, NanoTimer ...", | ||
@@ -5,0 +5,0 @@ "author": "kbajalc@gmail.com", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106894
1648