UNPKG

@formatjs/intl-listformat

Version:

Formats JS list in a i18n-safe way

15 lines (14 loc) 523 B
import { match } from "@formatjs/intl-localematcher"; import { supportedLocales } from "./supported-locales.generated.js"; function supportedLocalesOf(locale) { if (!locale) { return true; } const locales = Array.isArray(locale) ? locale : [locale]; return Intl.ListFormat.supportedLocalesOf(locales).length === locales.length; } export function shouldPolyfill(locale = "en") { if (!("ListFormat" in Intl) || !supportedLocalesOf(locale)) { return locale ? match([locale], supportedLocales, "en") : undefined; } }