@formatjs/intl-getcanonicallocales 3.4.0 → 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.4.0",
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 = {
@@ -9492,7 +9575,7 @@ function compareExtension(e1, e2) {
9492
9575
  }
9493
9576
  function mergeVariants(v1, v2) {
9494
9577
  const result = [...v1];
9495
- 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);
9496
9579
  return result;
9497
9580
  }
9498
9581
  function compareLanguageAliasRules(a, b) {
@@ -9538,7 +9621,7 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
9538
9621
  unicodeLanguageId.variants = unicodeLanguageId.variants.map((v) => v.toLowerCase());
9539
9622
  const original = emitUnicodeLanguageId(unicodeLanguageId);
9540
9623
  let finalLangAst = unicodeLanguageId;
9541
- 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));
9542
9625
  const languageRule = languageAliasRules[finalLangAst.lang]?.find(matches);
9543
9626
  const undRule = finalLangAst.lang === "und" ? void 0 : languageAliasRules.und?.find(matches);
9544
9627
  const matched = !languageRule ? undRule : !undRule ? languageRule : compareLanguageAliasRules(languageRule, undRule) <= 0 ? languageRule : undRule;
@@ -9548,7 +9631,7 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
9548
9631
  lang: type.lang !== "und" || finalLangAst.lang === "und" ? replacement.lang : finalLangAst.lang,
9549
9632
  script: type.script ? replacement.script : finalLangAst.script || replacement.script,
9550
9633
  region: type.region ? replacement.region : finalLangAst.region || replacement.region,
9551
- 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)
9552
9635
  };
9553
9636
  return canonicalizeUnicodeLanguageId(finalLangAst);
9554
9637
  }
@@ -9566,7 +9649,7 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
9566
9649
  })] || likelySubtags[finalLangAst.lang];
9567
9650
  if (likelySubtag) {
9568
9651
  const { region: likelyRegion } = parseUnicodeLanguageId(likelySubtag.split("-"));
9569
- if (likelyRegion && regions.indexOf(likelyRegion) > -1) replacedRegion = likelyRegion;
9652
+ if (likelyRegion && arrayIndexOf(regions, likelyRegion) > -1) replacedRegion = likelyRegion;
9570
9653
  }
9571
9654
  }
9572
9655
  if (replacedRegion) finalLangAst.region = replacedRegion;
@@ -9615,15 +9698,6 @@ function CanonicalizeUnicodeLocaleId(locale) {
9615
9698
  return locale;
9616
9699
  }
9617
9700
  // packages/intl-getcanonicallocales/index.ts
9618
- const originalLocaleToString = typeof Intl !== "undefined" ? Intl.Locale?.prototype.toString : void 0;
9619
- function localeString(value) {
9620
- if (value === null || typeof value !== "object" && typeof value !== "function") return void 0;
9621
- const currentLocaleToString = typeof Intl !== "undefined" ? Intl.Locale?.prototype.toString : void 0;
9622
- for (const method of [originalLocaleToString, currentLocaleToString]) if (method) try {
9623
- const tag = method.call(value);
9624
- if (typeof tag === "string") return tag;
9625
- } catch {}
9626
- }
9627
9701
  /**
9628
9702
  * ECMA-402 §9.2.1 CanonicalizeLocaleList, steps 3–7.
9629
9703
  * https://tc39.es/ecma402/#sec-canonicalizelocalelist
@@ -9631,29 +9705,36 @@ function localeString(value) {
9631
9705
  */
9632
9706
  function CanonicalizeLocaleList(locales) {
9633
9707
  if (locales === void 0) return [];
9634
- 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");
9635
9709
  const singleLocale = localeString(locales);
9636
- 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);
9637
9711
  const length = +list.length;
9638
- 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);
9639
9713
  const seen = [];
