| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 | 
							- /**
 
-  * Module dependencies.
 
-  */
 
- var tty = require('tty');
 
- /**
 
-  * Expose `debug()` as the module.
 
-  */
 
- module.exports = debug;
 
- /**
 
-  * Enabled debuggers.
 
-  */
 
- var names = []
 
-   , skips = [];
 
- (process.env.DEBUG || '')
 
-   .split(/[\s,]+/)
 
-   .forEach(function(name){
 
-     name = name.replace('*', '.*?');
 
-     if (name[0] === '-') {
 
-       skips.push(new RegExp('^' + name.substr(1) + '$'));
 
-     } else {
 
-       names.push(new RegExp('^' + name + '$'));
 
-     }
 
-   });
 
- /**
 
-  * Colors.
 
-  */
 
- var colors = [6, 2, 3, 4, 5, 1];
 
- /**
 
-  * Previous debug() call.
 
-  */
 
- var prev = {};
 
- /**
 
-  * Previously assigned color.
 
-  */
 
- var prevColor = 0;
 
- /**
 
-  * Is stdout a TTY? Colored output is disabled when `true`.
 
-  */
 
- var isatty = tty.isatty(2);
 
- /**
 
-  * Select a color.
 
-  *
 
-  * @return {Number}
 
-  * @api private
 
-  */
 
- function color() {
 
-   return colors[prevColor++ % colors.length];
 
- }
 
- /**
 
-  * Humanize the given `ms`.
 
-  *
 
-  * @param {Number} m
 
-  * @return {String}
 
-  * @api private
 
-  */
 
- function humanize(ms) {
 
-   var sec = 1000
 
-     , min = 60 * 1000
 
-     , hour = 60 * min;
 
-   if (ms >= hour) return (ms / hour).toFixed(1) + 'h';
 
-   if (ms >= min) return (ms / min).toFixed(1) + 'm';
 
-   if (ms >= sec) return (ms / sec | 0) + 's';
 
-   return ms + 'ms';
 
- }
 
- /**
 
-  * Create a debugger with the given `name`.
 
-  *
 
-  * @param {String} name
 
-  * @return {Type}
 
-  * @api public
 
-  */
 
- function debug(name) {
 
-   function disabled(){}
 
-   disabled.enabled = false;
 
-   var match = skips.some(function(re){
 
-     return re.test(name);
 
-   });
 
-   if (match) return disabled;
 
-   match = names.some(function(re){
 
-     return re.test(name);
 
-   });
 
-   if (!match) return disabled;
 
-   var c = color();
 
-   function colored(fmt) {
 
-     fmt = coerce(fmt);
 
-     var curr = new Date;
 
-     var ms = curr - (prev[name] || curr);
 
-     prev[name] = curr;
 
-     fmt = '  \u001b[9' + c + 'm' + name + ' '
 
-       + '\u001b[3' + c + 'm\u001b[90m'
 
-       + fmt + '\u001b[3' + c + 'm'
 
-       + ' +' + humanize(ms) + '\u001b[0m';
 
-     console.error.apply(this, arguments);
 
-   }
 
-   function plain(fmt) {
 
-     fmt = coerce(fmt);
 
-     fmt = new Date().toUTCString()
 
-       + ' ' + name + ' ' + fmt;
 
-     console.error.apply(this, arguments);
 
-   }
 
-   colored.enabled = plain.enabled = true;
 
-   return isatty || process.env.DEBUG_COLORS
 
-     ? colored
 
-     : plain;
 
- }
 
- /**
 
-  * Coerce `val`.
 
-  */
 
- function coerce(val) {
 
-   if (val instanceof Error) return val.stack || val.message;
 
-   return val;
 
- }
 
 
  |