2023-06-11 19:08:16 +01:00
|
|
|
import { createFormatter, type Formatter } from '@vintl/compact-number'
|
2024-06-14 22:23:02 +02:00
|
|
|
import type { IntlController } from '@vintl/vintl/controller'
|
2023-06-11 19:08:16 +01:00
|
|
|
|
|
|
|
|
const formatters = new WeakMap<IntlController<any>, Formatter>()
|
|
|
|
|
|
|
|
|
|
export function useCompactNumber(): Formatter {
|
|
|
|
|
const vintl = useVIntl()
|
|
|
|
|
|
|
|
|
|
let formatter = formatters.get(vintl)
|
|
|
|
|
|
|
|
|
|
if (formatter == null) {
|
|
|
|
|
const formatterRef = computed(() => createFormatter(vintl.intl))
|
|
|
|
|
formatter = (value, options) => formatterRef.value(value, options)
|
|
|
|
|
formatters.set(vintl, formatter)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return formatter
|
|
|
|
|
}
|