UNPKG

@httpx/assert

Version:
38 lines (35 loc) 1.78 kB
import { S as StringNonEmpty, P as ParsableSafeInt, a as ParsableStrictIsoDateZ } from './string.types-CUAzdQ54.cjs'; import { M as MsgOrErrorFactory } from './internal.types-D5VRBw-5.cjs'; import './opaque.types-Dc5fGlwR.cjs'; /** * Assert a value is a non-empty string (trims the string by default) * @throws TypeError */ declare function assertStringNonEmpty(v: unknown, msgOrErrorFactory?: MsgOrErrorFactory): asserts v is StringNonEmpty; /** * * @throws TypeError */ declare function assertParsableSafeInt(v: unknown, msgOrErrorFactory?: MsgOrErrorFactory): asserts v is ParsableSafeInt; /** * Ensure a string that contains an ISO-8601 date time in 'YYYY-MM-DDTHH:mm:ss.sssZ' * format (UTC+0 / time). This check allow the value to be safely passed to `new Date()`or `Date.parse()` * without parser or timezone mis-interpretations. 'T' and 'Z' checks are done in a case-insensitive way. * * ```typescript * assertParsableStrictIsoDateZ('2023-12-28T23:37:31.653Z'); // ✅ true * assertParsableStrictIsoDateZ('2023-12-29T23:37:31.653z'); // ✅ true (case-insensitive works) * assertParsableStrictIsoDateZ('2023-12-28T23:37:31.653'); // 💥 false (missing 'Z') * assertParsableStrictIsoDateZ('2023-02-29T23:37:31.653Z'); // 💥 false (No 29th february in 2023) * * const dateStr = '2023-12-29T23:37:31.653Z'; * assertParsableStrictIsoDateZ(dateStr, `Wrong date: ${dateStr}`); * // 👉 assertion passed, safe to use * const date = new Date(dateStr); * const timestampNumber = Date.parse(dateStr); * ``` * * @throws TypeError */ declare function assertParsableStrictIsoDateZ(v: unknown, msgOrErrorFactory?: MsgOrErrorFactory): asserts v is ParsableStrictIsoDateZ; export { assertParsableSafeInt, assertParsableStrictIsoDateZ, assertStringNonEmpty };