Modrinth/composables/compact-number.ts
Sasha Sorokin 34fd9d29c8
Update Nuxt to v3.12.1 (#1720)
* Update Nuxt dependencies

* Fix ref access in ChartDisplay

* Fix feature flags cookie options type error

* Specify type-only imports

* Fix shorthands access to tags outside of reactive scope

* Replace most useRoute calls with useRoute from vue-router

Nuxt's version of this composable is horrendously broken (nuxt/nuxt#21340)

* Import all svgs with ?component parameter

Fixes weird hydration issues + gives correct type
2024-06-14 13:23:02 -07:00

19 lines
548 B
TypeScript

import { createFormatter, type Formatter } from '@vintl/compact-number'
import type { IntlController } from '@vintl/vintl/controller'
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
}