1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.shouldPolyfill = shouldPolyfill;
|
4 | var intl_localematcher_1 = require("@formatjs/intl-localematcher");
|
5 | var supported_locales_generated_1 = require("./supported-locales.generated");
|
6 | function 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 | }
|
14 | function 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 | }
|
25 | function 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_generated_1.supportedLocales, 'en');
|
31 | }
|
32 | }
|