@formatjs/intl-getcanonicallocales 3.3.1 → 3.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-getcanonicallocales",
3
- "version": "3.3.1",
3
+ "version": "3.4.1",
4
4
  "description": "Intl.getCanonicalLocales polyfill",
5
5
  "keywords": [
6
6
  "ecma402",
package/polyfill-force.js CHANGED
@@ -1,3 +1,84 @@
1
+ // packages/ecma262-abstract/IsObject.js
2
+ /** Includes browser host objects such as document.all. */
3
+ function IsObject(value) {
4
+ return value !== null && (typeof value === "object" || typeof value === "function" || typeof value === "undefined" && value !== void 0);
5
+ }
6
+ // packages/ecma262-abstract/intrinsics.js
7
+ const objectFrom = Object;
8
+ const mathMin = Math.min;
9
+ const mathMax = Math.max;
10
+ const mathTrunc = Math.trunc;
11
+ Number.isInteger;
12
+ Number.isFinite;
13
+ Number.isSafeInteger;
14
+ const TypeErrorConstructor$1 = TypeError;
15
+ const arrayApply = Reflect.apply;
16
+ const every = Array.prototype.every;
17
+ Array.prototype.some;
18
+ function arrayEvery(values, predicate) {
19
+ return arrayApply(every, values, [predicate]);
20
+ }
21
+ const includes = Array.prototype.includes;
22
+ const indexOf = Array.prototype.indexOf;
23
+ function arrayIncludes(values, search) {
24
+ return arrayApply(includes, values, [search]);
25
+ }
26
+ function arrayIndexOf(values, search) {
27
+ return arrayApply(indexOf, values, [search]);
28
+ }
29
+ // packages/intl-getcanonicallocales/locale-brand.ts
30
+ const apply$1 = Reflect.apply;
31
+ const defineProperty$2 = Object.defineProperty;
32
+ let readers;
33
+ function addLocaleBrandReader(read) {
34
+ if (typeof read !== "function") throw new TypeErrorConstructor$1("Locale brand reader must be callable");
35
+ for (let node = readers; node; node = node.next) if (node.read === read) return;
36
+ readers = {
37
+ read,
38
+ next: readers
39
+ };
40
+ }
41
+ function getLocaleBrandReaders() {
42
+ const result = [];
43
+ for (let node = readers; node; node = node.next) defineProperty$2(result, result.length, {
44
+ value: node.read,
45
+ writable: true,
46
+ enumerable: true,
47
+ configurable: true
48
+ });
49
+ return result;
50
+ }
51
+ function localeString(value) {
52
+ if (!IsObject(value)) return void 0;
53
+ for (let node = readers; node; node = node.next) {
54
+ const tag = node.read(value);
55
+ if (typeof tag === "string") return tag;
56
+ }
57
+ }
58
+ const LocaleConstructor = typeof Intl === "undefined" ? void 0 : Intl.Locale;
59
+ const snapshot = LocaleConstructor?.__getLocaleBrandReaders;
60
+ if (typeof snapshot === "function") {
61
+ const known = apply$1(snapshot, LocaleConstructor, []);
62
+ for (let index = 0; index < known.length; index++) addLocaleBrandReader(known[index]);
63
+ } else {
64
+ const nativeToString = LocaleConstructor?.prototype.toString;
65
+ if (typeof nativeToString === "function") addLocaleBrandReader((value) => {
66
+ try {
67
+ const tag = apply$1(nativeToString, value, []);
68
+ return typeof tag === "string" ? tag : void 0;
69
+ } catch {
70
+ return;
71
+ }
72
+ });
73
+ }
74
+ // packages/ecma262-abstract/ToObject.js
75
+ /**
76
+ * https://tc39.es/ecma262/#sec-toobject
77
+ */
78
+ function ToObject(arg) {
79
+ if (arg === void 0 || arg === null) throw new TypeErrorConstructor$1("undefined/null cannot be converted to object");
80
+ return objectFrom(arg);
81
+ }
1
82
  // packages/intl-getcanonicallocales/appendToList.ts
2
83
  function appendToList(list, ...values) {
3
84
  for (const value of values) Object.defineProperty(list, list.length, {
@@ -8,12 +89,14 @@ function appendToList(list, ...values) {
8
89
  });
9
90
  }
10
91
  // packages/ecma262-abstract/ToString.js
92
+ const StringConstructor = String;
93
+ const TypeErrorConstructor = TypeError;
11
94
  /**
12
95
  * https://tc39.es/ecma262/#sec-tostring
13
96
  */
14
97
  function ToString(o) {
15
- if (typeof o === "symbol") throw TypeError("Cannot convert a Symbol value to a string");
16
- return String(o);
98
+ if (typeof o === "symbol") throw TypeErrorConstructor("Cannot convert a Symbol value to a string");
99
+ return StringConstructor(o);
17
100
  }
18
101
  // node_modules/.aspect_rules_js/@formatjs_generated+cldr.core@0.0.0/node_modules/@formatjs_generated/cldr.core/aliases.js
19
102
  const subdivisionAlias = {
@@ -9486,11 +9569,13 @@ function compareKV(t1, t2) {
9486
9569
  return t1[0] < t2[0] ? -1 : t1[0] > t2[0] ? 1 : 0;
9487
9570
  }
9488
9571
  function compareExtension(e1, e2) {
9572
+ if (e1.type === "x") return e2.type === "x" ? 0 : 1;
9573
+ if (e2.type === "x") return -1;
9489
9574
  return e1.type < e2.type ? -1 : e1.type > e2.type ? 1 : 0;
9490
9575
  }
9491
9576
  function mergeVariants(v1, v2) {
9492
9577
  const result = [...v1];
9493
- for (const v of v2) if (v1.indexOf(v) < 0) appendToList(result, v);
9578
+ for (const v of v2) if (arrayIndexOf(v1, v) < 0) appendToList(result, v);
9494
9579
  return result;
9495
9580
  }
9496
9581
  function compareLanguageAliasRules(a, b) {
@@ -9536,7 +9621,7 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
9536
9621
  unicodeLanguageId.variants = unicodeLanguageId.variants.map((v) => v.toLowerCase());
9537
9622
  const original = emitUnicodeLanguageId(unicodeLanguageId);
9538
9623
  let finalLangAst = unicodeLanguageId;
9539
- const matches = ({ type }) => (!type.script || type.script === finalLangAst.script) && (!type.region || type.region === finalLangAst.region) && type.variants.every((variant) => finalLangAst.variants.includes(variant));
9624
+ const matches = ({ type }) => (!type.script || type.script === finalLangAst.script) && (!type.region || type.region === finalLangAst.region) && arrayEvery(type.variants, (variant) => arrayIncludes(finalLangAst.variants, variant));
9540
9625
  const languageRule = languageAliasRules[finalLangAst.lang]?.find(matches);
9541
9626
  const undRule = finalLangAst.lang === "und" ? void 0 : languageAliasRules.und?.find(matches);
9542
9627
  const matched = !languageRule ? undRule : !undRule ? languageRule : compareLanguageAliasRules(languageRule, undRule) <= 0 ? languageRule : undRule;
@@ -9546,7 +9631,7 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
9546
9631
  lang: type.lang !== "und" || finalLangAst.lang === "und" ? replacement.lang : finalLangAst.lang,
9547
9632
  script: type.script ? replacement.script : finalLangAst.script || replacement.script,
9548
9633
  region: type.region ? replacement.region : finalLangAst.region || replacement.region,
9549
- variants: mergeVariants(finalLangAst.variants.filter((v) => !type.variants.includes(v)), replacement.variants)
9634
+ variants: mergeVariants(finalLangAst.variants.filter((v) => !arrayIncludes(type.variants, v)), replacement.variants)
9550
9635
  };
9551
9636
  return canonicalizeUnicodeLanguageId(finalLangAst);
9552
9637
  }
@@ -9564,7 +9649,7 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
9564
9649
  })] || likelySubtags[finalLangAst.lang];
