UNPKG

1.13 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.shouldPolyfill = void 0;
4var intl_localematcher_1 = require("@formatjs/intl-localematcher");
5var supported_locales_1 = require("./supported-locales");
6function supportedLocalesOf(locale) {
7 if (!locale) {
8 return true;
9 }
10 var locales = Array.isArray(locale) ? locale : [locale];
11 return (Intl.RelativeTimeFormat.supportedLocalesOf(locales).length ===
12 locales.length);
13}
14function hasResolvedOptionsNumberingSystem(locale) {
15 try {
16 return ('numberingSystem' in
17 new Intl.RelativeTimeFormat(locale || 'en', {
18 numeric: 'auto',
19 }).resolvedOptions());
20 }
21 catch (_) {
22 return false;
23 }
24}
25function shouldPolyfill(locale) {
26 if (locale === void 0) { locale = 'en'; }
27 if (!('RelativeTimeFormat' in Intl) ||
28 !supportedLocalesOf(locale) ||
29 !hasResolvedOptionsNumberingSystem(locale)) {
30 return (0, intl_localematcher_1.match)([locale], supported_locales_1.supportedLocales, 'en');
31 }
32}
33exports.shouldPolyfill = shouldPolyfill;