UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

31 lines • 1.8 kB
/** * Validate whether a string is a nanosecond timestamp `parseNanoseconds` will parse. * * `parseNanoseconds` returns `0n` for both `"0"` and garbage, so this is how the two are * told apart — the check its own JSDoc asks callers to make. * * - Shape **and** range: a canonical decimal integer (optional `-`, digits, no leading * zeros) that also falls inside what `Temporal.Instant` can represent. Shape alone is * `nanosecondDecimal` in `regex/`. * - Length is checked before `BigInt`, so an arbitrarily long payload string is rejected * rather than converted. * - Takes the string *value*, not JSON text — `JSON.parse(payload).observedAt`, not the * payload. A quoted `"\"123\""` is not a decimal integer. * - A value that is not a string, a `String` object included, returns `false`. A `true` result * narrows an `unknown` value to `string`. * * @param value any value; a string is checked as the decimal string form of a nanosecond timestamp * @returns boolean indicating whether `parseNanoseconds` will parse it * * @example isValidNanoPattern("1710072000123456789") // true * @example isValidNanoPattern("0") // true — the epoch, where parseNanoseconds returns 0n * @example isValidNanoPattern("-1000000000") // true * @example isValidNanoPattern("8640000000000000000001") // false — outside the instant range * @example isValidNanoPattern("01") // false — leading zero * @example isValidNanoPattern("1e18") // false * @example isValidNanoPattern("garbage") // false * @example isValidNanoPattern(null) // false */ export declare function isValidNanoPattern(value: string): boolean; export declare function isValidNanoPattern(value: {} | null | undefined | void): boolean; export declare function isValidNanoPattern(value: unknown): value is string;