Skip to content

Commit

Permalink
Fixed match regex to support negative numbers (#96)
Browse files Browse the repository at this point in the history
Fixes #70.
  • Loading branch information
yoavmmn authored and TooTallNate committed Nov 29, 2017
1 parent a2caead commit f0bc0a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions tests.js
Expand Up @@ -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
Expand Down

0 comments on commit f0bc0a2

Please sign in to comment.