Permalink
Browse files

debug: add an `enabled` flag to the returned debug function

So that you can do things conditionally if debug mode is enabled.

Closes #11.
  • Loading branch information...
1 parent 3d03d65 commit a9261144ff1322a4d25ffaeefe1452245cc641b3 @TooTallNate TooTallNate committed Mar 16, 2012
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/debug.js
View
@@ -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;

0 comments on commit a926114

Please sign in to comment.