9565
9650
  if (likelySubtag) {
9566
9651
  const { region: likelyRegion } = parseUnicodeLanguageId(likelySubtag.split("-"));
9567
- if (likelyRegion && regions.indexOf(likelyRegion) > -1) replacedRegion = likelyRegion;
9652
+ if (likelyRegion && arrayIndexOf(regions, likelyRegion) > -1) replacedRegion = likelyRegion;
9568
9653
  }
9569
9654
  }
9570
9655
  if (replacedRegion) finalLangAst.region = replacedRegion;
@@ -9613,15 +9698,6 @@ function CanonicalizeUnicodeLocaleId(locale) {
9613
9698
  return locale;
9614
9699
  }
9615
9700
  // packages/intl-getcanonicallocales/index.ts
9616
- const originalLocaleToString = typeof Intl !== "undefined" ? Intl.Locale?.prototype.toString : void 0;
9617
- function localeString(value) {
9618
- if (value === null || typeof value !== "object" && typeof value !== "function") return void 0;
9619
- const currentLocaleToString = typeof Intl !== "undefined" ? Intl.Locale?.prototype.toString : void 0;
9620
- for (const method of [originalLocaleToString, currentLocaleToString]) if (method) try {
9621
- const tag = method.call(value);
9622
- if (typeof tag === "string") return tag;
9623
- } catch {}
9624
- }
9625
9701
  /**
9626
9702
  * ECMA-402 §9.2.1 CanonicalizeLocaleList, steps 3–7.
9627
9703
  * https://tc39.es/ecma402/#sec-canonicalizelocalelist
@@ -9629,29 +9705,36 @@ function localeString(value) {
9629
9705
  */
