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
- Shikishiki.style
- Web Interface Guidelinesvercel.com
- Everything is Fertilenickcammarata.com
- Dates and Times | SheetJS Community Editiondocs.sheetjs.com
- GitHub - wanasit/chrono: A natural language date parser in Javascriptgithub.com
- Numbers Every Programmer Should Know By Yearcolin-scott.github.io
- Golang Time Format: Format and Parse Time with Layout Examplesgolinuxcloud.com
- OpenAI Platformplatform.openai.com
- User Inyerface - A worst-practice UI experimentuserinyerface.com
- 9.9. 时间/日期函数和操作符postgres.cn
- GitHub - chenglou/pretext: Fast, accurate & comprehensive text measurement & layoutgithub.com
- The Design of This Websiteturntrout.com