9640
9714
  for (let k = 0; k < len; k++) {
9641
9715
  if (!(k in list)) continue;
9642
9716
  const value = list[k];
9643
- if (value === null || ![
9644
- "string",
9645
- "object",
9646
- "function"
9647
- ].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");
9648
9718
  const canonicalizedTag = emitUnicodeLocaleId(CanonicalizeUnicodeLocaleId(parseUnicodeLocaleId(localeString(value) ?? ToString(value))));
9649
- if (seen.indexOf(canonicalizedTag) < 0) appendToList(seen, canonicalizedTag);
9719
+ if (arrayIndexOf(seen, canonicalizedTag) < 0) appendToList(seen, canonicalizedTag);
9650
9720
  }
9651
9721
  return seen;
9652
9722
  }
9653
9723
  function getCanonicalLocales(locales) {
9654
9724
  return CanonicalizeLocaleList(locales);
9655
9725
  }
9726
+ Object.defineProperties(getCanonicalLocales, {
9727
+ __addLocaleBrandReader: { value: addLocaleBrandReader },
9728
+ __getLocaleBrandReaders: { value: getLocaleBrandReaders }
9729
+ });
9656
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;
9657
9738
  function memoize(fn, options) {
9658
9739
  const cache = options && options.cache ? options.cache : cacheDefault;
9659
9740
  const serializer = options && options.serializer ? options.serializer : serializerDefault;
@@ -9669,23 +9750,29 @@ function monadic(fn, cache, serializer, arg) {
9669
9750
  const cacheKey = isPrimitive(arg) ? arg : serializer(arg);
9670
9751
  let computedValue = cache.get(cacheKey);
9671
9752
  if (typeof computedValue === "undefined") {
9672
- computedValue = fn.call(this, arg);
9753
+ computedValue = apply(fn, this, [arg]);
9673
9754
  cache.set(cacheKey, computedValue);
9674
9755
  }
9675
9756
  return computedValue;
9676
9757
  }
9677
9758
  function variadic(fn, cache, serializer) {
9678
- const args = Array.prototype.slice.call(arguments, 3);
9759
+ const args = apply(slice, arguments, [3]);
9760
+ if (serializer === serializerDefault) setPrototypeOf(args, null);
9679
9761
  const cacheKey = serializer(args);
9680
9762
  let computedValue = cache.get(cacheKey);
9681
9763
  if (typeof computedValue === "undefined") {
9682
- computedValue = fn.apply(this, args);
9764
+ computedValue = apply(fn, this, args);
9683
9765
  cache.set(cacheKey, computedValue);
9684
9766
  }
9685
9767
  return computedValue;
9686
9768
  }
9687
9769
  function assemble(fn, context, strategy, cache, serialize) {
9688
- return strategy.bind(context, fn, cache, serialize);
9770
+ return apply(bind, strategy, [
9771
+ context,
9772
+ fn,
9773
+ cache,
9774
+ serialize
9775
+ ]);
9689
9776
  }
9690
9777
  function strategyDefault(fn, options) {
9691
9778
  const strategy = fn.length === 1 ? monadic : variadic;
@@ -9698,11 +9785,18 @@ function strategyMonadic(fn, options) {
9698
9785
  return assemble(fn, this, monadic, options.cache.create(), options.serializer);
9699
9786
  }
9700
9787
  const serializerDefault = function() {
9701
- return JSON.stringify(arguments);
9788
+ setPrototypeOf(arguments, null);
9789
+ return stringify(arguments);
9702
9790
  };
9703
9791
  var ObjectWithoutPrototypeCache = class {
9704
9792
  constructor() {
9705
- 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
+ });
9706
9800
  }
9707
9801
  get(key) {
9708
9802
  return this.cache[key];
@@ -9734,11 +9828,56 @@ function ensureIntl() {
9734
9828
  writable: true,
9735
9829
  value: {}
9736
9830
  });
9831
+ if (providerIntl === void 0) providerIntl = Intl;
9737
9832
  return Intl;
9738
9833
  }
9739
9834
  memoize((...args) => new Intl.NumberFormat(...args), { strategy: strategies.variadic });
9740
9835
  memoize((...args) => new Intl.PluralRules(...args), { strategy: strategies.variadic });
9741
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);
9742
9881
  defineProperty(ensureIntl(), "getCanonicalLocales", { value: getCanonicalLocales });
9743
9882
 
9744
9883
  //# sourceMappingURL=polyfill-force.js.map