mirror of
https://github.com/debug-js/debug.git
synced 2026-01-18 16:12:38 +00:00
Added: humanize diffs. Closes #8
This commit is contained in:
parent
27fc4c58c7
commit
aa9b0b65fb
21
lib/debug.js
21
lib/debug.js
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user