flâneur

One Way to Format, Everywhere

marcelochaman.com · 1,650 words · saved by 1 readers

Centralized formatters for consistency, with cached Intl objects for performance

1export { toDate, toDateNullable, isValidDate }; 2export type { DateInput, DateInputNullable }; 3 4const getDTF = createCachedIntlGetter< 5 Intl.DateTimeFormatOptions, 6 Intl.DateTimeFormat 7>((locale, opts) => new Intl.DateTimeFormat(locale, opts)); 8 9const getRTF = createCachedIntlGetter< 10 Intl.RelativeTimeFormatOptions, 11 Intl.RelativeTimeFormat 12>( 13 (locale, opts) => new Intl.RelativeTimeFormat(locale ?? DEFAULT_LOCALE, opts), 14); 15 16type DurationFormatOptions = { 17 style?: 'long' | 'short' | 'narrow' | 'digital'; 18}; 19interface DurationFormatter { 20…

saved by

related reading