@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.
34 lines • 1.77 kB
TypeScript
/** The text of a fallback range around the two single texts: `P + a + J + b + S`. */
export interface FallbackTemplate {
readonly prefix: string;
readonly joiner: string;
readonly suffix: string;
}
/** Forget every template (the `Intl.DateTimeFormat` constructor was replaced, a test seam). */
export declare function forgetFallbackTemplates(): void;
/**
* The template read off a helper range and its two single texts, or `null` when it has no
* recognisable shape.
*
* @example readTemplate("6/15/2024 – 6/17/2024", "6/15/2024", "6/17/2024") // { prefix: "", joiner: " – ", suffix: "" }
* @example readTemplate("du 15/06 au 17/06", "15/06", "17/06") // { prefix: "du ", joiner: " au ", suffix: "" }
*/
export declare function readTemplate(range: string, first: string, last: string): FallbackTemplate | null;
/**
* The fallback template of a locale and numbering system, read from a helper formatter (bounded:
* one `formatRange` and two `format` calls, then cached, at most 256 entries).
*
* @param locale the locale the formatter resolved
* @param numberingSystem the numbering system it resolved
* @param calendar the calendar the helper prints in
* @returns the template, or `null` when the engine's range has no shape this reads
*
* @example fallbackTemplate("en", "latn", "gregory") // { prefix: "", joiner: " – ", suffix: "" }
*/
export declare function fallbackTemplate(locale: string, numberingSystem: string, calendar: string): FallbackTemplate | null;
/**
* A range written from two single-date texts.
*
* @example joinFallback({ prefix: "", joiner: " – ", suffix: "" }, "1872 AD", "6 Meiji") // "1872 AD – 6 Meiji"
*/
export declare function joinFallback(template: FallbackTemplate, first: string, last: string): string;