# parseDuration

`function` in `utils` · v0.6.1

<https://docs.seedcord.org/packages/utils/0.6.1/functions/parse-duration>

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. The return is a positive number or `null`, never `0` or `NaN`, so a malformed input can never read as a valid duration.

```ts
parseDuration(
    input: string
): number | null
```

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. The return is a positive number or `null`, never `0` or `NaN`, so a malformed input can never read as a valid duration.

Parameters.

- `input` `string` — The duration string to parse.

Returns `number | null`.
