Added: humanize diffs. Closes #8

This commit is contained in:
Tj Holowaychuk 2012-02-02 16:52:37 -08:00
parent 27fc4c58c7
commit aa9b0b65fb

View File

@ -69,6 +69,25 @@ 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`.
*
@ -93,7 +112,7 @@ function debug(name) {
fmt = ' \033[9' + c + 'm' + name + ' '
+ '\033[3' + c + 'm\033[90m'
+ fmt + '\033[3' + c + 'm'
+ ' +' + ms + 'ms\033[0m';
+ ' +' + humanize(ms) + '\033[0m';
console.error.apply(this, arguments);
}