mirror of
https://github.com/debug-js/debug.git
synced 2026-01-25 16:42:28 +00:00
debug: add an enabled flag to the returned debug function
So that you can do things conditionally if debug mode is enabled. Closes #11.
This commit is contained in:
parent
3d03d65ea6
commit
a9261144ff
@ -105,17 +105,20 @@ function humanize(ms) {
|
||||
*/
|
||||
|
||||
function debug(name) {
|
||||
function disabled(){}
|
||||
disabled.enabled = false;
|
||||
|
||||
var match = skips.some(function(re){
|
||||
return re.test(name);
|
||||
});
|
||||
|
||||
if (match) return function(){};
|
||||
if (match) return disabled;
|
||||
|
||||
match = names.some(function(re){
|
||||
return re.test(name);
|
||||
});
|
||||
|
||||
if (!match) return function(){};
|
||||
if (!match) return disabled;
|
||||
var c = color();
|
||||
|
||||
function colored(fmt) {
|
||||
@ -137,6 +140,8 @@ function debug(name) {
|
||||
console.error.apply(this, arguments);
|
||||
}
|
||||
|
||||
colored.enabled = plain.enabled = true;
|
||||
|
||||
return isatty
|
||||
? colored
|
||||
: plain;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user