1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.InitializeRelativeTimeFormat = InitializeRelativeTimeFormat;
|
4 | var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
5 | var intl_localematcher_1 = require("@formatjs/intl-localematcher");
|
6 | var NUMBERING_SYSTEM_REGEX = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/i;
|
7 | function InitializeRelativeTimeFormat(rtf, locales, options, _a) {
|
8 | var getInternalSlots = _a.getInternalSlots, availableLocales = _a.availableLocales, relevantExtensionKeys = _a.relevantExtensionKeys, localeData = _a.localeData, getDefaultLocale = _a.getDefaultLocale;
|
9 | var internalSlots = getInternalSlots(rtf);
|
10 | internalSlots.initializedRelativeTimeFormat = true;
|
11 | var requestedLocales = (0, ecma402_abstract_1.CanonicalizeLocaleList)(locales);
|
12 | var opt = Object.create(null);
|
13 | var opts = (0, ecma402_abstract_1.CoerceOptionsToObject)(options);
|
14 | var matcher = (0, ecma402_abstract_1.GetOption)(opts, 'localeMatcher', 'string', ['best fit', 'lookup'], 'best fit');
|
15 | opt.localeMatcher = matcher;
|
16 | var numberingSystem = (0, ecma402_abstract_1.GetOption)(opts,
|
17 |
|
18 | 'numberingSystem', 'string', undefined, undefined);
|
19 | if (numberingSystem !== undefined) {
|
20 | if (!NUMBERING_SYSTEM_REGEX.test(numberingSystem)) {
|
21 | throw new RangeError("Invalid numbering system ".concat(numberingSystem));
|
22 | }
|
23 | }
|
24 | opt.nu = numberingSystem;
|
25 | var r = (0, intl_localematcher_1.ResolveLocale)(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
|
26 | var locale = r.locale, nu = r.nu;
|
27 | internalSlots.locale = locale;
|
28 | internalSlots.style = (0, ecma402_abstract_1.GetOption)(opts, 'style', 'string', ['long', 'narrow', 'short'], 'long');
|
29 | internalSlots.numeric = (0, ecma402_abstract_1.GetOption)(opts, 'numeric', 'string', ['always', 'auto'], 'always');
|
30 | var fields = localeData[r.dataLocale];
|
31 | (0, ecma402_abstract_1.invariant)(!!fields, "Missing locale data for ".concat(r.dataLocale));
|
32 | internalSlots.fields = fields;
|
33 | internalSlots.numberFormat = (0, ecma402_abstract_1.createMemoizedNumberFormat)(locales);
|
34 | internalSlots.pluralRules = (0, ecma402_abstract_1.createMemoizedPluralRules)(locales);
|
35 | internalSlots.numberingSystem = nu;
|
36 | return rtf;
|
37 | }
|