Comparing version 0.0.25 to 0.0.26
@@ -39,2 +39,3 @@ /// <reference types="node" /> | ||
alwaysDiff: boolean; | ||
level: DebugLevel; | ||
} | ||
@@ -80,3 +81,3 @@ export declare enum DebugLevel { | ||
var coerce: (val: any) => any; | ||
var level: DebugLevel; | ||
var level: () => DebugLevel; | ||
var isBellow: (ofLevel: DebugLevel) => boolean; | ||
@@ -102,4 +103,4 @@ var setLevel: (toLevel: DebugLevel) => void; | ||
var time: (...args: any[]) => [number, number]; | ||
var end: (...args: any[]) => void; | ||
var timeEnd: (...args: any[]) => void; | ||
var end: (...args: any[]) => any; | ||
var timeEnd: (...args: any[]) => any; | ||
var millis: (span: [number, number], offset?: number) => string; | ||
@@ -106,0 +107,0 @@ } |
@@ -234,3 +234,7 @@ "use strict"; | ||
let val = process.env[key]; | ||
if (/^(yes|on|true|enabled)$/i.test(val)) { | ||
// console.log(prop, val); | ||
if (prop === 'level') { | ||
val = val in DebugLevel ? DebugLevel[val] : DebugLevel.DEBUG; | ||
} | ||
else if (/^(yes|on|true|enabled)$/i.test(val)) { | ||
val = true; | ||
@@ -397,12 +401,16 @@ } | ||
}; | ||
Debug.level = DebugLevel.DEBUG; | ||
Debug.level = function level() { | ||
return ('level' in Debug.inspectOpts) | ||
? Debug.inspectOpts.level | ||
: DebugLevel.DEBUG; | ||
}; | ||
Debug.isBellow = function isBellow(ofLevel) { | ||
return Debug.level > ofLevel; | ||
return Debug.level() > ofLevel; | ||
}; | ||
Debug.setLevel = function setLevel(toLevel) { | ||
if (toLevel == null || toLevel === undefined) { | ||
Debug.level = DebugLevel.OFF; | ||
Debug.inspectOpts.level = DebugLevel.OFF; | ||
} | ||
else { | ||
Debug.level = (DebugLevel[toLevel] || DebugLevel.INFO); | ||
Debug.inspectOpts.level = (DebugLevel[toLevel] || DebugLevel.INFO); | ||
} | ||
@@ -424,23 +432,39 @@ }; | ||
Debug.log = function log(...args) { | ||
if (Debug.isBellow(DebugLevel.INFO)) | ||
return; | ||
Debug.useConsole() ? console.log(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.fatal = function fatal(...args) { | ||
if (Debug.isBellow(DebugLevel.FATAL)) | ||
return; | ||
Debug.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.error = function error(...args) { | ||
if (Debug.isBellow(DebugLevel.ERROR)) | ||
return; | ||
Debug.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.info = function info(...args) { | ||
if (Debug.isBellow(DebugLevel.INFO)) | ||
return; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.warn = function warn(...args) { | ||
if (Debug.isBellow(DebugLevel.WARN)) | ||
return; | ||
Debug.useConsole() ? console.warn(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.debug = 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) { | ||
if (Debug.isBellow(DebugLevel.TRACE)) | ||
return; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.time = function time(...args) { | ||
if (Debug.isBellow(DebugLevel.INFO)) | ||
return void null; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
@@ -450,5 +474,9 @@ return void null; | ||
Debug.end = function end(...args) { | ||
if (Debug.isBellow(DebugLevel.INFO)) | ||
return void null; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
}; | ||
Debug.timeEnd = function timeEnd(...args) { | ||
if (Debug.isBellow(DebugLevel.INFO)) | ||
return void null; | ||
Debug.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
@@ -455,0 +483,0 @@ }; |
{ | ||
"name": "exer", | ||
"version": "0.0.25", | ||
"version": "0.0.26", | ||
"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
180870
2455