From a9261144ff1322a4d25ffaeefe1452245cc641b3 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Fri, 16 Mar 2012 14:54:37 -0700 Subject: [PATCH] debug: add an `enabled` flag to the returned debug function So that you can do things conditionally if debug mode is enabled. Closes #11. --- lib/debug.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/debug.js b/lib/debug.js index 1be8b66..1383f5f 100644 --- a/lib/debug.js +++ b/lib/debug.js @@ -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;