Permalink
Browse files

[fix][dist] 0.1.7

  • Loading branch information...
1 parent ca54303 commit 5960eda62c5442bf7386c7fe78b1f8911b6d989c @3rd-Eden committed Mar 15, 2013
Showing with 110 additions and 3 deletions.
  1. +3 −0 changelog.md
  2. +1 −1 index.js
  3. +105 −0 ms.js
  4. +1 −2 package.json
View
@@ -1,3 +1,6 @@
+### 0.1.7
+- The `ms` module is horribly broken, now shipping with working copy of it.
+
### 0.1.6
- Send ping packets over the pub/sub channel to prevent it from going idle.
- Output an error when you are serving static files from a unknown directory.
View
@@ -5,7 +5,7 @@ var EventEmitter = require('events').EventEmitter
, Logger = require('devnull')
, zlib = require('zlib')
, path = require('path')
- , ms = require('ms');
+ , ms = require('./ms');
/**
* Unique identifier for the server.
View
105 ms.js
@@ -0,0 +1,105 @@
+/**
+ * Helpers.
+ */
+
+var s = 1000;
+var m = s * 60;
+var h = m * 60;
+var d = h * 24;
+var y = d * 365.25;
+
+/**
+ * Parse or format the given `val`.
+ *
+ * Options:
+ *
+ * - `long` verbose formatting [false]
+ *
+ * @param {String|Number} val
+ * @param {Object} options
+ * @return {String|Number}
+ * @api public
+ */
+
+module.exports = function(val, options){
+ options = options || {};
+ if ('string' == typeof val) return parse(val);
+ return options.long
+ ? long(val)
+ : short(val);
+};
+
+/**
+ * Parse the given `str` and return milliseconds.
+ *
+ * @param {String} str
+ * @return {Number}
+ * @api private
+ */
+
+function parse(str) {
+ var match = /^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(str);
+ if (!match) return;
+ var n = parseFloat(match[1]);
+ var type = (match[2] || 'ms').toLowerCase();
+ switch (type) {
+ case 'years':
+ case 'year':
+ case 'y':
+ return n * y;
+ case 'days':
+ case 'day':
+ case 'd':
+ return n * d;
+ case 'hours':
+ case 'hour':
+ case 'h':
+ return n * h;
+ case 'minutes':
+ case 'minute':
+ case 'm':
+ return n * m;
+ case 'seconds':
+ case 'second':
+ case 's':
+ return n * s;
+ case 'ms':
+ return n;
+ }
+}
+
+/**
+ * Short format for `ms`.
+ *
+ * @param {Number} ms
+ * @return {String}
+ * @api private
+ */
+
+function short(ms) {
+ if (ms >= d) return Math.round(ms / d) + 'd';
+ if (ms >= h) return Math.round(ms / h) + 'h';
+ if (ms >= m) return Math.round(ms / m) + 'm';
+ if (ms >= s) return Math.round(ms / s) + 's';
+ return ms + 'ms';
+}
+
+/**
+ * Long format for `ms`.
+ *
+ * @param {Number} ms
+ * @return {String}
+ * @api private
+ */
+
+function long(ms) {
+ if (ms == d) return Math.round(ms / d) + ' day';
+ if (ms > d) return Math.round(ms / d) + ' days';
+ if (ms == h) return Math.round(ms / h) + ' hour';
+ if (ms > h) return Math.round(ms / h) + ' hours';
+ if (ms == m) return Math.round(ms / m) + ' minute';
+ if (ms > m) return Math.round(ms / m) + ' minutes';
+ if (ms == s) return Math.round(ms / s) + ' second';
+ if (ms > s) return Math.round(ms / s) + ' seconds';
+ return ms + ' ms';
+}
View
@@ -1,6 +1,6 @@
{
"name": "versions",
- "version": "0.1.6",
+ "version": "0.1.7",
"description": "Content Delivery Network",
"main": "index.js",
"scripts": {
@@ -29,7 +29,6 @@
"devnull": "0.0.x",
"expirable": "0.0.x",
"hashring": "1.0.x",
- "ms": "0.5.x",
"request": "2.14.x",
"semver": "1.1.x"
},

0 comments on commit 5960eda

Please sign in to comment.