@formatjs/intl-listformat 8.0.4 → 8.0.6

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.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/polyfill.iife.js +107 -10
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formatjs/intl-listformat",
3
3
  "description": "Formats JS list in a i18n-safe way",
4
- "version": "8.0.4",
4
+ "version": "8.0.6",
5
5
  "license": "MIT",
6
6
  "author": "Long Ho <holevietlong@gmail.com>",
7
7
  "type": "module",
@@ -15,12 +15,12 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "tslib": "^2.8.0",
18
- "@formatjs/ecma402-abstract": "3.0.3",
19
- "@formatjs/intl-localematcher": "0.7.2"
18
+ "@formatjs/ecma402-abstract": "3.0.5",
19
+ "@formatjs/intl-localematcher": "0.7.3"
20
20
  },
21
21
  "devDependencies": {
22
- "@formatjs/intl-getcanonicallocales": "3.0.3",
23
- "@formatjs/intl-locale": "5.0.4"
22
+ "@formatjs/intl-getcanonicallocales": "3.0.4",
23
+ "@formatjs/intl-locale": "5.0.6"
24
24
  },
25
25
  "bugs": "https://github.com/formatjs/formatjs/issues",
26
26
  "gitHead": "a7842673d8ad205171ad7c8cb8bb2f318b427c0c",
package/polyfill.iife.js CHANGED
@@ -2690,6 +2690,11 @@
2690
2690
  }
2691
2691
  var SIMPLE_UNITS = SANCTIONED_UNITS.map(removeUnitNamespace);
2692
2692
 
2693
+ // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/decimal-cache.js
2694
+ var getPowerOf10 = memoize(function(exponent) {
2695
+ return Decimal.pow(10, exponent);
2696
+ });
2697
+
2693
2698
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/ComputeExponentForMagnitude.js
2694
2699
  Decimal.set({
2695
2700
  toExpPos: 100
@@ -6751,7 +6756,7 @@
6751
6756
  }
6752
6757
  throw new Error("No matching distance found");
6753
6758
  }
