Comparing version 0.0.34 to 0.0.35
@@ -98,3 +98,2 @@ /// <reference types="node" /> | ||
var alertIcon: string; | ||
var fatalIcon: string; | ||
var criticalIcon: string; | ||
@@ -104,3 +103,2 @@ var errorIcon: string; | ||
var warnIcon: string; | ||
var warningIcon: string; | ||
var noticeIcon: string; | ||
@@ -110,2 +108,3 @@ var debugIcon: string; | ||
var timeIcon: string; | ||
var endIcon: string; | ||
var log: (...args: any[]) => void; | ||
@@ -123,4 +122,4 @@ var emerg: (...args: any[]) => void; | ||
var time: (...args: any[]) => [number, number]; | ||
var end: (...args: any[]) => any; | ||
var timeEnd: (...args: any[]) => any; | ||
var end: (...args: any[]) => [number, number]; | ||
var timeEnd: (...args: any[]) => [number, number]; | ||
var millis: (span: [number, number], offset?: number) => string; | ||
@@ -127,0 +126,0 @@ } |
132
lib/debug.js
@@ -167,20 +167,8 @@ "use strict"; | ||
// TODO: Color code per level (fun.color) | ||
let z = fun && fun.name || ''; | ||
switch (z) { | ||
case 'log': | ||
z = ''; | ||
break; | ||
case 'detail': | ||
z = 'debug'; | ||
break; | ||
case 'timeEnd': | ||
z = 'time'; | ||
break; | ||
case 'end': | ||
z = 'time'; | ||
break; | ||
} | ||
let z = fun && fun.level || ''; | ||
let level = z.toUpperCase(); | ||
const tmp = level; | ||
level = level === 'END' ? 'TIME' : level; | ||
if (Debug.inspectOpts.systemd) { | ||
let num = DebugLevel[level || 'INFO']; | ||
let num = DebugLevel[tmp || 'INFO']; | ||
if (num === 8) | ||
@@ -191,3 +179,3 @@ num = 7; | ||
else if (this.useColors) { | ||
z = Debug[`${z}Icon`]; | ||
z = Debug[`${tmp.toLowerCase()}Icon`]; | ||
level = z ? (z + ' ') : level; | ||
@@ -464,88 +452,114 @@ } | ||
Debug.logIcon = ''; | ||
Debug.emergIcon = 'đ'; | ||
Debug.alertIcon = 'đ'; | ||
Debug.fatalIcon = 'đ'; | ||
Debug.criticalIcon = 'đ'; | ||
Debug.errorIcon = 'â'; | ||
Debug.emergIcon = 'â ī¸'; | ||
Debug.alertIcon = 'đĨ'; | ||
Debug.criticalIcon = 'â'; | ||
Debug.errorIcon = 'đ´'; | ||
Debug.infoIcon = 'âšī¸'; | ||
Debug.warnIcon = 'â ī¸'; | ||
Debug.warningIcon = 'â ī¸'; | ||
Debug.noticeIcon = 'â ī¸'; | ||
Debug.debugIcon = 'đš'; | ||
Debug.traceIcon = 'đ¸'; | ||
Debug.timeIcon = 'âąī¸'; | ||
Debug.noticeIcon = 'đ'; | ||
Debug.debugIcon = 'đˇ'; | ||
Debug.traceIcon = 'đļ'; | ||
Debug.timeIcon = 'âŗ'; | ||
Debug.endIcon = 'â'; | ||
/** | ||
* Invokes `util.format()` with the specified arguments and writes to stderr. | ||
*/ | ||
Debug.log = function log(...args) { | ||
function log(...args) { | ||
if (Debug.isBellow(DebugLevel.INFO)) | ||
return; | ||
Debug.useConsole() ? console.log(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.emerg = function emerg(...args) { | ||
} | ||
log.level = 'INFO'; | ||
Debug.log = log; | ||
function emerg(...args) { | ||
if (Debug.isBellow(DebugLevel.EMERG)) | ||
return; | ||
Debug.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.fatal = function fatal(...args) { | ||
} | ||
emerg.level = 'EMERG'; | ||
Debug.emerg = emerg; | ||
function fatal(...args) { | ||
if (Debug.isBellow(DebugLevel.ALERT)) | ||
return; | ||
Debug.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.alert = function alert(...args) { | ||
} | ||
fatal.level = 'ALERT'; | ||
Debug.fatal = fatal; | ||
function alert(...args) { | ||
if (Debug.isBellow(DebugLevel.ALERT)) | ||
return; | ||
Debug.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.critical = function critical(...args) { | ||
} | ||
alert.level = 'ALERT'; | ||
Debug.alert = alert; | ||
function critical(...args) { | ||
if (Debug.isBellow(DebugLevel.CRITICAL)) | ||
return; | ||
Debug.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.error = function error(...args) { | ||
} | ||
critical.level = 'CRITICAL'; | ||
Debug.critical = critical; | ||
function error(...args) { | ||
if (Debug.isBellow(DebugLevel.ERROR)) | ||
return; | ||
Debug.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.warn = function warn(...args) { | ||
} | ||
error.level = 'ERROR'; | ||
Debug.error = error; | ||
function warn(...args) { | ||
if (Debug.isBellow(DebugLevel.WARNING)) | ||
return; | ||
Debug.useConsole() ? console.warn(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.notice = function notice(...args) { | ||
} | ||
warn.level = 'WARN'; | ||
Debug.warn = warn; | ||
function notice(...args) { | ||
if (Debug.isBellow(DebugLevel.NOTICE)) | ||
return; | ||
Debug.useConsole() ? console.warn(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.info = function info(...args) { | ||
} | ||
notice.level = 'NOTICE'; | ||
Debug.notice = notice; | ||
function info(...args) { | ||
if (Debug.isBellow(DebugLevel.INFO)) | ||
return; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.debug = function detail(...args) { | ||
} | ||
info.level = 'INFO'; | ||
Debug.info = info; | ||
function detail(...args) { | ||
if (Debug.isBellow(DebugLevel.DEBUG)) | ||
return; | ||
Debug.useConsole() ? console.debug(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.trace = function trace(...args) { | ||
} | ||
detail.level = 'DEBUG'; | ||
Debug.debug = detail; | ||
function trace(...args) { | ||
if (Debug.isBellow(DebugLevel.TRACE)) | ||
return; | ||
Debug.useConsole() ? console.debug(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.time = function time(...args) { | ||
} | ||
trace.level = 'TRACE'; | ||
Debug.trace = trace; | ||
function time(...args) { | ||
if (Debug.isBellow(DebugLevel.TIME)) | ||
return void null; | ||
return; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
return void null; | ||
}; | ||
Debug.end = function end(...args) { | ||
} | ||
time.level = 'TIME'; | ||
Debug.time = time; | ||
function end(...args) { | ||
if (Debug.isBellow(DebugLevel.TIME)) | ||
return void null; | ||
return; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.timeEnd = function timeEnd(...args) { | ||
} | ||
end.level = 'END'; | ||
Debug.end = end; | ||
function timeEnd(...args) { | ||
if (Debug.isBellow(DebugLevel.TIME)) | ||
return void null; | ||
return; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
timeEnd.level = 'END'; | ||
Debug.timeEnd = timeEnd; | ||
Debug.millis = function millis(span, offset) { | ||
@@ -552,0 +566,0 @@ const ms = (span[0] * 1000) + Math.floor(span[1] / 1000000) - (offset || 0); |
{ | ||
"name": "exer", | ||
"version": "0.0.34", | ||
"version": "0.0.35", | ||
"description": "Utils in TypeScript, Debug, NanoTimer ...", | ||
@@ -5,0 +5,0 @@ "author": "kbajalc@gmail.com", |
125
src/debug.ts
@@ -236,17 +236,12 @@ import tty = require('tty'); | ||
// TODO: Color code per level (fun.color) | ||
let z = fun && fun.name || ''; | ||
switch (z) { | ||
case 'log': z = ''; break; | ||
case 'detail': z = 'debug'; break; | ||
case 'timeEnd': z = 'time'; break; | ||
case 'end': z = 'time'; break; | ||
} | ||
let z = fun && fun.level || ''; | ||
let level = z.toUpperCase(); | ||
const tmp = level; | ||
level = level === 'END' ? 'TIME' : level; | ||
if (Debug.inspectOpts.systemd) { | ||
let num: any = DebugLevel[level || 'INFO']; | ||
let num: any = DebugLevel[tmp || 'INFO']; | ||
if (num === 8) num = 7; | ||
level = `<${num}>`; | ||
} else if (this.useColors) { | ||
z = (Debug as any)[`${z}Icon`]; | ||
z = (Debug as any)[`${tmp.toLowerCase()}Icon`]; | ||
level = z ? (z + ' ') : level; | ||
@@ -527,14 +522,13 @@ } | ||
Debug.logIcon = ''; | ||
Debug.emergIcon = 'đ'; | ||
Debug.alertIcon = 'đ'; | ||
Debug.fatalIcon = 'đ'; | ||
Debug.criticalIcon = 'đ'; | ||
Debug.errorIcon = 'â'; | ||
Debug.emergIcon = 'â ī¸'; | ||
Debug.alertIcon = 'đĨ'; | ||
Debug.criticalIcon = 'â'; | ||
Debug.errorIcon = 'đ´'; | ||
Debug.infoIcon = 'âšī¸'; | ||
Debug.warnIcon = 'â ī¸'; | ||
Debug.warningIcon = 'â ī¸'; | ||
Debug.noticeIcon = 'â ī¸'; | ||
Debug.debugIcon = 'đš'; | ||
Debug.traceIcon = 'đ¸'; | ||
Debug.timeIcon = 'âąī¸'; | ||
Debug.noticeIcon = 'đ'; | ||
Debug.debugIcon = 'đˇ'; | ||
Debug.traceIcon = 'đļ'; | ||
Debug.timeIcon = 'âŗ'; | ||
Debug.endIcon = 'â'; | ||
@@ -544,72 +538,99 @@ /** | ||
*/ | ||
Debug.log = function log(...args: any[]) { | ||
function log(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.INFO)) return; | ||
Debug.useConsole() ? console.log(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
log.level = 'INFO'; | ||
Debug.log = log; | ||
Debug.emerg = function emerg(...args: any[]) { | ||
function emerg(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.EMERG)) return; | ||
Debug.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
emerg.level = 'EMERG'; | ||
Debug.emerg = emerg; | ||
Debug.fatal = function fatal(...args: any[]) { | ||
function fatal(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.ALERT)) return; | ||
Debug.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
fatal.level = 'ALERT'; | ||
Debug.fatal = fatal; | ||
Debug.alert = function alert(...args: any[]) { | ||
function alert(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.ALERT)) return; | ||
Debug.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
alert.level = 'ALERT'; | ||
Debug.alert = alert; | ||
Debug.critical = function critical(...args: any[]) { | ||
function critical(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.CRITICAL)) return; | ||
Debug.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
critical.level = 'CRITICAL'; | ||
Debug.critical = critical; | ||
Debug.error = function error(...args: any[]) { | ||
function error(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.ERROR)) return; | ||
Debug.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
error.level = 'ERROR'; | ||
Debug.error = error; | ||
Debug.warn = function warn(...args: any[]) { | ||
function warn(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.WARNING)) return; | ||
Debug.useConsole() ? console.warn(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
warn.level = 'WARN'; | ||
Debug.warn = warn; | ||
Debug.notice = function notice(...args: any[]) { | ||
function notice(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.NOTICE)) return; | ||
Debug.useConsole() ? console.warn(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
notice.level = 'NOTICE'; | ||
Debug.notice = notice; | ||
Debug.info = function info(...args: any[]) { | ||
function info(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.INFO)) return; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
info.level = 'INFO'; | ||
Debug.info = info; | ||
Debug.debug = function detail(...args: any[]) { | ||
function detail(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.DEBUG)) return; | ||
Debug.useConsole() ? console.debug(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
detail.level = 'DEBUG'; | ||
Debug.debug = detail; | ||
Debug.trace = function trace(...args: any[]) { | ||
function trace(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.TRACE)) return; | ||
Debug.useConsole() ? console.debug(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
trace.level = 'TRACE'; | ||
Debug.trace = trace; | ||
Debug.time = function time(...args: any[]): [number, number] { | ||
if (Debug.isBellow(DebugLevel.TIME)) return void null; | ||
function time(...args: any[]): any { | ||
if (Debug.isBellow(DebugLevel.TIME)) return; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
return void null; | ||
}; | ||
} | ||
time.level = 'TIME'; | ||
Debug.time = time; | ||
Debug.end = function end(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.TIME)) return void null; | ||
function end(...args: any[]): any { | ||
if (Debug.isBellow(DebugLevel.TIME)) return; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
end.level = 'END'; | ||
Debug.end = end; | ||
Debug.timeEnd = function timeEnd(...args: any[]) { | ||
if (Debug.isBellow(DebugLevel.TIME)) return void null; | ||
function timeEnd(...args: any[]): any { | ||
if (Debug.isBellow(DebugLevel.TIME)) return; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
} | ||
timeEnd.level = 'END'; | ||
Debug.timeEnd = timeEnd; | ||
@@ -616,0 +637,0 @@ Debug.millis = function millis(span: [number, number], offset?: number): string { |
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
261548
4286