9630
9706
  function CanonicalizeLocaleList(locales) {
9631
9707
  if (locales === void 0) return [];
9632
- if (locales === null) throw new TypeError("Cannot convert null to an object");
9708
+ if (locales === null) throw new TypeErrorConstructor$1("Cannot convert null to an object");
9633
9709
  const singleLocale = localeString(locales);
9634
- const list = typeof locales === "string" ? [locales] : singleLocale !== void 0 ? [singleLocale] : Object(locales);
9710
+ const list = typeof locales === "string" ? [locales] : singleLocale !== void 0 ? [singleLocale] : ToObject(locales);
9635
9711
  const length = +list.length;
9636
- const len = isNaN(length) ? 0 : Math.min(Math.max(Math.floor(length), 0), 9007199254740991);
9712
+ const len = length !== length ? 0 : mathMin(mathMax(mathTrunc(length), 0), 9007199254740991);
9637
9713
  const seen = [];
9638
9714
  for (let k = 0; k < len; k++) {
9639
9715
  if (!(k in list)) continue;
9640
9716
  const value = list[k];
9641
- if (value === null || ![
9642
- "string",
9643
- "object",
9644
- "function"
9645
- ].includes(typeof value)) throw new TypeError("Locale list entries must be strings or objects");
9717
+ if (typeof value !== "string" && !IsObject(value)) throw new TypeErrorConstructor$1("Locale list entries must be strings or objects");
9646
9718
  const canonicalizedTag = emitUnicodeLocaleId(CanonicalizeUnicodeLocaleId(parseUnicodeLocaleId(localeString(value) ?? ToString(value))));
9647
- if (seen.indexOf(canonicalizedTag) < 0) appendToList(seen, canonicalizedTag);
9719
+ if (arrayIndexOf(seen, canonicalizedTag) < 0) appendToList(seen, canonicalizedTag);
9648
9720
  }
9649
9721
  return seen;
9650
9722
  }
9651
9723
  function getCanonicalLocales(locales) {
9652
9724
  return CanonicalizeLocaleList(locales);
9653
9725
  }
9726
+ Object.defineProperties(getCanonicalLocales, {
9727
+ __addLocaleBrandReader: { value: addLocaleBrandReader },
9728
+ __getLocaleBrandReaders: { value: getLocaleBrandReaders }
9729
+ });
9654
9730
  // node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js