6754
- function findMatchingDistance(desired, supported) {
6759
+ function findMatchingDistanceImpl(desired, supported) {
6755
6760
  var desiredLocale = new Intl.Locale(desired).maximize();
6756
6761
  var supportedLocale = new Intl.Locale(supported).maximize();
6757
6762
  var desiredLSR = {
@@ -6793,7 +6798,26 @@
6793
6798
  }
6794
6799
  return matchingDistance;
6795
6800
  }
6801
+ var findMatchingDistance = memoize(findMatchingDistanceImpl, {
6802
+ serializer: function(args) {
6803
+ return "".concat(args[0], "|").concat(args[1]);
6804
+ }
6805
+ });
6806
+ function getFallbackCandidates(locale) {
6807
+ var candidates = [];
6808
+ var current = locale;
6809
+ while (current) {
6810
+ candidates.push(current);
6811
+ var lastDash = current.lastIndexOf("-");
6812
+ if (lastDash === -1)
6813
+ break;
6814
+ current = current.substring(0, lastDash);
6815
+ }
6816
+ return candidates;
6817
+ }
6818
+ var canonicalizedSupportedCache = /* @__PURE__ */ new WeakMap();
6796
6819
  function findBestMatch(requestedLocales, supportedLocales2, threshold) {
6820
+ var _a;
6797
6821
  if (threshold === void 0) {
6798
6822
  threshold = DEFAULT_MATCHING_THRESHOLD;
6799
6823
  }
@@ -6802,17 +6826,84 @@
6802
6826
  matchedDesiredLocale: "",
6803
6827
  distances: {}
6804
6828
  };
6805
- requestedLocales.forEach(function(desired, i) {
6806
- if (!result.distances[desired]) {
6807
- result.distances[desired] = {};
6808
- }
6809
- supportedLocales2.forEach(function(supported) {
6810
- var distance = findMatchingDistance(desired, supported) + 0 + i * 40;
6811
- result.distances[desired][supported] = distance;
6829
+ var canonicalizedSupportedLocales = canonicalizedSupportedCache.get(supportedLocales2);
6830
+ if (!canonicalizedSupportedLocales) {
6831
+ canonicalizedSupportedLocales = supportedLocales2.map(function(locale) {
6832
+ try {
6833
+ var canonical = Intl.getCanonicalLocales([locale]);
6834
+ return canonical[0] || locale;
6835
+ } catch (_a2) {
6836
+ return locale;
6837
+ }
6838
+ });
6839
+ canonicalizedSupportedCache.set(supportedLocales2, canonicalizedSupportedLocales);
6840
+ }
6841
+ var supportedSet = new Set(canonicalizedSupportedLocales);
6842
+ for (var i = 0; i < requestedLocales.length; i++) {
6843
+ var desired = requestedLocales[i];
6844
+ if (supportedSet.has(desired)) {
6845
+ var distance = 0 + i * 40;
6846
+ result.distances[desired] = (_a = {}, _a[desired] = distance, _a);
6812
6847
  if (distance < lowestDistance) {
6813
6848
  lowestDistance = distance;
6814
6849
  result.matchedDesiredLocale = desired;
6815
- result.matchedSupportedLocale = supported;
6850
+ result.matchedSupportedLocale = desired;
6851
+ }
6852
+ if (i === 0) {
6853
+ return result;
6854
+ }
6855
+ }
6856
+ }
6857
+ for (var i = 0; i < requestedLocales.length; i++) {
6858
+ var desired = requestedLocales[i];
6859
+ try {
6860
+ var maximized = new Intl.Locale(desired).maximize().toString();
6861
+ if (maximized !== desired) {
6862
+ var maximizedCandidates = getFallbackCandidates(maximized);
6863
+ for (var j = 0; j < maximizedCandidates.length; j++) {
6864
+ var candidate = maximizedCandidates[j];
6865
+ if (candidate === desired)
6866
+ continue;
6867
+ if (supportedSet.has(candidate)) {
6868
+ var distance = void 0;
6869
+ try {
6870
+ var candidateMaximized = new Intl.Locale(candidate).maximize().toString();
6871
+ distance = candidateMaximized === maximized ? 0 + i * 40 : j * 10 + i * 40;
6872
+ } catch (_b) {
6873
+ distance = j * 10 + i * 40;
6874
+ }
6875
+ if (!result.distances[desired]) {
6876
+ result.distances[desired] = {};
6877
+ }
6878
+ result.distances[desired][candidate] = distance;
6879
+ if (distance < lowestDistance) {
6880
+ lowestDistance = distance;
6881
+ result.matchedDesiredLocale = desired;
6882
+ result.matchedSupportedLocale = candidate;
6883
+ }
6884
+ break;
6885
+ }
6886
+ }
6887
+ }
6888
+ } catch (_c) {
6889
+ }
6890
+ }
6891
+ if (result.matchedSupportedLocale && lowestDistance === 0) {
6892
+ return result;
6893
+ }
6894
+ requestedLocales.forEach(function(desired2, i2) {
6895
+ if (!result.distances[desired2]) {
6896
+ result.distances[desired2] = {};
6897
+ }
6898
+ canonicalizedSupportedLocales.forEach(function(canonicalLocale, supportedIndex) {
6899
+ var originalSupported = supportedLocales2[supportedIndex];
6900
+ var distance2 = findMatchingDistance(desired2, canonicalLocale);
6901
+ var finalDistance = distance2 + 0 + i2 * 40;
6902
+ result.distances[desired2][originalSupported] = finalDistance;
6903
+ if (finalDistance < lowestDistance) {
6904
+ lowestDistance = finalDistance;
6905
+ result.matchedDesiredLocale = desired2;
6906
+ result.matchedSupportedLocale = originalSupported;
6816
6907
  }
6817
6908
  });
6818
6909
  });
@@ -6893,10 +6984,16 @@
6893
6984
  }
6894
6985
 
6895
6986
  // node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/abstract/BestAvailableLocale.js
6987
+ var availableLocalesSetCache = /* @__PURE__ */ new WeakMap();
6896
6988
  function BestAvailableLocale(availableLocales, locale) {
6989
+ var availableSet = availableLocalesSetCache.get(availableLocales);
6990
+ if (!availableSet) {
6991
+ availableSet = new Set(availableLocales);
6992
+ availableLocalesSetCache.set(availableLocales, availableSet);
6993
+ }
6897
6994
  var candidate = locale;
6898
6995
  while (true) {
6899
- if (availableLocales.indexOf(candidate) > -1) {
6996
+ if (availableSet.has(candidate)) {
6900
6997
  return candidate;
6901
6998
  }
6902
6999
  var pos = candidate.lastIndexOf("-");