@formatjs/intl-locale 5.3.10 → 5.3.11

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.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  //#region packages/intl-locale/index.d.ts
2
- interface IntlLocaleOptions {
2
+ export interface IntlLocaleOptions {
3
3
  language?: string;
4
4
  script?: string;
5
5
  region?: string;
6
+ variants?: string;
6
7
  calendar?: string;
7
8
  collation?: string;
8
9
  hourCycle?: "h11" | "h12" | "h23" | "h24";
@@ -11,19 +12,19 @@ interface IntlLocaleOptions {
11
12
  numeric?: boolean;
12
13
  firstDayOfWeek?: string;
13
14
  }
14
- interface IntlLocaleInternal extends IntlLocaleOptions {
15
+ export interface IntlLocaleInternal extends IntlLocaleOptions {
15
16
  locale: string;
16
17
  initializedLocale: boolean;
17
18
  }
18
- declare class Locale {
19
+ export declare class Locale {
19
20
  constructor(tag: string | Locale, opts?: IntlLocaleOptions);
20
21
  /**
21
- * https://www.unicode.org/reports/tr35/#Likely_Subtags
22
- */
22
+ * https://www.unicode.org/reports/tr35/#Likely_Subtags
23
+ */
23
24
  maximize(): Locale;
24
25
  /**
25
- * https://www.unicode.org/reports/tr35/#Likely_Subtags
26
- */
26
+ * https://www.unicode.org/reports/tr35/#Likely_Subtags
27
+ */
27
28
  minimize(): Locale;
28
29
  toString(): string;
29
30
  get baseName(): string;
@@ -33,76 +34,74 @@ declare class Locale {
33
34
  get numeric(): boolean | undefined;
34
35
  get numberingSystem(): string | undefined;
35
36
  /**
36
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.language
37
- */
37
+ * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.language
38
+ */
38
39
  get language(): string;
39
40
  /**
40
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.script
41
- */
41
+ * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.script
42
+ */
42
43
  get script(): string | undefined;
43
44
  /**
44
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.region
45
- */
45
+ * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.region
46
+ */
46
47
  get region(): string | undefined;
47
48
  /**
48
- * Returns the variant subtags of the locale, or undefined if none exist.
49
- * Multiple variants are joined with hyphens in alphabetical order.
50
- *
51
- * Added in ECMA-402 via PR #960 to align with other subtag accessors.
52
- * @see https://tc39.es/ecma402/#sec-Intl.Locale.prototype.variants
53
- * @see https://github.com/tc39/ecma402/pull/960
54
- * @see https://github.com/tc39/ecma402/issues/900
55
- */
49
+ * Returns the variant subtags of the locale, or undefined if none exist.
50
+ * Multiple variants are joined with hyphens in alphabetical order.
51
+ *
52
+ * Added in ECMA-402 via PR #960 to align with other subtag accessors.
53
+ * @see https://tc39.es/ecma402/#sec-Intl.Locale.prototype.variants
54
+ * @see https://github.com/tc39/ecma402/pull/960
55
+ * @see https://github.com/tc39/ecma402/issues/900
56
+ */
56
57
  get variants(): string | undefined;
57
58
  get firstDayOfWeek(): string | undefined;
58
59
  get hourCycle(): "h11" | "h12" | "h23" | "h24" | undefined;
59
60
  /**
60
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars
61
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCalendars
62
- */
61
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars
62
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCalendars
63
+ */
63
64
  getCalendars(): string[];
64
65
  /**
65
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations
66
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCollations
67
- */
66
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations
67
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCollations
68
+ */
68
69
  getCollations(): string[];
69
70
  /**
70
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles
71
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getHourCycles
72
- */
71
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles
72
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getHourCycles
73
+ */
73
74
  getHourCycles(): string[];
74
75
  /**
75
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems
76
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getNumberingSystems
77
- */
76
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems
77
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getNumberingSystems
78
+ */
78
79
  getNumberingSystems(): string[];
79
80
  /**
80
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones
81
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTimeZones
82
- */
81
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones
82
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTimeZones
83
+ */
83
84
  getTimeZones(): string[] | undefined;
84
85
  /**
85
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
86
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTextInfo
87
- */
86
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
87
+ * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTextInfo
88
+ */
88
89
  getTextInfo(): {
89
90
  direction: string;
90
91
  };
91
92
  /**
92
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo
93
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getWeekInfo
94
- */
93
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo
94
+ * ECMA-402 §15.3.22 Intl.Locale.prototype.getWeekInfo, steps 3–7.
95
+ * https://tc39.es/ecma402/#sec-Intl.Locale.prototype.getWeekInfo
96
+ * https://github.com/tc39/ecma402/blob/b1c961988b9a07894b1dc3dc2b5626ea48387d61/spec/locale.html#L420-L424
97
+ */
95
98
  getWeekInfo(): {
96
- firstDay: string;
97
- weekend: {
98
- start: string;
99
- end: string;
100
- };
101
- minimalDays: number;
99
+ firstDay: number;
100
+ weekend: number[];
102
101
  };
103
102
  static relevantExtensionKeys: readonly ["ca", "co", "hc", "kf", "kn", "nu", "fw"];
104
103
  static readonly polyfilled = true;
105
104
  }
106
105
  //#endregion
107
- export { IntlLocaleInternal, IntlLocaleOptions, Locale, Locale as default };
106
+ export { Locale as default };
108
107
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,5 +1,20 @@
1
1
  import { supportedValuesOf } from "@formatjs/intl-supportedvaluesof";
2
- import { emitUnicodeLanguageId, emitUnicodeLocaleId, isStructurallyValidLanguageTag, isUnicodeLanguageSubtag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, likelySubtags, parseUnicodeLanguageId, parseUnicodeLocaleId } from "@formatjs/intl-getcanonicallocales";
2
+ import { emitUnicodeLanguageId, emitUnicodeLocaleId, isStructurallyValidLanguageTag, isUnicodeLanguageSubtag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, isUnicodeVariantSubtag, likelySubtags, parseUnicodeLanguageId, parseUnicodeLocaleId } from "@formatjs/intl-getcanonicallocales";
3
+ //#region packages/ecma262-abstract/ToString.js
4
+ /**
5
+ * https://tc39.es/ecma262/#sec-tostring
6
+ */
7
+ function ToString(o) {
8
+ if (typeof o === "symbol") throw TypeError("Cannot convert a Symbol value to a string");
9
+ return String(o);
10
+ }
11
+ //#endregion
12
+ //#region packages/ecma402-abstract/IsUnicodeLocaleIdentifierType.js
13
+ /** Tests the Unicode locale identifier `type` grammar, not locale support. */
14
+ function IsUnicodeLocaleIdentifierType(value) {
15
+ return /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*(?![\s\S])/i.test(value);
16
+ }
17
+ //#endregion
3
18
  //#region packages/ecma262-abstract/HasOwnProperty.js
4
19
  /**
5
20
  * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-hasownproperty
@@ -38,15 +53,6 @@ function CoerceOptionsToObject(options) {
38
53
  return ToObject(options);
39
54
  }
40
55
  //#endregion
41
- //#region packages/ecma262-abstract/ToString.js
42
- /**
43
- * https://tc39.es/ecma262/#sec-tostring
44
- */
45
- function ToString(o) {
46
- if (typeof o === "symbol") throw TypeError("Cannot convert a Symbol value to a string");
47
- return String(o);
48
- }
49
- //#endregion
50
56
  //#region packages/ecma402-abstract/GetOption.js
51
57
  /**
52
58
  * https://tc39.es/ecma402/#sec-getoption
@@ -57,7 +63,7 @@ function ToString(o) {
57
63
  * @param fallback
58
64
  */
59
65
  function GetOption(opts, prop, type, values, fallback) {
60
- if (typeof opts !== "object") throw new TypeError("Options must be an object");
66
+ if (opts === null || typeof opts !== "object" && typeof opts !== "function") throw new TypeError("Options must be an object");
61
67
  let value = opts[prop];
62
68
  if (value !== void 0) {
63
69
  if (type !== "boolean" && type !== "string") throw new TypeError("invalid type");
@@ -929,9 +935,13 @@ const characterOrders = {
929
935
  //#endregion
930
936
  //#region packages/intl-locale/get_internal_slots.ts
931
937
  const internalSlotMap = /* @__PURE__ */ new WeakMap();
932
- function getInternalSlots(x, internalSlotsList = []) {
938
+ function getInternalSlotsIfPresent(x) {
939
+ return internalSlotMap.get(x);
940
+ }
941
+ function getInternalSlots(x, internalSlotsList) {
933
942
  let internalSlots = internalSlotMap.get(x);
934
943
  if (!internalSlots) {
944
+ if (internalSlotsList === void 0) throw new TypeError("Intl.Locale method called on incompatible receiver");
935
945
  internalSlots = Object.create(null, internalSlotsList.reduce((all, prop) => {
936
946
  all[prop] = {
937
947
  enumerable: false,
@@ -4162,29 +4172,36 @@ const weekData = {
4162
4172
  };
4163
4173
  //#endregion
4164
4174
  //#region packages/intl-locale/preference-data.ts
4165
- function getCalendarPreferenceDataForRegion(region) {
4166
- return (calendars[(region ? region.toUpperCase() : null) || ""] || calendars["001"]).map((c) => {
4167
- if (c === "gregorian") return "gregory";
4168
- if (c === "islamic-civil") return "islamicc";
4169
- return c;
4170
- });
4175
+ function getCalendarPreferenceDataForRegion(region, regionOverride, language) {
4176
+ for (const candidate of [regionOverride, region]) {
4177
+ if (!candidate) continue;
4178
+ const territory = candidate.toUpperCase();
4179
+ const values = calendars[`${language}-${territory}`] || calendars[territory];
4180
+ if (values) return values.map((c) => c === "gregorian" ? "gregory" : c);
4181
+ }
4182
+ return ["gregory"];
4171
4183
  }
4172
- function getHourCyclesPreferenceDataForLocaleOrRegion(locale, region) {
4173
- const _locale = locale.toLowerCase();
4174
- const _region = region ? region.toUpperCase() : "";
4175
- return [...hourCycles[_locale] || hourCycles[_region] || hourCycles[`${_locale}-001`] || hourCycles["001"]];
4184
+ function getHourCyclesPreferenceDataForLocaleOrRegion(language, region, regionOverride) {
4185
+ for (const candidate of [regionOverride, region]) {
4186
+ if (!candidate) continue;
4187
+ const territory = candidate.toUpperCase();
4188
+ const values = hourCycles[`${language}-${territory}`] || hourCycles[territory];
4189
+ if (values) return [...values];
4190
+ }
4191
+ return ["h23"];
4176
4192
  }
4177
4193
  function getTimeZonePreferenceForRegion(region) {
4178
4194
  const territory = region.toLowerCase();
4179
4195
  if (timezones[territory]) return [...timezones[territory]];
4180
4196
  return [];
4181
4197
  }
4182
- function getWeekDataForRegion(region) {
4183
- return weekData[(region ? region.toUpperCase() : "") || "001"] || weekData["001"];
4198
+ function getWeekDataForRegion(region, regionOverride) {
4199
+ const _region = region ? region.toUpperCase() : "";
4200
+ const override = (regionOverride || "").toUpperCase();
4201
+ return weekData[override] || weekData[_region] || weekData["001"];
4184
4202
  }
4185
4203
  //#endregion
4186
4204
  //#region packages/intl-locale/index.ts
4187
- const ALPHANUM_3_8 = /^[a-z0-9]{3,8}$/i;
4188
4205
  const RELEVANT_EXTENSION_KEYS = [
4189
4206
  "ca",
4190
4207
  "co",
@@ -4194,17 +4211,23 @@ const RELEVANT_EXTENSION_KEYS = [
4194
4211
  "nu",
4195
4212
  "fw"
4196
4213
  ];
4197
- const UNICODE_TYPE_REGEX = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/i;
4198
4214
  function applyOptionsToTag(tag, options) {
4199
4215
  invariant(typeof tag === "string", "language tag must be a string");
4200
4216
  invariant(isStructurallyValidLanguageTag(tag), "malformed language tag", RangeError);
4217
+ tag = Intl.getCanonicalLocales(tag)[0];
4201
4218
  const language = GetOption(options, "language", "string", void 0, void 0);
4202
4219
  if (language !== void 0) invariant(isUnicodeLanguageSubtag(language), "Malformed unicode_language_subtag", RangeError);
4203
4220
  const script = GetOption(options, "script", "string", void 0, void 0);
4204
4221
  if (script !== void 0) invariant(isUnicodeScriptSubtag(script), "Malformed unicode_script_subtag", RangeError);
4205
4222
  const region = GetOption(options, "region", "string", void 0, void 0);
4206
4223
  if (region !== void 0) invariant(isUnicodeRegionSubtag(region), "Malformed unicode_region_subtag", RangeError);
4224
+ const variants = GetOption(options, "variants", "string", void 0, void 0);
4207
4225
  const languageId = parseUnicodeLanguageId(tag);
4226
+ if (variants !== void 0) {
4227
+ const subtags = variants.replace(/[A-Z]/g, (character) => character.toLowerCase()).split("-");
4228
+ if (subtags.some((variant) => !isUnicodeVariantSubtag(variant)) || new Set(subtags).size !== subtags.length) throw new RangeError("Malformed unicode_variant_subtag");
4229
+ languageId.variants = subtags;
4230
+ }
4208
4231
  if (language !== void 0) languageId.lang = language;
4209
4232
  if (script !== void 0) languageId.script = script;
4210
4233
  if (region !== void 0) languageId.region = region;
@@ -4246,6 +4269,8 @@ function applyUnicodeExtensionToTag(tag, options, relevantExtensionKeys) {
4246
4269
  });
4247
4270
  } else unicodeExtension.keywords = keywords;
4248
4271
  result.locale = Intl.getCanonicalLocales(emitUnicodeLocaleId(ast))[0];
4272
+ const canonicalExtension = parseUnicodeLocaleId(result.locale).extensions.find((extension) => extension.type === "u");
4273
+ for (const key of relevantExtensionKeys) result[key] = canonicalExtension?.keywords.find((keyword) => keyword[0] === key)?.[1];
4249
4274
  return result;
4250
4275
  }
4251
4276
  function mergeUnicodeLanguageId(lang, script, region, variants = [], replacement) {
@@ -4264,49 +4289,38 @@ function mergeUnicodeLanguageId(lang, script, region, variants = [], replacement
4264
4289
  }
4265
4290
  function addLikelySubtags(tag) {
4266
4291
  const ast = parseUnicodeLocaleId(tag);
4267
- const { lang, script, region, variants } = ast.lang;
4268
- if (script && region) {
4269
- const match = likelySubtags[emitUnicodeLanguageId({
4292
+ const { lang, variants } = ast.lang;
4293
+ const script = ast.lang.script === "Zzzz" ? void 0 : ast.lang.script;
4294
+ const region = ast.lang.region === "ZZ" ? void 0 : ast.lang.region;
4295
+ if (lang !== "und" && script && region) return tag;
4296
+ for (const candidate of [
4297
+ {
4270
4298
  lang,
4271
4299
  script,
4272
4300
  region,
4273
4301
  variants: []
4274
- })];
4275
- if (match) {
4276
- ast.lang = mergeUnicodeLanguageId(void 0, void 0, void 0, variants, parseUnicodeLanguageId(match));
4277
- return emitUnicodeLocaleId(ast);
4278
- }
4279
- }
4280
- if (script) {
4281
- const match = likelySubtags[emitUnicodeLanguageId({
4302
+ },
4303
+ {
4282
4304
  lang,
4283
4305
  script,
4284
4306
  variants: []
4285
- })];
4286
- if (match) {
4287
- ast.lang = mergeUnicodeLanguageId(void 0, void 0, region, variants, parseUnicodeLanguageId(match));
4288
- return emitUnicodeLocaleId(ast);
4289
- }
4290
- }
4291
- if (region) {
4292
- const match = likelySubtags[emitUnicodeLanguageId({
4307
+ },
4308
+ {
4293
4309
  lang,
4294
4310
  region,
4295
4311
  variants: []
4296
- })];
4297
- if (match) {
4298
- ast.lang = mergeUnicodeLanguageId(void 0, script, void 0, variants, parseUnicodeLanguageId(match));
4299
- return emitUnicodeLocaleId(ast);
4312
+ },
4313
+ {
4314
+ lang,
4315
+ variants: []
4300
4316
  }
4317
+ ]) {
4318
+ const match = likelySubtags[emitUnicodeLanguageId(candidate)];
4319
+ if (!match) continue;
4320
+ ast.lang = mergeUnicodeLanguageId(lang, script, region, variants, parseUnicodeLanguageId(match));
4321
+ return emitUnicodeLocaleId(ast);
4301
4322
  }
4302
- const match = likelySubtags[lang] || likelySubtags[emitUnicodeLanguageId({
4303
- lang: "und",
4304
- script,
4305
- variants: []
4306
- })];
4307
- if (!match) throw new Error(`No match for addLikelySubtags`);
4308
- ast.lang = mergeUnicodeLanguageId(void 0, script, region, variants, parseUnicodeLanguageId(match));
4309
- return emitUnicodeLocaleId(ast);
4323
+ return tag;
4310
4324
  }
4311
4325
  /**
4312
4326
  * From: https://github.com/unicode-org/icu/blob/4231ca5be053a22a1be24eb891817458c97db709/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java#L2395
@@ -4315,11 +4329,11 @@ function addLikelySubtags(tag) {
4315
4329
  function removeLikelySubtags(tag) {
4316
4330
  let maxLocale = addLikelySubtags(tag);
4317
4331
  if (!maxLocale) return tag;
4332
+ const ast = parseUnicodeLocaleId(maxLocale);
4318
4333
  maxLocale = emitUnicodeLanguageId({
4319
4334
  ...parseUnicodeLanguageId(maxLocale),
4320
4335
  variants: []
4321
4336
  });
4322
- const ast = parseUnicodeLocaleId(tag);
4323
4337
  const { lang: { lang, script, region, variants } } = ast;
4324
4338
  if (addLikelySubtags(emitUnicodeLanguageId({
4325
4339
  lang,
@@ -4348,7 +4362,7 @@ function removeLikelySubtags(tag) {
4348
4362
  lang: mergeUnicodeLanguageId(lang, script, void 0, variants)
4349
4363
  });
4350
4364
  }
4351
- return tag;
4365
+ return emitUnicodeLocaleId(ast);
4352
4366
  }
4353
4367
  function createArrayFromListOrRestricted(list, restricted) {
4354
4368
  let result = list;
@@ -4359,13 +4373,19 @@ function calendarsOfLocale(loc) {
4359
4373
  const locInternalSlots = getInternalSlots(loc);
4360
4374
  const restricted = locInternalSlots.calendar;
4361
4375
  const locale = locInternalSlots.locale;
4362
- let region;
4363
- if (locale !== "root") region = loc.maximize().region;
4364
- return createArrayFromListOrRestricted(getCalendarPreferenceDataForRegion(region), restricted);
4376
+ const { region, regionOverride } = regionPreference(loc);
4377
+ return createArrayFromListOrRestricted(getCalendarPreferenceDataForRegion(region, regionOverride, parseUnicodeLanguageId(locale).lang), restricted);
4365
4378
  }
4366
4379
  function collationsOfLocale(loc) {
4367
- const restricted = getInternalSlots(loc).collation;
4368
- const supportedCollations = supportedValuesOf("collation").filter((co) => co !== "standard" && co !== "search");
4380
+ const locInternalSlots = getInternalSlots(loc);
4381
+ const restricted = locInternalSlots.collation;
4382
+ if (restricted !== void 0) return [restricted];
4383
+ const locale = locInternalSlots.locale;
4384
+ if (!Intl.Collator.supportedLocalesOf([locale], { localeMatcher: "lookup" }).length) return ["emoji", "eor"];
4385
+ const supportedCollations = supportedValuesOf("collation").filter((co) => co !== "standard" && co !== "search" && new Intl.Collator(locale, {
4386
+ collation: co,
4387
+ localeMatcher: "lookup"
4388
+ }).resolvedOptions().collation === co);
4369
4389
  supportedCollations.sort();
4370
4390
  return createArrayFromListOrRestricted(supportedCollations, restricted);
4371
4391
  }
@@ -4373,9 +4393,8 @@ function hourCyclesOfLocale(loc) {
4373
4393
  const locInternalSlots = getInternalSlots(loc);
4374
4394
  const restricted = locInternalSlots.hourCycle;
4375
4395
  const locale = locInternalSlots.locale;
4376
- let region;
4377
- if (locale !== "root") region = loc.maximize().region;
4378
- return createArrayFromListOrRestricted(getHourCyclesPreferenceDataForLocaleOrRegion(locale, region), restricted);
4396
+ const { region, regionOverride } = regionPreference(loc);
4397
+ return createArrayFromListOrRestricted(getHourCyclesPreferenceDataForLocaleOrRegion(parseUnicodeLanguageId(locale).lang, region, regionOverride), restricted);
4379
4398
  }
4380
4399
  function numberingSystemsOfLocale(loc) {
4381
4400
  const locInternalSlots = getInternalSlots(loc);
@@ -4399,13 +4418,25 @@ function translateCharacterOrder(order) {
4399
4418
  return "ltr";
4400
4419
  }
4401
4420
  function characterDirectionOfLocale(loc) {
4402
- return translateCharacterOrder(characterOrders[loc.minimize().toString()]);
4421
+ const locale = loc.minimize().toString();
4422
+ return translateCharacterOrder(characterOrders[locale]);
4403
4423
  }
4404
- function weekInfoOfLocale(loc) {
4424
+ function regionPreference(loc) {
4405
4425
  const locale = getInternalSlots(loc).locale;
4406
- let region;
4407
- if (locale !== "root") region = loc.maximize().region;
4408
- return getWeekDataForRegion(region);
4426
+ const ast = parseUnicodeLocaleId(locale);
4427
+ const extension = ast.extensions.find((ext) => ext.type === "u");
4428
+ const subdivisionRegion = (key) => {
4429
+ const match = (extension?.keywords.find((entry) => entry[0] === key)?.[1])?.match(/^([a-z]{2}|[0-9]{3})[a-z0-9]{1,4}$/i);
4430
+ return match ? new Locale(`und-${match[1]}`).region : void 0;
4431
+ };
4432
+ return {
4433
+ region: ast.lang.region || subdivisionRegion("sd") || parseUnicodeLanguageId(addLikelySubtags(locale)).region || "001",
4434
+ regionOverride: subdivisionRegion("rg")
4435
+ };
4436
+ }
4437
+ function weekInfoOfLocale(loc) {
4438
+ const { region, regionOverride } = regionPreference(loc);
4439
+ return getWeekDataForRegion(region, regionOverride);
4409
4440
  }
4410
4441
  const TABLE_1 = [
4411
4442
  "sun",
@@ -4417,7 +4448,7 @@ const TABLE_1 = [
4417
4448
  "sat"
4418
4449
  ];
4419
4450
  function weekdayToString(fw) {
4420
- return TABLE_1[+fw];
4451
+ return /^[0-7]$/.test(fw) ? TABLE_1[Number(fw) % 7] : fw;
4421
4452
  }
4422
4453
  var Locale = class Locale {
4423
4454
  constructor(tag, opts) {
@@ -4434,30 +4465,30 @@ var Locale = class Locale {
4434
4465
  if (relevantExtensionKeys.indexOf("kf") > -1) internalSlotsList.push("caseFirst");
4435
4466
  if (relevantExtensionKeys.indexOf("kn") > -1) internalSlotsList.push("numeric");
4436
4467
  if (tag === void 0) throw new TypeError("First argument to Intl.Locale constructor can't be empty or missing");
4437
- if (typeof tag !== "string" && typeof tag !== "object") throw new TypeError("tag must be a string or object");
4468
+ if (tag === null || typeof tag !== "string" && typeof tag !== "object" && typeof tag !== "function") throw new TypeError("tag must be a string or object");
4438
4469
  let tagInternalSlots;
4439
- if (typeof tag === "object" && (tagInternalSlots = getInternalSlots(tag)) && HasOwnProperty(tagInternalSlots, "initializedLocale")) tag = tagInternalSlots.locale;
4440
- else tag = tag.toString();
4470
+ if (typeof tag === "object" && (tagInternalSlots = getInternalSlotsIfPresent(tag)) && HasOwnProperty(tagInternalSlots, "initializedLocale")) tag = tagInternalSlots.locale;
4471
+ else tag = ToString(tag);
4441
4472
  let internalSlots = getInternalSlots(this, internalSlotsList);
4442
4473
  let options = CoerceOptionsToObject(opts);
4443
4474
  tag = applyOptionsToTag(tag, options);
4444
4475
  const opt = Object.create(null);
4445
4476
  const calendar = GetOption(options, "calendar", "string", void 0, void 0);
4446
4477
  if (calendar !== void 0) {
4447
- if (!UNICODE_TYPE_REGEX.test(calendar)) throw new RangeError("invalid calendar");
4478
+ if (!IsUnicodeLocaleIdentifierType(calendar)) throw new RangeError("invalid calendar");
4448
4479
  }
4449
4480
  opt.ca = calendar;
4450
4481
  const collation = GetOption(options, "collation", "string", void 0, void 0);
4451
4482
  if (collation !== void 0) {
4452
- if (!UNICODE_TYPE_REGEX.test(collation)) throw new RangeError("invalid collation");
4483
+ if (!IsUnicodeLocaleIdentifierType(collation)) throw new RangeError("invalid collation");
4453
4484
  }
4454
4485
  opt.co = collation;
4455
4486
  let fw = GetOption(options, "firstDayOfWeek", "string", void 0, void 0);
4456
4487
  if (fw !== void 0) {
4457
4488
  fw = weekdayToString(fw);
4458
- if (!ALPHANUM_3_8.test(fw)) throw new RangeError("Invalid firstDayOfWeek");
4489
+ if (!IsUnicodeLocaleIdentifierType(fw)) throw new RangeError("Invalid firstDayOfWeek");
4459
4490
  }
4460
- opt.fw = fw;
4491
+ opt.fw = fw?.toLowerCase();
4461
4492
  opt.hc = GetOption(options, "hourCycle", "string", [
4462
4493
  "h11",
4463
4494
  "h12",
@@ -4475,7 +4506,7 @@ var Locale = class Locale {
4475
4506
  opt.kn = kn;
4476
4507
  const numberingSystem = GetOption(options, "numberingSystem", "string", void 0, void 0);
4477
4508
  if (numberingSystem !== void 0) {
4478
- if (!UNICODE_TYPE_REGEX.test(numberingSystem)) throw new RangeError("Invalid numberingSystem");
4509
+ if (!IsUnicodeLocaleIdentifierType(numberingSystem)) throw new RangeError("Invalid numberingSystem");
4479
4510
  }
4480
4511
  opt.nu = numberingSystem;
4481
4512
  const r = applyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys);
@@ -4485,7 +4516,7 @@ var Locale = class Locale {
4485
4516
  internalSlots.firstDayOfWeek = r.fw;
4486
4517
  internalSlots.hourCycle = r.hc;
4487
4518
  if (relevantExtensionKeys.indexOf("kf") > -1) internalSlots.caseFirst = r.kf;
4488
- if (relevantExtensionKeys.indexOf("kn") > -1) internalSlots.numeric = SameValue(r.kn, "true");
4519
+ if (relevantExtensionKeys.indexOf("kn") > -1) internalSlots.numeric = r.kn === "" || SameValue(r.kn, "true");
4489
4520
  internalSlots.numberingSystem = r.nu;
4490
4521
  }
4491
4522
  /**
@@ -4494,7 +4525,8 @@ var Locale = class Locale {
4494
4525
  maximize() {
4495
4526
  const locale = getInternalSlots(this).locale;
4496
4527
  try {
4497
- return new Locale(addLikelySubtags(locale));
4528
+ const maximizedLocale = addLikelySubtags(locale);
4529
+ return new Locale(maximizedLocale);
4498
4530
  } catch {
4499
4531
  return new Locale(locale);
4500
4532
  }
@@ -4505,13 +4537,16 @@ var Locale = class Locale {
4505
4537
  minimize() {
4506
4538
  const locale = getInternalSlots(this).locale;
4507
4539
  try {
4508
- return new Locale(removeLikelySubtags(locale));
4540
+ const minimizedLocale = removeLikelySubtags(locale);
4541
+ return new Locale(minimizedLocale);
4509
4542
  } catch {
4510
4543
  return new Locale(locale);
4511
4544
  }
4512
4545
  }
4513
4546
  toString() {
4514
- return getInternalSlots(this).locale;
4547
+ const slots = getInternalSlots(this);
4548
+ if (!HasOwnProperty(slots, "initializedLocale")) throw new TypeError("Error uninitialized locale");
4549
+ return slots.locale;
4515
4550
  }
4516
4551
  get baseName() {
4517
4552
  const locale = getInternalSlots(this).locale;
@@ -4625,7 +4660,9 @@ var Locale = class Locale {
4625
4660
  }
4626
4661
  /**
4627
4662
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo
4628
- * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getWeekInfo
4663
+ * ECMA-402 §15.3.22 Intl.Locale.prototype.getWeekInfo, steps 3–7.
4664
+ * https://tc39.es/ecma402/#sec-Intl.Locale.prototype.getWeekInfo
4665
+ * https://github.com/tc39/ecma402/blob/b1c961988b9a07894b1dc3dc2b5626ea48387d61/spec/locale.html#L420-L424
4629
4666
  */
4630
4667
  getWeekInfo() {
4631
4668
  const info = Object.create(Object.prototype);
@@ -4634,10 +4671,10 @@ var Locale = class Locale {
4634
4671
  const wi = weekInfoOfLocale(this);
4635
4672
  const we = wi.weekend;
4636
4673
  createDataProperty(info, "firstDay", wi.firstDay);
4637
- createDataProperty(info, "weekend", we);
4638
- createDataProperty(info, "minimalDays", wi.minimalDays);
4674
+ createDataProperty(info, "weekend", [...we]);
4639
4675
  const fw = internalSlots.firstDayOfWeek;
4640
- if (fw !== void 0) info.firstDay = fw;
4676
+ const day = TABLE_1.indexOf(fw);
4677
+ if (day !== -1) info.firstDay = day || 7;
4641
4678
  return info;
4642
4679
  }
4643
4680
  static {