UNPKG

932 BJavaScriptView Raw
1import { match } from '@formatjs/intl-localematcher';
2import { supportedLocales } from './supported-locales.generated';
3function supportedLocalesOf(locale) {
4 if (!locale) {
5 return true;
6 }
7 var locales = Array.isArray(locale) ? locale : [locale];
8 return (Intl.RelativeTimeFormat.supportedLocalesOf(locales).length ===
9 locales.length);
10}
11function hasResolvedOptionsNumberingSystem(locale) {
12 try {
13 return ('numberingSystem' in
14 new Intl.RelativeTimeFormat(locale || 'en', {
15 numeric: 'auto',
16 }).resolvedOptions());
17 }
18 catch (_) {
19 return false;
20 }
21}
22export function shouldPolyfill(locale) {
23 if (locale === void 0) { locale = 'en'; }
24 if (!('RelativeTimeFormat' in Intl) ||
25 !supportedLocalesOf(locale) ||
26 !hasResolvedOptionsNumberingSystem(locale)) {
27 return match([locale], supportedLocales, 'en');
28 }
29}