@formatjs/intl-locale 5.1.1 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,582 +1,578 @@
1
- import { __assign, __spreadArray } from "tslib";
2
- import { CoerceOptionsToObject, GetOption, HasOwnProperty, SameValue, createDataProperty, invariant, } from '@formatjs/ecma402-abstract';
3
- import { supportedValuesOf } from '@formatjs/intl-enumerator';
4
- import { emitUnicodeLanguageId, emitUnicodeLocaleId, isStructurallyValidLanguageTag, isUnicodeLanguageSubtag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, likelySubtags, parseUnicodeLanguageId, parseUnicodeLocaleId, } from '@formatjs/intl-getcanonicallocales';
5
- import { characterOrders } from './character-orders.generated.js';
6
- import getInternalSlots from './get_internal_slots.js';
7
- import { numberingSystems } from './numbering-systems.generated.js';
8
- import { getCalendarPreferenceDataForRegion, getHourCyclesPreferenceDataForLocaleOrRegion, getTimeZonePreferenceForRegion, getWeekDataForRegion, } from './preference-data.js';
9
- var ALPHANUM_3_8 = /^[a-z0-9]{3,8}$/i;
10
- var RELEVANT_EXTENSION_KEYS = [
11
- 'ca',
12
- 'co',
13
- 'hc',
14
- 'kf',
15
- 'kn',
16
- 'nu',
17
- 'fw',
1
+ import { CoerceOptionsToObject, GetOption, HasOwnProperty, SameValue, createDataProperty, invariant } from "@formatjs/ecma402-abstract";
2
+ import { supportedValuesOf } from "@formatjs/intl-enumerator";
3
+ import { emitUnicodeLanguageId, emitUnicodeLocaleId, isStructurallyValidLanguageTag, isUnicodeLanguageSubtag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, likelySubtags, parseUnicodeLanguageId, parseUnicodeLocaleId } from "@formatjs/intl-getcanonicallocales";
4
+ import { characterOrders } from "./character-orders.generated.js";
5
+ import getInternalSlots from "./get_internal_slots.js";
6
+ import { numberingSystems } from "./numbering-systems.generated.js";
7
+ import { getCalendarPreferenceDataForRegion, getHourCyclesPreferenceDataForLocaleOrRegion, getTimeZonePreferenceForRegion, getWeekDataForRegion } from "./preference-data.js";
8
+ const ALPHANUM_3_8 = /^[a-z0-9]{3,8}$/i;
9
+ const RELEVANT_EXTENSION_KEYS = [
10
+ "ca",
11
+ "co",
12
+ "hc",
13
+ "kf",
14
+ "kn",
15
+ "nu",
16
+ "fw"
18
17
  ];
19
- var UNICODE_TYPE_REGEX = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/i;
18
+ const UNICODE_TYPE_REGEX = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/i;
20
19
  function applyOptionsToTag(tag, options) {
21
- invariant(typeof tag === 'string', 'language tag must be a string');
22
- invariant(isStructurallyValidLanguageTag(tag), 'malformed language tag', RangeError);
23
- var language = GetOption(options, 'language', 'string', undefined, undefined);
24
- if (language !== undefined) {
25
- invariant(isUnicodeLanguageSubtag(language), 'Malformed unicode_language_subtag', RangeError);
26
- }
27
- var script = GetOption(options, 'script', 'string', undefined, undefined);
28
- if (script !== undefined) {
29
- invariant(isUnicodeScriptSubtag(script), 'Malformed unicode_script_subtag', RangeError);
30
- }
31
- var region = GetOption(options, 'region', 'string', undefined, undefined);
32
- if (region !== undefined) {
33
- invariant(isUnicodeRegionSubtag(region), 'Malformed unicode_region_subtag', RangeError);
34
- }
35
- var languageId = parseUnicodeLanguageId(tag);
36
- if (language !== undefined) {
37
- languageId.lang = language;
38
- }
39
- if (script !== undefined) {
40
- languageId.script = script;
41
- }
42
- if (region !== undefined) {
43
- languageId.region = region;
44
- }
45
- return Intl.getCanonicalLocales(emitUnicodeLocaleId(__assign(__assign({}, parseUnicodeLocaleId(tag)), { lang: languageId })))[0];
20
+ invariant(typeof tag === "string", "language tag must be a string");
21
+ invariant(isStructurallyValidLanguageTag(tag), "malformed language tag", RangeError);
22
+ const language = GetOption(options, "language", "string", undefined, undefined);
23
+ if (language !== undefined) {
24
+ invariant(isUnicodeLanguageSubtag(language), "Malformed unicode_language_subtag", RangeError);
25
+ }
26
+ const script = GetOption(options, "script", "string", undefined, undefined);
27
+ if (script !== undefined) {
28
+ invariant(isUnicodeScriptSubtag(script), "Malformed unicode_script_subtag", RangeError);
29
+ }
30
+ const region = GetOption(options, "region", "string", undefined, undefined);
31
+ if (region !== undefined) {
32
+ invariant(isUnicodeRegionSubtag(region), "Malformed unicode_region_subtag", RangeError);
33
+ }
34
+ const languageId = parseUnicodeLanguageId(tag);
35
+ if (language !== undefined) {
36
+ languageId.lang = language;
37
+ }
38
+ if (script !== undefined) {
39
+ languageId.script = script;
40
+ }
41
+ if (region !== undefined) {
42
+ languageId.region = region;
43
+ }
44
+ return Intl.getCanonicalLocales(emitUnicodeLocaleId({
45
+ ...parseUnicodeLocaleId(tag),
46
+ lang: languageId
47
+ }))[0];
46
48
  }
47
49
  function applyUnicodeExtensionToTag(tag, options, relevantExtensionKeys) {
48
- var unicodeExtension;
49
- var keywords = [];
50
- var ast = parseUnicodeLocaleId(tag);
51
- for (var _i = 0, _a = ast.extensions; _i < _a.length; _i++) {
52
- var ext = _a[_i];
53
- if (ext.type === 'u') {
54
- unicodeExtension = ext;
55
- if (Array.isArray(ext.keywords))
56
- keywords = ext.keywords;
57
- }
58
- }
59
- var result = Object.create(null);
60
- for (var _b = 0, relevantExtensionKeys_1 = relevantExtensionKeys; _b < relevantExtensionKeys_1.length; _b++) {
61
- var key = relevantExtensionKeys_1[_b];
62
- var value = void 0, entry = void 0;
63
- for (var _c = 0, keywords_1 = keywords; _c < keywords_1.length; _c++) {
64
- var keyword = keywords_1[_c];
65
- if (keyword[0] === key) {
66
- entry = keyword;
67
- value = entry[1];
68
- }
69
- }
70
- invariant(key in options, "".concat(key, " must be in options"));
71
- var optionsValue = options[key];
72
- if (optionsValue !== undefined) {
73
- invariant(typeof optionsValue === 'string', "Value for ".concat(key, " must be a string"));
74
- value = optionsValue;
75
- if (entry) {
76
- entry[1] = value;
77
- }
78
- else {
79
- keywords.push([key, value]);
80
- }
81
- }
82
- result[key] = value;
83
- }
84
- if (!unicodeExtension) {
85
- if (keywords.length) {
86
- ast.extensions.push({
87
- type: 'u',
88
- keywords: keywords,
89
- attributes: [],
90
- });
91
- }
92
- }
93
- else {
94
- unicodeExtension.keywords = keywords;
95
- }
96
- result.locale = Intl.getCanonicalLocales(emitUnicodeLocaleId(ast))[0];
97
- return result;
50
+ let unicodeExtension;
51
+ let keywords = [];
52
+ const ast = parseUnicodeLocaleId(tag);
53
+ for (const ext of ast.extensions) {
54
+ if (ext.type === "u") {
55
+ unicodeExtension = ext;
56
+ if (Array.isArray(ext.keywords)) keywords = ext.keywords;
57
+ }
58
+ }
59
+ const result = Object.create(null);
60
+ for (const key of relevantExtensionKeys) {
61
+ let value, entry;
62
+ for (const keyword of keywords) {
63
+ if (keyword[0] === key) {
64
+ entry = keyword;
65
+ value = entry[1];
66
+ }
67
+ }
68
+ invariant(key in options, `${key} must be in options`);
69
+ const optionsValue = options[key];
70
+ if (optionsValue !== undefined) {
71
+ invariant(typeof optionsValue === "string", `Value for ${key} must be a string`);
72
+ value = optionsValue;
73
+ if (entry) {
74
+ entry[1] = value;
75
+ } else {
76
+ keywords.push([key, value]);
77
+ }
78
+ }
79
+ result[key] = value;
80
+ }
81
+ if (!unicodeExtension) {
82
+ if (keywords.length) {
83
+ ast.extensions.push({
84
+ type: "u",
85
+ keywords,
86
+ attributes: []
87
+ });
88
+ }
89
+ } else {
90
+ unicodeExtension.keywords = keywords;
91
+ }
92
+ result.locale = Intl.getCanonicalLocales(emitUnicodeLocaleId(ast))[0];
93
+ return result;
98
94
  }
99
- function mergeUnicodeLanguageId(lang, script, region, variants, replacement) {
100
- if (variants === void 0) { variants = []; }
101
- if (!replacement) {
102
- return {
103
- lang: lang || 'und',
104
- script: script,
105
- region: region,
106
- variants: variants,
107
- };
108
- }
109
- return {
110
- lang: !lang || lang === 'und' ? replacement.lang : lang,
111
- script: script || replacement.script,
112
- region: region || replacement.region,
113
- variants: __spreadArray(__spreadArray([], variants, true), replacement.variants, true),
114
- };
95
+ function mergeUnicodeLanguageId(lang, script, region, variants = [], replacement) {
96
+ if (!replacement) {
97
+ return {
98
+ lang: lang || "und",
99
+ script,
100
+ region,
101
+ variants
102
+ };
103
+ }
104
+ return {
105
+ lang: !lang || lang === "und" ? replacement.lang : lang,
106
+ script: script || replacement.script,
107
+ region: region || replacement.region,
108
+ variants: [...variants, ...replacement.variants]
109
+ };
115
110
  }
116
111
  function addLikelySubtags(tag) {
117
- var ast = parseUnicodeLocaleId(tag);
118
- var unicodeLangId = ast.lang;
119
- var lang = unicodeLangId.lang, script = unicodeLangId.script, region = unicodeLangId.region, variants = unicodeLangId.variants;
120
- if (script && region) {
121
- var match_1 = likelySubtags[emitUnicodeLanguageId({ lang: lang, script: script, region: region, variants: [] })];
122
- if (match_1) {
123
- var parts_1 = parseUnicodeLanguageId(match_1);
124
- ast.lang = mergeUnicodeLanguageId(undefined, undefined, undefined, variants, parts_1);
125
- return emitUnicodeLocaleId(ast);
126
- }
127
- }
128
- if (script) {
129
- var match_2 = likelySubtags[emitUnicodeLanguageId({ lang: lang, script: script, variants: [] })];
130
- if (match_2) {
131
- var parts_2 = parseUnicodeLanguageId(match_2);
132
- ast.lang = mergeUnicodeLanguageId(undefined, undefined, region, variants, parts_2);
133
- return emitUnicodeLocaleId(ast);
134
- }
135
- }
136
- if (region) {
137
- var match_3 = likelySubtags[emitUnicodeLanguageId({ lang: lang, region: region, variants: [] })];
138
- if (match_3) {
139
- var parts_3 = parseUnicodeLanguageId(match_3);
140
- ast.lang = mergeUnicodeLanguageId(undefined, script, undefined, variants, parts_3);
141
- return emitUnicodeLocaleId(ast);
142
- }
143
- }
144
- var match = likelySubtags[lang] ||
145
- likelySubtags[emitUnicodeLanguageId({ lang: 'und', script: script, variants: [] })];
146
- if (!match) {
147
- throw new Error("No match for addLikelySubtags");
148
- }
149
- var parts = parseUnicodeLanguageId(match);
150
- ast.lang = mergeUnicodeLanguageId(undefined, script, region, variants, parts);
151
- return emitUnicodeLocaleId(ast);
112
+ const ast = parseUnicodeLocaleId(tag);
113
+ const unicodeLangId = ast.lang;
114
+ const { lang, script, region, variants } = unicodeLangId;
115
+ if (script && region) {
116
+ const match = likelySubtags[emitUnicodeLanguageId({
117
+ lang,
118
+ script,
119
+ region,
120
+ variants: []
121
+ })];
122
+ if (match) {
123
+ const parts = parseUnicodeLanguageId(match);
124
+ ast.lang = mergeUnicodeLanguageId(undefined, undefined, undefined, variants, parts);
125
+ return emitUnicodeLocaleId(ast);
126
+ }
127
+ }
128
+ if (script) {
129
+ const match = likelySubtags[emitUnicodeLanguageId({
130
+ lang,
131
+ script,
132
+ variants: []
133
+ })];
134
+ if (match) {
135
+ const parts = parseUnicodeLanguageId(match);
136
+ ast.lang = mergeUnicodeLanguageId(undefined, undefined, region, variants, parts);
137
+ return emitUnicodeLocaleId(ast);
138
+ }
139
+ }
140
+ if (region) {
141
+ const match = likelySubtags[emitUnicodeLanguageId({
142
+ lang,
143
+ region,
144
+ variants: []
145
+ })];
146
+ if (match) {
147
+ const parts = parseUnicodeLanguageId(match);
148
+ ast.lang = mergeUnicodeLanguageId(undefined, script, undefined, variants, parts);
149
+ return emitUnicodeLocaleId(ast);
150
+ }
151
+ }
152
+ const match = likelySubtags[lang] || likelySubtags[emitUnicodeLanguageId({
153
+ lang: "und",
154
+ script,
155
+ variants: []
156
+ })];
157
+ if (!match) {
158
+ throw new Error(`No match for addLikelySubtags`);
159
+ }
160
+ const parts = parseUnicodeLanguageId(match);
161
+ ast.lang = mergeUnicodeLanguageId(undefined, script, region, variants, parts);
162
+ return emitUnicodeLocaleId(ast);
152
163
  }
153
164
  /**
154
- * From: https://github.com/unicode-org/icu/blob/4231ca5be053a22a1be24eb891817458c97db709/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java#L2395
155
- * @param tag
156
- */
165
+ * From: https://github.com/unicode-org/icu/blob/4231ca5be053a22a1be24eb891817458c97db709/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java#L2395
166
+ * @param tag
167
+ */
157
168
  function removeLikelySubtags(tag) {
158
- var maxLocale = addLikelySubtags(tag);
159
- if (!maxLocale) {
160
- return tag;
161
- }
162
- maxLocale = emitUnicodeLanguageId(__assign(__assign({}, parseUnicodeLanguageId(maxLocale)), { variants: [] }));
163
- var ast = parseUnicodeLocaleId(tag);
164
- var _a = ast.lang, lang = _a.lang, script = _a.script, region = _a.region, variants = _a.variants;
165
- var trial = addLikelySubtags(emitUnicodeLanguageId({ lang: lang, variants: [] }));
166
- if (trial === maxLocale) {
167
- return emitUnicodeLocaleId(__assign(__assign({}, ast), { lang: mergeUnicodeLanguageId(lang, undefined, undefined, variants) }));
168
- }
169
- if (region) {
170
- var trial_1 = addLikelySubtags(emitUnicodeLanguageId({ lang: lang, region: region, variants: [] }));
171
- if (trial_1 === maxLocale) {
172
- return emitUnicodeLocaleId(__assign(__assign({}, ast), { lang: mergeUnicodeLanguageId(lang, undefined, region, variants) }));
173
- }
174
- }
175
- if (script) {
176
- var trial_2 = addLikelySubtags(emitUnicodeLanguageId({ lang: lang, script: script, variants: [] }));
177
- if (trial_2 === maxLocale) {
178
- return emitUnicodeLocaleId(__assign(__assign({}, ast), { lang: mergeUnicodeLanguageId(lang, script, undefined, variants) }));
179
- }
180
- }
181
- return tag;
169
+ let maxLocale = addLikelySubtags(tag);
170
+ if (!maxLocale) {
171
+ return tag;
172
+ }
173
+ maxLocale = emitUnicodeLanguageId({
174
+ ...parseUnicodeLanguageId(maxLocale),
175
+ variants: []
176
+ });
177
+ const ast = parseUnicodeLocaleId(tag);
178
+ const { lang: { lang, script, region, variants } } = ast;
179
+ const trial = addLikelySubtags(emitUnicodeLanguageId({
180
+ lang,
181
+ variants: []
182
+ }));
183
+ if (trial === maxLocale) {
184
+ return emitUnicodeLocaleId({
185
+ ...ast,
186
+ lang: mergeUnicodeLanguageId(lang, undefined, undefined, variants)
187
+ });
188
+ }
189
+ if (region) {
190
+ const trial = addLikelySubtags(emitUnicodeLanguageId({
191
+ lang,
192
+ region,
193
+ variants: []
194
+ }));
195
+ if (trial === maxLocale) {
196
+ return emitUnicodeLocaleId({
197
+ ...ast,
198
+ lang: mergeUnicodeLanguageId(lang, undefined, region, variants)
199
+ });
200
+ }
201
+ }
202
+ if (script) {
203
+ const trial = addLikelySubtags(emitUnicodeLanguageId({
204
+ lang,
205
+ script,
206
+ variants: []
207
+ }));
208
+ if (trial === maxLocale) {
209
+ return emitUnicodeLocaleId({
210
+ ...ast,
211
+ lang: mergeUnicodeLanguageId(lang, script, undefined, variants)
212
+ });
213
+ }
214
+ }
215
+ return tag;
182
216
  }
183
217
  function createArrayFromListOrRestricted(list, restricted) {
184
- var result = list;
185
- if (restricted !== undefined) {
186
- result = [restricted];
187
- }
188
- return Array.from(result);
218
+ let result = list;
219
+ if (restricted !== undefined) {
220
+ result = [restricted];
221
+ }
222
+ return Array.from(result);
189
223
  }
190
224
  function calendarsOfLocale(loc) {
191
- var locInternalSlots = getInternalSlots(loc);
192
- var restricted = locInternalSlots.calendar;
193
- var locale = locInternalSlots.locale;
194
- var region;
195
- if (locale !== 'root') {
196
- region = loc.maximize().region;
197
- }
198
- var preferredCalendars = getCalendarPreferenceDataForRegion(region);
199
- return createArrayFromListOrRestricted(preferredCalendars, restricted);
225
+ const locInternalSlots = getInternalSlots(loc);
226
+ const restricted = locInternalSlots.calendar;
227
+ const locale = locInternalSlots.locale;
228
+ let region;
229
+ if (locale !== "root") {
230
+ region = loc.maximize().region;
231
+ }
232
+ const preferredCalendars = getCalendarPreferenceDataForRegion(region);
233
+ return createArrayFromListOrRestricted(preferredCalendars, restricted);
200
234
  }
201
235
  function collationsOfLocale(loc) {
202
- var locInternalSlots = getInternalSlots(loc);
203
- var restricted = locInternalSlots.collation;
204
- var locale = locInternalSlots.locale;
205
- var supportedCollations = supportedValuesOf('collation', locale).filter(function (co) { return co !== 'standard' && co !== 'search'; });
206
- supportedCollations.sort();
207
- return createArrayFromListOrRestricted(supportedCollations, restricted);
236
+ const locInternalSlots = getInternalSlots(loc);
237
+ const restricted = locInternalSlots.collation;
238
+ const locale = locInternalSlots.locale;
239
+ const supportedCollations = supportedValuesOf("collation", locale).filter((co) => co !== "standard" && co !== "search");
240
+ supportedCollations.sort();
241
+ return createArrayFromListOrRestricted(supportedCollations, restricted);
208
242
  }
209
243
  function hourCyclesOfLocale(loc) {
210
- var locInternalSlots = getInternalSlots(loc);
211
- var restricted = locInternalSlots.hourCycle;
212
- var locale = locInternalSlots.locale;
213
- var region;
214
- if (locale !== 'root') {
215
- region = loc.maximize().region;
216
- }
217
- var preferredHourCycles = getHourCyclesPreferenceDataForLocaleOrRegion(locale, region);
218
- return createArrayFromListOrRestricted(preferredHourCycles, restricted);
244
+ const locInternalSlots = getInternalSlots(loc);
245
+ const restricted = locInternalSlots.hourCycle;
246
+ const locale = locInternalSlots.locale;
247
+ let region;
248
+ if (locale !== "root") {
249
+ region = loc.maximize().region;
250
+ }
251
+ const preferredHourCycles = getHourCyclesPreferenceDataForLocaleOrRegion(locale, region);
252
+ return createArrayFromListOrRestricted(preferredHourCycles, restricted);
219
253
  }
220
254
  function numberingSystemsOfLocale(loc) {
221
- var _a;
222
- var locInternalSlots = getInternalSlots(loc);
223
- var restricted = locInternalSlots.numberingSystem;
224
- var locale = locInternalSlots.locale;
225
- var language = loc.language;
226
- var localeNumberingSystems = (_a = numberingSystems[locale]) !== null && _a !== void 0 ? _a : numberingSystems[language];
227
- if (localeNumberingSystems) {
228
- return createArrayFromListOrRestricted(__spreadArray([], localeNumberingSystems, true), restricted);
229
- }
230
- return createArrayFromListOrRestricted([], restricted);
255
+ const locInternalSlots = getInternalSlots(loc);
256
+ const restricted = locInternalSlots.numberingSystem;
257
+ const locale = locInternalSlots.locale;
258
+ const language = loc.language;
259
+ const localeNumberingSystems = numberingSystems[locale] ?? numberingSystems[language];
260
+ if (localeNumberingSystems) {
261
+ return createArrayFromListOrRestricted([...localeNumberingSystems], restricted);
262
+ }
263
+ return createArrayFromListOrRestricted([], restricted);
231
264
  }
232
265
  function timeZonesOfLocale(loc) {
233
- var locInternalSlots = getInternalSlots(loc);
234
- var locale = locInternalSlots.locale;
235
- var region = parseUnicodeLanguageId(locale).region;
236
- if (!region) {
237
- return undefined;
238
- }
239
- var preferredTimeZones = getTimeZonePreferenceForRegion(region);
240
- preferredTimeZones.sort();
241
- return Array.from(preferredTimeZones);
266
+ const locInternalSlots = getInternalSlots(loc);
267
+ const locale = locInternalSlots.locale;
268
+ const region = parseUnicodeLanguageId(locale).region;
269
+ if (!region) {
270
+ return undefined;
271
+ }
272
+ const preferredTimeZones = getTimeZonePreferenceForRegion(region);
273
+ preferredTimeZones.sort();
274
+ return Array.from(preferredTimeZones);
242
275
  }
243
276
  function translateCharacterOrder(order) {
244
- if (order === 'right-to-left') {
245
- return 'rtl';
246
- }
247
- return 'ltr';
277
+ if (order === "right-to-left") {
278
+ return "rtl";
279
+ }
280
+ return "ltr";
248
281
  }
249
282
  function characterDirectionOfLocale(loc) {
250
- var locale = loc.minimize().toString();
251
- return translateCharacterOrder(characterOrders[locale]);
283
+ const locale = loc.minimize().toString();
284
+ return translateCharacterOrder(characterOrders[locale]);
252
285
  }
253
286
  function weekInfoOfLocale(loc) {
254
- var locInternalSlots = getInternalSlots(loc);
255
- var locale = locInternalSlots.locale;
256
- var region;
257
- if (locale !== 'root') {
258
- region = loc.maximize().region;
259
- }
260
- return getWeekDataForRegion(region);
287
+ const locInternalSlots = getInternalSlots(loc);
288
+ const locale = locInternalSlots.locale;
289
+ let region;
290
+ if (locale !== "root") {
291
+ region = loc.maximize().region;
292
+ }
293
+ return getWeekDataForRegion(region);
261
294
  }
262
- var TABLE_1 = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
295
+ const TABLE_1 = [
296
+ "sun",
297
+ "mon",
298
+ "tue",
299
+ "wed",
300
+ "thu",
301
+ "fri",
302
+ "sat"
303
+ ];
263
304
  function weekdayToString(fw) {
264
- return TABLE_1[+fw];
265
- }
266
- var Locale = /** @class */ (function () {
267
- function Locale(tag, opts) {
268
- // test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
269
- // Cannot use `new.target` bc of IE11 & TS transpiles it to something else
270
- var newTarget = this && this instanceof Locale ? this.constructor : void 0;
271
- if (!newTarget) {
272
- throw new TypeError("Intl.Locale must be called with 'new'");
273
- }
274
- var relevantExtensionKeys = Locale.relevantExtensionKeys;
275
- var internalSlotsList = [
276
- 'initializedLocale',
277
- 'locale',
278
- 'calendar',
279
- 'collation',
280
- 'hourCycle',
281
- 'numberingSystem',
282
- ];
283
- if (relevantExtensionKeys.indexOf('kf') > -1) {
284
- internalSlotsList.push('caseFirst');
285
- }
286
- if (relevantExtensionKeys.indexOf('kn') > -1) {
287
- internalSlotsList.push('numeric');
288
- }
289
- if (tag === undefined) {
290
- throw new TypeError("First argument to Intl.Locale constructor can't be empty or missing");
291
- }
292
- if (typeof tag !== 'string' && typeof tag !== 'object') {
293
- throw new TypeError('tag must be a string or object');
294
- }
295
- var tagInternalSlots;
296
- if (typeof tag === 'object' &&
297
- (tagInternalSlots = getInternalSlots(tag)) &&
298
- HasOwnProperty(tagInternalSlots, 'initializedLocale')) {
299
- tag = tagInternalSlots.locale;
300
- }
301
- else {
302
- tag = tag.toString();
303
- }
304
- var internalSlots = getInternalSlots(this, internalSlotsList);
305
- var options = CoerceOptionsToObject(opts);
306
- tag = applyOptionsToTag(tag, options);
307
- var opt = Object.create(null);
308
- var calendar = GetOption(options, 'calendar', 'string', undefined, undefined);
309
- if (calendar !== undefined) {
310
- if (!UNICODE_TYPE_REGEX.test(calendar)) {
311
- throw new RangeError('invalid calendar');
312
- }
313
- }
314
- opt.ca = calendar;
315
- var collation = GetOption(options, 'collation', 'string', undefined, undefined);
316
- if (collation !== undefined) {
317
- if (!UNICODE_TYPE_REGEX.test(collation)) {
318
- throw new RangeError('invalid collation');
319
- }
320
- }
321
- opt.co = collation;
322
- var fw = GetOption(options, 'firstDayOfWeek', 'string', undefined, undefined);
323
- if (fw !== undefined) {
324
- fw = weekdayToString(fw);
325
- if (!ALPHANUM_3_8.test(fw)) {
326
- throw new RangeError('Invalid firstDayOfWeek');
327
- }
328
- }
329
- opt.fw = fw;
330
- var hc = GetOption(options, 'hourCycle', 'string', ['h11', 'h12', 'h23', 'h24'], undefined);
331
- opt.hc = hc;
332
- var kf = GetOption(options, 'caseFirst', 'string', ['upper', 'lower', 'false'], undefined);
333
- opt.kf = kf;
334
- var _kn = GetOption(options, 'numeric', 'boolean', undefined, undefined);
335
- var kn;
336
- if (_kn !== undefined) {
337
- kn = String(_kn);
338
- }
339
- opt.kn = kn;
340
- var numberingSystem = GetOption(options, 'numberingSystem', 'string', undefined, undefined);
341
- if (numberingSystem !== undefined) {
342
- if (!UNICODE_TYPE_REGEX.test(numberingSystem)) {
343
- throw new RangeError('Invalid numberingSystem');
344
- }
345
- }
346
- opt.nu = numberingSystem;
347
- var r = applyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys);
348
- internalSlots.locale = r.locale;
349
- internalSlots.calendar = r.ca;
350
- internalSlots.collation = r.co;
351
- internalSlots.firstDayOfWeek = r.fw;
352
- internalSlots.hourCycle = r.hc;
353
- if (relevantExtensionKeys.indexOf('kf') > -1) {
354
- internalSlots.caseFirst = r.kf;
355
- }
356
- if (relevantExtensionKeys.indexOf('kn') > -1) {
357
- internalSlots.numeric = SameValue(r.kn, 'true');
358
- }
359
- internalSlots.numberingSystem = r.nu;
360
- }
361
- /**
362
- * https://www.unicode.org/reports/tr35/#Likely_Subtags
363
- */
364
- Locale.prototype.maximize = function () {
365
- var locale = getInternalSlots(this).locale;
366
- try {
367
- var maximizedLocale = addLikelySubtags(locale);
368
- return new Locale(maximizedLocale);
369
- }
370
- catch (_a) {
371
- return new Locale(locale);
372
- }
373
- };
374
- /**
375
- * https://www.unicode.org/reports/tr35/#Likely_Subtags
376
- */
377
- Locale.prototype.minimize = function () {
378
- var locale = getInternalSlots(this).locale;
379
- try {
380
- var minimizedLocale = removeLikelySubtags(locale);
381
- return new Locale(minimizedLocale);
382
- }
383
- catch (_a) {
384
- return new Locale(locale);
385
- }
386
- };
387
- Locale.prototype.toString = function () {
388
- return getInternalSlots(this).locale;
389
- };
390
- Object.defineProperty(Locale.prototype, "baseName", {
391
- get: function () {
392
- var locale = getInternalSlots(this).locale;
393
- return emitUnicodeLanguageId(parseUnicodeLanguageId(locale));
394
- },
395
- enumerable: false,
396
- configurable: true
397
- });
398
- Object.defineProperty(Locale.prototype, "calendar", {
399
- get: function () {
400
- return getInternalSlots(this).calendar;
401
- },
402
- enumerable: false,
403
- configurable: true
404
- });
405
- Object.defineProperty(Locale.prototype, "collation", {
406
- get: function () {
407
- return getInternalSlots(this).collation;
408
- },
409
- enumerable: false,
410
- configurable: true
411
- });
412
- Object.defineProperty(Locale.prototype, "caseFirst", {
413
- get: function () {
414
- return getInternalSlots(this).caseFirst;
415
- },
416
- enumerable: false,
417
- configurable: true
418
- });
419
- Object.defineProperty(Locale.prototype, "numeric", {
420
- get: function () {
421
- return getInternalSlots(this).numeric;
422
- },
423
- enumerable: false,
424
- configurable: true
425
- });
426
- Object.defineProperty(Locale.prototype, "numberingSystem", {
427
- get: function () {
428
- return getInternalSlots(this).numberingSystem;
429
- },
430
- enumerable: false,
431
- configurable: true
432
- });
433
- Object.defineProperty(Locale.prototype, "language", {
434
- /**
435
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.language
436
- */
437
- get: function () {
438
- var locale = getInternalSlots(this).locale;
439
- return parseUnicodeLanguageId(locale).lang;
440
- },
441
- enumerable: false,
442
- configurable: true
443
- });
444
- Object.defineProperty(Locale.prototype, "script", {
445
- /**
446
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.script
447
- */
448
- get: function () {
449
- var locale = getInternalSlots(this).locale;
450
- return parseUnicodeLanguageId(locale).script;
451
- },
452
- enumerable: false,
453
- configurable: true
454
- });
455
- Object.defineProperty(Locale.prototype, "region", {
456
- /**
457
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.region
458
- */
459
- get: function () {
460
- var locale = getInternalSlots(this).locale;
461
- return parseUnicodeLanguageId(locale).region;
462
- },
463
- enumerable: false,
464
- configurable: true
465
- });
466
- Object.defineProperty(Locale.prototype, "firstDayOfWeek", {
467
- get: function () {
468
- var internalSlots = getInternalSlots(this);
469
- if (!HasOwnProperty(internalSlots, 'initializedLocale')) {
470
- throw new TypeError('Error uninitialized locale');
471
- }
472
- return internalSlots.firstDayOfWeek;
473
- },
474
- enumerable: false,
475
- configurable: true
476
- });
477
- Object.defineProperty(Locale.prototype, "hourCycle", {
478
- get: function () {
479
- var internalSlots = getInternalSlots(this);
480
- if (!HasOwnProperty(internalSlots, 'initializedLocale')) {
481
- throw new TypeError('Error uninitialized locale');
482
- }
483
- return internalSlots.hourCycle;
484
- },
485
- enumerable: false,
486
- configurable: true
487
- });
488
- /**
489
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars
490
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCalendars
491
- */
492
- Locale.prototype.getCalendars = function () {
493
- return calendarsOfLocale(this);
494
- };
495
- /**
496
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations
497
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCollations
498
- */
499
- Locale.prototype.getCollations = function () {
500
- return collationsOfLocale(this);
501
- };
502
- /**
503
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles
504
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getHourCycles
505
- */
506
- Locale.prototype.getHourCycles = function () {
507
- var internalSlots = getInternalSlots(this);
508
- if (!HasOwnProperty(internalSlots, 'initializedLocale')) {
509
- throw new TypeError('Error uninitialized locale');
510
- }
511
- return hourCyclesOfLocale(this);
512
- };
513
- /**
514
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems
515
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getNumberingSystems
516
- */
517
- Locale.prototype.getNumberingSystems = function () {
518
- return numberingSystemsOfLocale(this);
519
- };
520
- /**
521
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones
522
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTimeZones
523
- */
524
- Locale.prototype.getTimeZones = function () {
525
- return timeZonesOfLocale(this);
526
- };
527
- /**
528
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
529
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTextInfo
530
- */
531
- Locale.prototype.getTextInfo = function () {
532
- var info = Object.create(Object.prototype);
533
- var dir = characterDirectionOfLocale(this);
534
- createDataProperty(info, 'direction', dir);
535
- return info;
536
- };
537
- /**
538
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo
539
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getWeekInfo
540
- */
541
- Locale.prototype.getWeekInfo = function () {
542
- var info = Object.create(Object.prototype);
543
- var internalSlots = getInternalSlots(this);
544
- if (!HasOwnProperty(internalSlots, 'initializedLocale')) {
545
- throw new TypeError('Error uninitialized locale');
546
- }
547
- var wi = weekInfoOfLocale(this);
548
- var we = wi.weekend;
549
- createDataProperty(info, 'firstDay', wi.firstDay);
550
- createDataProperty(info, 'weekend', we);
551
- createDataProperty(info, 'minimalDays', wi.minimalDays);
552
- var fw = internalSlots.firstDayOfWeek;
553
- if (fw !== undefined) {
554
- info.firstDay = fw;
555
- }
556
- return info;
557
- };
558
- Locale.relevantExtensionKeys = RELEVANT_EXTENSION_KEYS;
559
- Locale.polyfilled = true;
560
- return Locale;
561
- }());
562
- export { Locale };
563
- try {
564
- if (typeof Symbol !== 'undefined') {
565
- Object.defineProperty(Locale.prototype, Symbol.toStringTag, {
566
- value: 'Intl.Locale',
567
- writable: false,
568
- enumerable: false,
569
- configurable: true,
570
- });
571
- }
572
- Object.defineProperty(Locale.prototype.constructor, 'length', {
573
- value: 1,
574
- writable: false,
575
- enumerable: false,
576
- configurable: true,
577
- });
305
+ return TABLE_1[+fw];
578
306
  }
579
- catch (_a) {
580
- // Meta fix so we're test262-compliant, not important
307
+ export class Locale {
308
+ constructor(tag, opts) {
309
+ // test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
310
+ // Cannot use `new.target` bc of IE11 & TS transpiles it to something else
311
+ const newTarget = this && this instanceof Locale ? this.constructor : void 0;
312
+ if (!newTarget) {
313
+ throw new TypeError("Intl.Locale must be called with 'new'");
314
+ }
315
+ const { relevantExtensionKeys } = Locale;
316
+ const internalSlotsList = [
317
+ "initializedLocale",
318
+ "locale",
319
+ "calendar",
320
+ "collation",
321
+ "hourCycle",
322
+ "numberingSystem"
323
+ ];
324
+ if (relevantExtensionKeys.indexOf("kf") > -1) {
325
+ internalSlotsList.push("caseFirst");
326
+ }
327
+ if (relevantExtensionKeys.indexOf("kn") > -1) {
328
+ internalSlotsList.push("numeric");
329
+ }
330
+ if (tag === undefined) {
331
+ throw new TypeError("First argument to Intl.Locale constructor can't be empty or missing");
332
+ }
333
+ if (typeof tag !== "string" && typeof tag !== "object") {
334
+ throw new TypeError("tag must be a string or object");
335
+ }
336
+ let tagInternalSlots;
337
+ if (typeof tag === "object" && (tagInternalSlots = getInternalSlots(tag)) && HasOwnProperty(tagInternalSlots, "initializedLocale")) {
338
+ tag = tagInternalSlots.locale;
339
+ } else {
340
+ tag = tag.toString();
341
+ }
342
+ let internalSlots = getInternalSlots(this, internalSlotsList);
343
+ let options = CoerceOptionsToObject(opts);
344
+ tag = applyOptionsToTag(tag, options);
345
+ const opt = Object.create(null);
346
+ const calendar = GetOption(options, "calendar", "string", undefined, undefined);
347
+ if (calendar !== undefined) {
348
+ if (!UNICODE_TYPE_REGEX.test(calendar)) {
349
+ throw new RangeError("invalid calendar");
350
+ }
351
+ }
352
+ opt.ca = calendar;
353
+ const collation = GetOption(options, "collation", "string", undefined, undefined);
354
+ if (collation !== undefined) {
355
+ if (!UNICODE_TYPE_REGEX.test(collation)) {
356
+ throw new RangeError("invalid collation");
357
+ }
358
+ }
359
+ opt.co = collation;
360
+ let fw = GetOption(options, "firstDayOfWeek", "string", undefined, undefined);
361
+ if (fw !== undefined) {
362
+ fw = weekdayToString(fw);
363
+ if (!ALPHANUM_3_8.test(fw)) {
364
+ throw new RangeError("Invalid firstDayOfWeek");
365
+ }
366
+ }
367
+ opt.fw = fw;
368
+ const hc = GetOption(options, "hourCycle", "string", [
369
+ "h11",
370
+ "h12",
371
+ "h23",
372
+ "h24"
373
+ ], undefined);
374
+ opt.hc = hc;
375
+ const kf = GetOption(options, "caseFirst", "string", [
376
+ "upper",
377
+ "lower",
378
+ "false"
379
+ ], undefined);
380
+ opt.kf = kf;
381
+ const _kn = GetOption(options, "numeric", "boolean", undefined, undefined);
382
+ let kn;
383
+ if (_kn !== undefined) {
384
+ kn = String(_kn);
385
+ }
386
+ opt.kn = kn;
387
+ const numberingSystem = GetOption(options, "numberingSystem", "string", undefined, undefined);
388
+ if (numberingSystem !== undefined) {
389
+ if (!UNICODE_TYPE_REGEX.test(numberingSystem)) {
390
+ throw new RangeError("Invalid numberingSystem");
391
+ }
392
+ }
393
+ opt.nu = numberingSystem;
394
+ const r = applyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys);
395
+ internalSlots.locale = r.locale;
396
+ internalSlots.calendar = r.ca;
397
+ internalSlots.collation = r.co;
398
+ internalSlots.firstDayOfWeek = r.fw;
399
+ internalSlots.hourCycle = r.hc;
400
+ if (relevantExtensionKeys.indexOf("kf") > -1) {
401
+ internalSlots.caseFirst = r.kf;
402
+ }
403
+ if (relevantExtensionKeys.indexOf("kn") > -1) {
404
+ internalSlots.numeric = SameValue(r.kn, "true");
405
+ }
406
+ internalSlots.numberingSystem = r.nu;
407
+ }
408
+ /**
409
+ * https://www.unicode.org/reports/tr35/#Likely_Subtags
410
+ */
411
+ maximize() {
412
+ const locale = getInternalSlots(this).locale;
413
+ try {
414
+ const maximizedLocale = addLikelySubtags(locale);
415
+ return new Locale(maximizedLocale);
416
+ } catch {
417
+ return new Locale(locale);
418
+ }
419
+ }
420
+ /**
421
+ * https://www.unicode.org/reports/tr35/#Likely_Subtags
422
+ */
423
+ minimize() {
424
+ const locale = getInternalSlots(this).locale;
425
+ try {
426
+ const minimizedLocale = removeLikelySubtags(locale);
427
+ return new Locale(minimizedLocale);
428
+ } catch {
429
+ return new Locale(locale);
430
+ }
431
+ }
432
+ toString() {
433
+ return getInternalSlots(this).locale;
434
+ }
435
+ get baseName() {
436
+ const locale = getInternalSlots(this).locale;
437
+ return emitUnicodeLanguageId(parseUnicodeLanguageId(locale));
438
+ }
439
+ get calendar() {
440
+ return getInternalSlots(this).calendar;
441
+ }
442
+ get collation() {
443
+ return getInternalSlots(this).collation;
444
+ }
445
+ get caseFirst() {
446
+ return getInternalSlots(this).caseFirst;
447
+ }
448
+ get numeric() {
449
+ return getInternalSlots(this).numeric;
450
+ }
451
+ get numberingSystem() {
452
+ return getInternalSlots(this).numberingSystem;
453
+ }
454
+ /**
455
+ * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.language
456
+ */
457
+ get language() {
458
+ const locale = getInternalSlots(this).locale;
459
+ return parseUnicodeLanguageId(locale).lang;
460
+ }
461
+ /**
462
+ * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.script
463
+ */
464
+ get script() {
465
+ const locale = getInternalSlots(this).locale;
466
+ return parseUnicodeLanguageId(locale).script;
467
+ }
468
+ /**
469
+ * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.region
470
+ */
471
+ get region() {
472
+ const locale = getInternalSlots(this).locale;
473
+ return parseUnicodeLanguageId(locale).region;
474
+ }
475
+ get firstDayOfWeek() {
476
+ const internalSlots = getInternalSlots(this);
477
+ if (!HasOwnProperty(internalSlots, "initializedLocale")) {
478
+ throw new TypeError("Error uninitialized locale");
479
+ }
480
+ return internalSlots.firstDayOfWeek;
481
+ }
482
+ get hourCycle() {
483
+ const internalSlots = getInternalSlots(this);
484
+ if (!HasOwnProperty(internalSlots, "initializedLocale")) {
485
+ throw new TypeError("Error uninitialized locale");
486
+ }
487
+ return internalSlots.hourCycle;
488
+ }
489
+ /**
490
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars
491
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCalendars
492
+ */
493
+ getCalendars() {
494
+ return calendarsOfLocale(this);
495
+ }
496
+ /**
497
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations
498
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCollations
499
+ */
500
+ getCollations() {
501
+ return collationsOfLocale(this);
502
+ }
503
+ /**
504
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles
505
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getHourCycles
506
+ */
507
+ getHourCycles() {
508
+ const internalSlots = getInternalSlots(this);
509
+ if (!HasOwnProperty(internalSlots, "initializedLocale")) {
510
+ throw new TypeError("Error uninitialized locale");
511
+ }
512
+ return hourCyclesOfLocale(this);
513
+ }
514
+ /**
515
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems
516
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getNumberingSystems
517
+ */
518
+ getNumberingSystems() {
519
+ return numberingSystemsOfLocale(this);
520
+ }
521
+ /**
522
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones
523
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTimeZones
524
+ */
525
+ getTimeZones() {
526
+ return timeZonesOfLocale(this);
527
+ }
528
+ /**
529
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
530
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTextInfo
531
+ */
532
+ getTextInfo() {
533
+ const info = Object.create(Object.prototype);
534
+ const dir = characterDirectionOfLocale(this);
535
+ createDataProperty(info, "direction", dir);
536
+ return info;
537
+ }
538
+ /**
539
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo
540
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getWeekInfo
541
+ */
542
+ getWeekInfo() {
543
+ const info = Object.create(Object.prototype);
544
+ const internalSlots = getInternalSlots(this);
545
+ if (!HasOwnProperty(internalSlots, "initializedLocale")) {
546
+ throw new TypeError("Error uninitialized locale");
547
+ }
548
+ const wi = weekInfoOfLocale(this);
549
+ const we = wi.weekend;
550
+ createDataProperty(info, "firstDay", wi.firstDay);
551
+ createDataProperty(info, "weekend", we);
552
+ createDataProperty(info, "minimalDays", wi.minimalDays);
553
+ const fw = internalSlots.firstDayOfWeek;
554
+ if (fw !== undefined) {
555
+ info.firstDay = fw;
556
+ }
557
+ return info;
558
+ }
559
+ static relevantExtensionKeys = RELEVANT_EXTENSION_KEYS;
560
+ static polyfilled = true;
581
561
  }
562
+ try {
563
+ if (typeof Symbol !== "undefined") {
564
+ Object.defineProperty(Locale.prototype, Symbol.toStringTag, {
565
+ value: "Intl.Locale",
566
+ writable: false,
567
+ enumerable: false,
568
+ configurable: true
569
+ });
570
+ }
571
+ Object.defineProperty(Locale.prototype.constructor, "length", {
572
+ value: 1,
573
+ writable: false,
574
+ enumerable: false,
575
+ configurable: true
576
+ });
577
+ } catch {}
582
578
  export default Locale;