@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.
42 lines • 2.45 kB
TypeScript
/**
* The fixed text grammars of time-ordered identifiers, and the digit decoders beside them
* (CORE-56; see "Scoped exception: identifier grammars" in `context/coding-standards.md`).
*
* UUIDs, ObjectIds, ULIDs, KSUIDs and Snowflakes carry a timestamp as digits in a fixed
* alphabet. No `Temporal.*.from` reads any of them, so each grammar is one regex here and a
* public function matches the whole input against it before decoding. All are fixed, never
* caller-supplied. Every loop is bounded by the grammar length (at most 27): O(1).
*
* Not in `regex/`: that namespace holds date-time grammars, and these validate identifiers.
*/
/**
* A UUID that carries a timestamp. RFC 9562 §4 ABNF: 8-4-4-4-12 hex digits, hyphens required,
* no braces, no `urn:uuid:`. The version digit (§4.2) is 1, 6 or 7, and the variant digit
* (§4.1) is 8, 9, a or b: bits `10xx`.
*/
export declare const timeUuidText: RegExp;
/** MongoDB ObjectId: 12 bytes in hex string form, 24 digits. */
export declare const objectIdText: RegExp;
/**
* ULID spec § Encoding: 26 Crockford base32 characters. The first is 0-7 so the 130 bits fit
* 128 (§ Overflow). With the `i` flag the class still excludes `i l o u`, because it excludes
* `I L O U`.
*/
export declare const ulidText: RegExp;
/** KSUID `base62.go`: 27 base62 characters. Case-sensitive, so no `i` flag. */
export declare const ksuidText: RegExp;
/** An unsigned decimal string of up to 20 digits: 2^64 − 1 has 20 digits. */
export declare const unsignedDecimalText: RegExp;
/** Crockford base32 alphabet (ULID spec § Encoding): no `I L O U`. */
export declare const CROCKFORD_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
/** KSUID `base62.go` alphabet: `0-9A-Za-z`, spelled out in full. */
export declare const BASE62_ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
/** Read hex digits as an integer. The caller has matched a grammar first. */
export declare function hexValue(digits: string): bigint;
/**
* Read `digits` as an integer in the base `alphabet.length`, most significant first. The
* caller has matched a grammar first and upper-cases Crockford digits it reads from either case.
*/
export declare function digitsValue(digits: string, alphabet: string): bigint;
/** Write an integer as `length` upper-case Crockford base32 digits, most significant first. */
export declare function crockfordDigits(value: bigint, length: number): string;