Modrinth/composables/how-ago.ts
2023-06-11 14:08:16 -04:00

19 lines
535 B
TypeScript

import { createFormatter, type Formatter } from '@vintl/how-ago'
import { IntlController } from '@vintl/vintl/controller'
const formatters = new WeakMap<IntlController<any>, Formatter>()
export function useRelativeTime(): 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
}