/** * Human-friendly duration parsing and formatting. * * Accepts strings like `"5m"`, `"30s"`, `"1500ms"`, `"2h"`, `"1d"`. * A unit suffix is always required. Always returns **non-negative milliseconds**. */ /** A duration value — a string with a unit suffix like `"5m"`, `"30s"`, `"500ms"`. */ export type Duration = string; /** * Node's timer delay is a 32-bit signed integer of milliseconds. A larger * `setTimeout`/`child_process` `timeout` overflows and is silently coerced to * ~1ms (with a `TimeoutOverflowWarning`), firing almost immediately — the * opposite of the caller's intent. Callers that feed a duration into a timer * should reject anything above this. */ export declare const MAX_TIMER_DELAY_MS = 2147483647; /** * Parse a duration string into milliseconds. * * @param input - A string like `"5m"`, `"30s"`, `"500ms"`. * @returns The duration in milliseconds (always finite and non-negative). * @throws If `input` is missing a unit suffix, has an unknown unit, or overflows. */ export declare function parseDuration(input: Duration): number; /** * Check whether a value is a valid Duration string (parseable, finite, and * non-negative). Note this accepts zero (e.g. `"0s"`); use * {@link parsePositiveDuration} when zero should be rejected. */ export declare function isValidDuration(input: unknown): input is Duration; /** * Outcome of {@link parsePositiveDuration}: either the parsed milliseconds, or * a reason the value was rejected — `"invalid"` (not a duration string with a * unit suffix) or `"non-positive"` (parses but is `<= 0`, which would disable a * timeout cap). */ export type PositiveDurationResult = { ok: true; ms: number; } | { ok: false; reason: "invalid" | "non-positive"; }; /** * Parse a duration that must be strictly positive in a single pass, classifying * the failure so callers can surface distinct messages without re-parsing. Use * this instead of chaining {@link isValidDuration} and a positivity check when * you also need the parsed milliseconds. */ export declare function parsePositiveDuration(input: unknown): PositiveDurationResult; /** * Outcome of {@link parseTimerDuration}: the parsed milliseconds, or a reason * it can't be fed to a timer — `"invalid"` (not a unit-suffixed duration), * `"non-positive"` (`<= 0`, which would disable a timeout cap), or `"overflow"` * (above {@link MAX_TIMER_DELAY_MS}, which a timer coerces to ~1ms). */ export type TimerDurationResult = { ok: true; ms: number; } | { ok: false; reason: "invalid" | "non-positive" | "overflow"; }; /** * Parse a duration destined for a `setTimeout`/`child_process` timeout: it must * be a positive, unit-suffixed duration within Node's timer range. Classifies * the failure so callers can surface distinct messages without re-parsing. This * is the timer-safe superset of {@link parsePositiveDuration}; prefer it * wherever the value ends up bounding a real timer. */ export declare function parseTimerDuration(input: unknown): TimerDurationResult; /** * Format milliseconds as a compact human-readable string. * Examples: `formatDuration(300_000)` → `"5m"`, `formatDuration(1500)` → `"1.5s"`. */ export declare function formatDuration(ms: number): string; //# sourceMappingURL=duration.d.ts.map