Skip to content

Commit 9191014

Browse files
committed
chore: unuse named groups for backward compability
1 parent 9e7fbd1 commit 9191014

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/lib/isDuration.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ export default function isDuration(value) {
4848

4949
// Match number (integer or decimal) optionally followed by a unit
5050
// Supports: "1", "1.5", ".5", "-1", "-1.5", "-.5", "1h", "1.5 hours", etc.
51-
const match = value.match(/^(?<nbr>-?(?:\d+(?:\.\d+)?|\.\d+))(?:\s?(?<unit>[a-zA-Z]+))?$/);
51+
// Using indexed capture groups for Node.js <10 compatibility
52+
const match = value.match(/^(-?(?:\d+(?:\.\d+)?|\.\d+))(?:\s?([a-zA-Z]+))?$/);
5253

53-
if (!match || !match.groups) {
54+
if (!match) {
5455
return false;
5556
}
5657

57-
const { unit } = match.groups;
58+
const unit = match[2];
5859

5960
return unit === undefined || AllDurationUnits.has(unit);
6061
}

0 commit comments

Comments
 (0)