(options?: Intl.CollatorOptions)
| 21 | * @param options - Collator options. |
| 22 | */ |
| 23 | export function useCollator(options?: Intl.CollatorOptions): Intl.Collator { |
| 24 | let {locale} = useLocale(); |
| 25 | |
| 26 | let cacheKey = |
| 27 | locale + |
| 28 | (options |
| 29 | ? Object.entries(options) |
| 30 | .sort((a, b) => (a[0] < b[0] ? -1 : 1)) |
| 31 | .join() |
| 32 | : ''); |
| 33 | if (cache.has(cacheKey)) { |
| 34 | return cache.get(cacheKey)!; |
| 35 | } |
| 36 | |
| 37 | let formatter = new Intl.Collator(locale, options); |
| 38 | cache.set(cacheKey, formatter); |
| 39 | return formatter; |
| 40 | } |
no test coverage detected