diff --git a/src/index.ts b/src/index.ts index d50e3c7..24ea52c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -75,7 +75,7 @@ export function parse(str: string): number { ); } const match = - /^(?-?\d*\.?\d+) *(?milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec( + /^(?-?\d*\.?\d+(?:[eE][-+]?\d+)?) *(?milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec( str, ); diff --git a/src/parse.test.ts b/src/parse.test.ts index 9182411..18c2ea0 100644 --- a/src/parse.test.ts +++ b/src/parse.test.ts @@ -2,6 +2,10 @@ import { describe, expect, it } from '@jest/globals'; import { parse } from './index'; describe('parse(string)', () => { + it('should support scientific notation', () => { + expect(parse('5.696545792019405e+297y')).toBe(5.696545792019405e+297 * 31557600000); + expect(parse('1.5e3ms')).toBe(1500); + }); it('should not throw an error', () => { expect(() => { parse('1m');