Comparing version 0.0.2 to 0.0.3
15
index.js
@@ -24,10 +24,13 @@ /** | ||
module.exports = function(ts) { | ||
var res; | ||
switch (ts) { | ||
case '': | ||
case null: | ||
case undefined: | ||
return +new Date(); | ||
} | ||
switch (typeof ts) { | ||
case 'object': res = +ts; break; | ||
case 'number': res = ts; break; | ||
case 'string': res = parse(ts); break; | ||
case 'undefined': res = +new Date(); break; | ||
case 'string': return parse(ts); | ||
case 'object': return +ts; | ||
case 'number': return ts; | ||
} | ||
return res; | ||
}; | ||
@@ -34,0 +37,0 @@ |
{ | ||
"name": "date-ms", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "date string to ms convertion lib", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,1 +1,3 @@ | ||
[](http://travis-ci.org/artjock/date-ms) | ||
date-ms | ||
@@ -14,2 +16,4 @@ ======= | ||
```js | ||
var ms = require('date-ms'); | ||
ms('1d') // 86400000 | ||
@@ -24,4 +28,5 @@ ms('10h') // 36000000 | ||
ms() // +new Date() | ||
ms('') // +new Date() | ||
ms(null) // +new Date() | ||
ms(undefined) // +new Date() | ||
ms(null) // NaN | ||
@@ -28,0 +33,0 @@ ms( new Date('2013-04-05') ) // 1365120000000 |
@@ -58,5 +58,10 @@ /** | ||
it('should return NaN if invalid', function () { | ||
it('should return NaN if invalid string', function () { | ||
expect( isNaN(ms('☃')) ).to.be(true); | ||
}); | ||
it('should return current date for empty string', function() { | ||
var now = +new Date(); | ||
expect( ms('') ).to.eql( now ); | ||
}); | ||
}) | ||
@@ -73,2 +78,11 @@ | ||
describe('ms(null)', function() { | ||
it('should return current date for null', function() { | ||
var now = +new Date(); | ||
expect( ms(null) ).to.eql( now ); | ||
}); | ||
}); | ||
// numbers | ||
@@ -75,0 +89,0 @@ describe('ms(number)', function(){ |
5727
6
147
42