Skip to content
Functionutilsv0.8.17

parseDuration

Parses a short duration string like 24h, 30m, 90s, 7d, or 500ms into milliseconds.

The grammar is one or more digits followed by one lowercase unit (ms, s, m, h, d). Anything else returns null, including a bare number, an unknown unit, an uppercase unit, surrounding whitespace, a fractional value, and a result of zero. A malformed input can never read as a valid duration.

parseDuration(
    input: string
): number | null

input

input: string

The duration string to parse.