Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed match regex to support negative numbers #96

Merged
merged 9 commits into from Nov 29, 2017
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