From 97c6ddf0704e7ff1e97f6d996effe1d334db4340 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Wed, 1 Feb 2012 11:54:32 -0800 Subject: [PATCH] Add `debug.enable` and `debug.enabled` APIs. Makes wildcard filters work once again. --- debug.js | 45 ++++++++++++++++++++++++++++++++++++++++---- example/browser.html | 4 +--- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/debug.js b/debug.js index 28539c4..f338d48 100644 --- a/debug.js +++ b/debug.js @@ -5,6 +5,12 @@ * MIT Licensed */ +/** + * The currently active debug mode names. + */ + +var names = []; + /** * Previous debug() call. */ @@ -20,11 +26,8 @@ var prev = {}; */ function debug(name) { - if (!debug.enable) { - throw new Error('You must set a function for `debug.enable`'); - } - var enabled = debug.enable(name); + var enabled = debug.enabled(name); if (!enabled) return function(){}; @@ -44,3 +47,37 @@ function debug(name) { return plain; } + +/** + * Enables a debug mode by name. This can include modes + * separated by a colon and wildcards. + * + * @param {String} name + * @api public + */ + +debug.enable = function(name) { + var split = (name || '').split(/[\s,]+/) + , len = split.length + for (var i=0; idebug()