UNPKG

@burglekitt/gmt

Version:

Temporal-based date and time utilities with timezone support and polyfill integration

28 lines (27 loc) 1.59 kB
/** * Return the locale-formatted parts of a PlainDate. * * - This is GMT's substitute for a token formatter (Luxon `toFormat`, date-fns * `format`). A token pattern hard-codes field order and ships US ordering to * every locale; `formatToParts` gives the caller full control over presentation * while the *locale* keeps control of order. See Decision 1 in * `context/roadmap/issues/J.md`. * - Each part is `{ type, value }` where `type` is one of: * `"era"`, `"year"`, `"month"`, `"day"`, `"weekday"`, `"literal"`. * - The caller should iterate the array as returned; reassembling in a fixed * order reintroduces exactly the bug `formatToParts` exists to avoid. * - Returns `[]` for invalid input. * * @param value ISO PlainDate string * @param locale optional BCP 47 locale identifier * @param options optional Intl.DateTimeFormatOptions * @returns array of `{ type, value }` parts, or `[]` on invalid input * * @example formatDateToParts("2024-03-15", "en-US") // [{ type: "month", value: "3" }, { type: "literal", value: "/" }, { type: "day", value: "15" }, { type: "literal", value: "/" }, { type: "year", value: "2024" }] * @example formatDateToParts("2024-03-15", "de-DE") // [{ type: "day", value: "15" }, { type: "literal", value: "." }, { type: "month", value: "3" }, { type: "literal", value: "." }, { type: "year", value: "2024" }] * @example formatDateToParts("invalid") // [] */ export declare function formatDateToParts(value: string, locale?: string, options?: Intl.DateTimeFormatOptions): Array<{ type: string; value: string; }>;