added ms unit

This commit is contained in:
mrbar42 2016-07-30 17:56:51 +03:00
parent 6fe356b494
commit 2a4a37660a
2 changed files with 4 additions and 0 deletions

View File

@ -26,6 +26,7 @@ var defaultOpts = {
*/
var unitMap = {
ms: ['ms', 'milli', 'millisecond', 'milliseconds'],
s: ['s', 'sec', 'secs', 'second', 'seconds'],
m: ['m', 'min', 'mins', 'minute', 'minutes'],
h: ['h', 'hr', 'hrs', 'hour', 'hours'],
@ -79,6 +80,7 @@ function parseTimestring(string, returnUnit, opts) {
function getUnitValues(opts) {
var unitValues = {
ms: 0.001,
s: 1,
m: 60,
h: 3600,

View File

@ -5,6 +5,7 @@ var timestring = require('./index');
describe('timestring', function() {
it('can parse a timestring', function() {
expect(timestring('500ms')).to.equal(0.5);
expect(timestring('1s')).to.equal(1);
expect(timestring('1m')).to.equal(60);
expect(timestring('1h')).to.equal(3600);
@ -15,6 +16,7 @@ describe('timestring', function() {
});
it('can return a value in a specified unit', function() {
expect(timestring('1m', 'ms')).to.equal(60000);
expect(timestring('5m', 's')).to.equal(300);
expect(timestring('5m', 'm')).to.equal(5);
});