diff --git a/index.js b/index.js index 23270ca..a401fe4 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ import en from './locale/en.js' -const durationRE = /((?:\d+(?:\.\d+)?|\.\d+)(?:[eE][-+]?\d+)?)\s*([\p{L}]{0,14})/gu +const durationRE = /((?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?)\s*([\p{L}]{0,14})/gu parse.unit = en diff --git a/test.js b/test.js index 5a7cfa7..e1b8971 100644 --- a/test.js +++ b/test.js @@ -117,6 +117,16 @@ t('edge cases', t => { t.end() }) +t('trailing decimal point with no fraction digits', t => { + // a bare `.` right after the integer part must not swallow the unit + // that follows it, e.g. "5. seconds" should behave like "5 seconds" + t.equal(parse('5. seconds'), 5 * s) + t.equal(parse('5.seconds'), 5 * s) + t.equal(parse('5. secs'), parse('5 secs')) + t.equal(parse('-5. secs'), -5 * s) + t.end() +}) + t('invalid', t => { t.equal(parse('abc'), null) t.equal(parse(), null)