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.

54 lines • 3.32 kB
/** The `Intl` formatter classes this module builds. */ type FormatterKind = "DateTimeFormat" | "NumberFormat" | "ListFormat" | "RelativeTimeFormat"; type FormatterLocale = string | string[] | undefined; /** * A date formatter with the week-year guard (D23, D24) and no year repair (D25 to D27, but for the era-year numerals under the guard): its parts * are the engine's own, as a caller that reads the engine's era needs them (D18, `islamicEra.ts`). * Not cached; the caller keeps it. * * @param locale BCP 47 locale * @param options the formatter's options, built by GMT code * @returns the guarded formatter * * @example guardedDateTimeFormat("en-u-ca-islamic-civil", { era: "short", timeZone: "UTC" }).formatToParts(0) // the engine's parts */ export declare function guardedDateTimeFormat(locale: FormatterLocale, options: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; /** * A shared, read-only formatter for these arguments; built on the first call with them. * * A formatter's output is fixed by its constructor arguments and the host's locale data. A * `DateTimeFormat` also reads the default locale and default time zone, so it is cached only * with a `locale` string (or array of strings) and a `timeZone` string; any other argument * set is constructed fresh, exactly as `new Intl[kind](locale, options)` would. A construction * failure throws and is never cached. A formatter is kept only while `Intl[kind]` is the * constructor that built it. * * @param kind which `Intl` formatter class to build * @param locale BCP 47 locale or locales, or `undefined` for the runtime default * @param options the formatter's options, built by GMT code * @param refuseDates whether a date formatter is refused where compat D33 refuses it; * `false` only for a formatter whose date parts the caller throws away (`joinDateTimeConnector`) * @returns the formatter * * @example cachedFormatter("DateTimeFormat", "en-GB", { timeZone: "UTC" }).format(0) // "01/01/1970" * @example cachedFormatter("ListFormat", "en", { type: "conjunction" }).format(["a", "b"]) // "a and b" * @example cachedFormatter("DateTimeFormat", "not a locale", { timeZone: "UTC" }) // throws RangeError */ export declare function cachedFormatter<K extends FormatterKind>(kind: K, locale: FormatterLocale, options: object, refuseDates?: boolean): InstanceType<(typeof Intl)[K]>; /** * Construct once to raise the error `Intl` raises for these arguments; a repeat is a no-op. * * Whether construction throws does not depend on the default zone, so the arguments need no * `timeZone`. Only a success is remembered; an invalid call throws every time. * * @param kind which `Intl` formatter class to build * @param locale BCP 47 locale or locales, or `undefined` for the runtime default * @param options the formatter's options, built by GMT code * * @example checkFormatterArguments("DateTimeFormat", "en-GB", { dateStyle: "long" }) // returns * @example checkFormatterArguments("DateTimeFormat", "en-GB", { dateStyle: "huge" }) // throws RangeError */ export declare function checkFormatterArguments(kind: FormatterKind, locale: FormatterLocale, options: object): void; /** Test seam: forget every cached formatter and every checked argument set. */ export declare function clearFormatterCache(): void; export {};