From f0bc0a2bfa34b2f4a424afaa330fd828cbf1b5b8 Mon Sep 17 00:00:00 2001 From: Yoav Maman Date: Wed, 29 Nov 2017 23:27:54 +0200 Subject: [PATCH] Fixed match regex to support negative numbers (#96) Fixes #70. --- index.js | 2 +- tests.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c0f2412..a1c796b 100644 --- a/index.js +++ b/index.js @@ -50,7 +50,7 @@ function parse(str) { if (str.length > 100) { return; } - var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( + var match = /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( str ); if (!match) { diff --git a/tests.js b/tests.js index ff0cdec..89b9d9c 100644 --- a/tests.js +++ b/tests.js @@ -64,6 +64,12 @@ describe('ms(string)', function() { it('should work with numbers starting with .', function() { expect(ms('.5ms')).to.be(0.5); }); + + it('should work with numbers starting with -', function() { + expect(ms('-5')).to.be(-5); + expect(ms('-.5ms')).to.be(-0.5); + expect(ms('-0.5ms')).to.be(-0.5); + }); }); // long strings