9731
+ const apply = Reflect.apply;
9732
+ const bind = Function.prototype.bind;
9733
+ const slice = Array.prototype.slice;
9734
+ const stringify = JSON.stringify;
9735
+ const create = Object.create;
9736
+ const defineProperty$1 = Object.defineProperty;
9737
+ const setPrototypeOf = Object.setPrototypeOf;
9655
9738
  function memoize(fn, options) {
9656
9739
  const cache = options && options.cache ? options.cache : cacheDefault;
9657
9740
  const serializer = options && options.serializer ? options.serializer : serializerDefault;
@@ -9667,23 +9750,29 @@ function monadic(fn, cache, serializer, arg) {
9667
9750
  const cacheKey = isPrimitive(arg) ? arg : serializer(arg);
9668
9751
  let computedValue = cache.get(cacheKey);
9669
9752
  if (typeof computedValue === "undefined") {
9670
- computedValue = fn.call(this, arg);
9753
+ computedValue = apply(fn, this, [arg]);
9671
9754
  cache.set(cacheKey, computedValue);
9672
9755
  }
9673
9756
  return computedValue;
9674
9757
  }
9675
9758
  function variadic(fn, cache, serializer) {
9676
- const args = Array.prototype.slice.call(arguments, 3);
9759
+ const args = apply(slice, arguments, [3]);
9760
+ if (serializer === serializerDefault) setPrototypeOf(args, null);
9677
9761
  const cacheKey = serializer(args);
9678
9762
  let computedValue = cache.get(cacheKey);
9679
9763
  if (typeof computedValue === "undefined") {
9680
- computedValue = fn.apply(this, args);
9764
+ computedValue = apply(fn, this, args);
9681
9765
  cache.set(cacheKey, computedValue);
9682
9766
  }
9683
9767
  return computedValue;
9684
9768
  }
9685
9769
  function assemble(fn, context, strategy, cache, serialize) {
9686
- return strategy.bind(context, fn, cache, serialize);
9770
+ return apply(bind, strategy, [
9771
+ context,
9772
+ fn,
9773
+ cache,
9774
+ serialize
9775
+ ]);
9687
9776
  }
9688
9777
  function strategyDefault(fn, options) {
9689
9778
  const strategy = fn.length === 1 ? monadic : variadic;
@@ -9696,11 +9785,18 @@ function strategyMonadic(fn, options) {
9696
9785
  return assemble(fn, this, monadic, options.cache.create(), options.serializer);
9697
9786
  }
9698
9787
  const serializerDefault = function() {
9699
- return JSON.stringify(arguments);
9788
+ setPrototypeOf(arguments, null);
9789
+ return stringify(arguments);
9700
9790
  };
9701
9791
  var ObjectWithoutPrototypeCache = class {
9702
9792
  constructor() {
9703
- this.cache = Object.create(null);
9793
+ defineProperty$1(this, "cache", {
9794
+ __proto__: null,
9795
+ value: create(null),
9796
+ writable: true,
9797
+ enumerable: true,
9798
+ configurable: true
9799
+ });
9704
9800
  }
9705
9801
  get(key) {
9706
9802
  return this.cache[key];
@@ -9732,11 +9828,56 @@ function ensureIntl() {
9732
9828
  writable: true,
9733
9829
  value: {}
9734
9830
  });
9831
+ if (providerIntl === void 0) providerIntl = Intl;
9735
9832
  return Intl;
9736
9833
  }
9737
9834
  memoize((...args) => new Intl.NumberFormat(...args), { strategy: strategies.variadic });
9738
9835
  memoize((...args) => new Intl.PluralRules(...args), { strategy: strategies.variadic });
9739
9836
  memoize((...args) => new Intl.ListFormat(...args), { strategy: strategies.variadic });
9837
+ const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
9838
+ strategies.variadic;
9839
+ let providerIntl = globalThis.Intl;
9840
+ function ownIntlProvider(name) {
9841
+ const descriptor = providerIntl && getOwnPropertyDescriptor(providerIntl, name);
9842
+ return (descriptor && getOwnPropertyDescriptor(descriptor, "value"))?.value;
9843
+ }
9844
+ let numberFormatProvider = ownIntlProvider("NumberFormat");
9845
+ let listFormatProvider = ownIntlProvider("ListFormat");
9846
+ const getFormatterPrototype = Object.getPrototypeOf;
9847
+ const formatterPartsMethods = /* @__PURE__ */ new WeakMap();
9848
+ const formatterPartsOwners = /* @__PURE__ */ new WeakMap();
9849
+ const getPartsMethod = formatterPartsMethods.get.bind(formatterPartsMethods);
9850
+ const setPartsMethod = formatterPartsMethods.set.bind(formatterPartsMethods);
9851
+ const getPartsOwner = formatterPartsOwners.get.bind(formatterPartsOwners);
9852
+ const setPartsOwner = formatterPartsOwners.set.bind(formatterPartsOwners);
9853
+ function findFormatterPartsMethod(Constructor) {
9854
+ const cached = getPartsMethod(Constructor);
9855
+ if (cached) return cached;
9856
+ let prototype = getOwnPropertyDescriptor(Constructor, "prototype")?.value;
9857
+ while (prototype != null) {
9858
+ const inherited = getPartsOwner(prototype);
9859
+ if (inherited) {
9860
+ setPartsMethod(Constructor, inherited);
9861
+ return inherited;
9862
+ }
9863
+ const descriptor = getOwnPropertyDescriptor(prototype, "formatToParts");
9864
+ const value = descriptor && getOwnPropertyDescriptor(descriptor, "value");
9865
+ if (value && typeof value.value === "function") {
9866
+ setPartsMethod(Constructor, value.value);
9867
+ setPartsOwner(prototype, value.value);
9868
+ return value.value;
9869
+ }
9870
+ prototype = getFormatterPrototype(prototype);
9871
+ }
9872
+ }
9873
+ if (typeof numberFormatProvider === "function") findFormatterPartsMethod(numberFormatProvider);
9874
+ if (typeof listFormatProvider === "function") findFormatterPartsMethod(listFormatProvider);
9875
+ const numberFormatMemoizers = /* @__PURE__ */ new WeakMap();
9876
+ numberFormatMemoizers.get.bind(numberFormatMemoizers);
9877
+ numberFormatMemoizers.set.bind(numberFormatMemoizers);
9878
+ const listFormatMemoizers = /* @__PURE__ */ new WeakMap();
9879
+ listFormatMemoizers.get.bind(listFormatMemoizers);
9880
+ listFormatMemoizers.set.bind(listFormatMemoizers);
9740
9881
  defineProperty(ensureIntl(), "getCanonicalLocales", { value: getCanonicalLocales });
9741
9882
 
9742
9883
  //# sourceMappingURL=polyfill-force.js.map