Permalink
Browse files

Added humanize() to CS variant

  • Loading branch information...
1 parent aa9b0b6 commit 29f968022dc56d694640424e1d42ca86d5687252 @tj tj committed Feb 3, 2012
Showing with 20 additions and 2 deletions.
  1. +20 −2 debug.js
View
@@ -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'
@@ -72,6 +71,25 @@ debug.disable = function(){
};
/**
+ * 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.
*
* @param {String} name

0 comments on commit 29f9680

Please sign in to comment.