Skip to content

Commit

Permalink
Added humanize() to CS variant
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Feb 3, 2012
1 parent aa9b0b6 commit 29f9680
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions debug.js
Expand Up @@ -24,8 +24,7 @@ function debug(name) {
fmt = name
+ ' '
+ fmt
+ ' +' + ms
+ 'ms';
+ ' +' + debug.humanize(ms);

// This hackery is required for IE8
// where `console.log` doesn't have 'apply'
Expand Down Expand Up @@ -71,6 +70,25 @@ debug.disable = function(){
debug.enable('');
};

/**
* Humanize the given `ms`.
*
* @param {Number} m
* @return {String}
* @api private
*/

debug.humanize = function(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';
};

/**
* Returns true if the given mode name is enabled, false otherwise.
*
Expand Down

0 comments on commit 29f9680

Please sign in to comment.