UNPKG

@arcjet/duration

Version:

Arcjet utilities for parsing duration strings

26 lines (25 loc) 689 B
/** * Parse a duration into a number representing seconds while ensuring the value * fits within an unsigned 32-bit integer. * * If a number is passed it is validated and returned. * * If a string is passed it must be in the form of digits followed by a unit. * Supported units are `s` (seconds), * `m` (minutes), * `h` (hours), * and `d` (days). * * @example * ```ts * console.log(parse("1s")) // => 1 * console.log(parse("1m")) // => 60 * console.log(parse("1h")) // => 3600 * console.log(parse("1d")) // => 86400 * ``` * @param value * Value to parse. * @returns * Parsed seconds. */ export declare function parse(value: number | string): number;