UNPKG

@formatjs/intl-enumerator

Version:
16 lines (15 loc) 445 B
import { createMemoizedNumberFormat } from "@formatjs/ecma402-abstract"; import { units } from "./units.generated.js"; function isSupported(unit, locale = "en") { try { const formatter = createMemoizedNumberFormat(locale, { style: "unit", unit }); return formatter.resolvedOptions().unit === unit; } catch {} return false; } export function getSupportedUnits(locale) { return units.filter((unit) => isSupported(unit, locale)); }