@formatjs/intl-relativetimeformat 12.0.5 → 12.0.7

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 +6 -6
  2. package/polyfill.iife.js +107 -10
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formatjs/intl-relativetimeformat",
3
3
  "description": "Formats JavaScript dates to relative time strings.",
4
- "version": "12.0.5",
4
+ "version": "12.0.7",
5
5
  "license": "MIT",
6
6
  "author": "Long Ho <holevietlong@gmail.com>",
7
7
  "type": "module",
@@ -15,13 +15,13 @@
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-pluralrules": "6.0.4",
23
- "@formatjs/intl-getcanonicallocales": "3.0.3",
24
- "@formatjs/intl-locale": "5.0.4"
22
+ "@formatjs/intl-getcanonicallocales": "3.0.4",
23
+ "@formatjs/intl-locale": "5.0.6",
24
+ "@formatjs/intl-pluralrules": "6.0.6"
25
25
  },
26
26
  "bugs": "https://github.com/formatjs/formatjs/issues",
27
27
  "gitHead": "a7842673d8ad205171ad7c8cb8bb2f318b427c0c",
package/polyfill.iife.js CHANGED
@@ -2681,6 +2681,11 @@
2681
2681
  }
2682
2682
  var SIMPLE_UNITS = SANCTIONED_UNITS.map(removeUnitNamespace);
2683
2683
 
2684
+ // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/decimal-cache.js
2685
+ var getPowerOf10 = memoize(function(exponent) {
2686
+ return Decimal.pow(10, exponent);
2687
+ });
2688
+
2684
2689
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/ComputeExponentForMagnitude.js
2685
2690
  Decimal.set({
2686
2691
  toExpPos: 100
@@ -6742,7 +6747,7 @@
6742
6747
  }
6743
6748
  throw new Error("No matching distance found");
6744
6749
  }
6745
- function findMatchingDistance(desired, supported) {
6750
+ function findMatchingDistanceImpl(desired, supported) {
6746
6751
  var desiredLocale = new Intl.Locale(desired).maximize();
6747
6752
  var supportedLocale = new Intl.Locale(supported).maximize();
6748
6753
  var desiredLSR = {
@@ -6784,7 +6789,26 @@
6784
6789
  }
6785
6790
  return matchingDistance;
6786
6791
  }
6792
+ var findMatchingDistance = memoize(findMatchingDistanceImpl, {
6793
+ serializer: function(args) {
6794
+ return "".concat(args[0], "|").concat(args[1]);
6795
+ }
6796
+ });
6797
+ function getFallbackCandidates(locale) {
6798
+ var candidates = [];
6799
+ var current = locale;
6800
+ while (current) {
6801
+ candidates.push(current);
6802
+ var lastDash = current.lastIndexOf("-");
6803
+ if (lastDash === -1)
6804
+ break;
6805
+ current = current.substring(0, lastDash);
6806
+ }
6807
+ return candidates;
6808
+ }
6809
+ var canonicalizedSupportedCache = /* @__PURE__ */ new WeakMap();
6787
6810
  function findBestMatch(requestedLocales, supportedLocales2, threshold) {
6811
+ var _a;
6788
6812
  if (threshold === void 0) {
6789
6813
  threshold = DEFAULT_MATCHING_THRESHOLD;
6790
6814
  }
@@ -6793,17 +6817,84 @@
6793
6817
  matchedDesiredLocale: "",
6794
6818
  distances: {}
6795
6819
  };
6796
- requestedLocales.forEach(function(desired, i) {
6797
- if (!result.distances[desired]) {
6798
- result.distances[desired] = {};
6799
- }
6800
- supportedLocales2.forEach(function(supported) {
6801
- var distance = findMatchingDistance(desired, supported) + 0 + i * 40;
6802
- result.distances[desired][supported] = distance;
6820
+ var canonicalizedSupportedLocales = canonicalizedSupportedCache.get(supportedLocales2);
6821
+ if (!canonicalizedSupportedLocales) {
6822
+ canonicalizedSupportedLocales = supportedLocales2.map(function(locale) {
6823
+ try {
6824
+ var canonical = Intl.getCanonicalLocales([locale]);
6825
+ return canonical[0] || locale;
6826
+ } catch (_a2) {
6827
+ return locale;
6828
+ }
6829
+ });
6830
+ canonicalizedSupportedCache.set(supportedLocales2, canonicalizedSupportedLocales);
6831
+ }
6832
+ var supportedSet = new Set(canonicalizedSupportedLocales);
6833
+ for (var i = 0; i < requestedLocales.length; i++) {
6834
+ var desired = requestedLocales[i];
6835
+ if (supportedSet.has(desired)) {
6836
+ var distance = 0 + i * 40;
6837
+ result.distances[desired] = (_a = {}, _a[desired] = distance, _a);
6803
6838
  if (distance < lowestDistance) {
6804
6839
  lowestDistance = distance;
6805
6840
  result.matchedDesiredLocale = desired;
6806
- result.matchedSupportedLocale = supported;
6841
+ result.matchedSupportedLocale = desired;
6842
+ }
6843
+ if (i === 0) {
6844
+ return result;
6845
+ }
6846
+ }
6847
+ }
6848
+ for (var i = 0; i < requestedLocales.length; i++) {
6849
+ var desired = requestedLocales[i];
6850
+ try {
6851
+ var maximized = new Intl.Locale(desired).maximize().toString();
6852
+ if (maximized !== desired) {
6853
+ var maximizedCandidates = getFallbackCandidates(maximized);
6854
+ for (var j = 0; j < maximizedCandidates.length; j++) {
6855
+ var candidate = maximizedCandidates[j];
6856
+ if (candidate === desired)
6857
+ continue;
6858
+ if (supportedSet.has(candidate)) {
6859
+ var distance = void 0;
6860
+ try {
6861
+ var candidateMaximized = new Intl.Locale(candidate).maximize().toString();
6862
+ distance = candidateMaximized === maximized ? 0 + i * 40 : j * 10 + i * 40;
6863
+ } catch (_b) {
6864
+ distance = j * 10 + i * 40;
6865
+ }
6866
+ if (!result.distances[desired]) {
6867
+ result.distances[desired] = {};
6868
+ }
6869
+ result.distances[desired][candidate] = distance;
6870
+ if (distance < lowestDistance) {
6871
+ lowestDistance = distance;
6872
+ result.matchedDesiredLocale = desired;
6873
+ result.matchedSupportedLocale = candidate;
6874
+ }
6875
+ break;
6876
+ }
6877
+ }
6878
+ }
6879
+ } catch (_c) {
6880
+ }
6881
+ }
6882
+ if (result.matchedSupportedLocale && lowestDistance === 0) {
6883
+ return result;
6884
+ }
6885
+ requestedLocales.forEach(function(desired2, i2) {
6886
+ if (!result.distances[desired2]) {
6887
+ result.distances[desired2] = {};
6888
+ }
6889
+ canonicalizedSupportedLocales.forEach(function(canonicalLocale, supportedIndex) {
6890
+ var originalSupported = supportedLocales2[supportedIndex];
6891
+ var distance2 = findMatchingDistance(desired2, canonicalLocale);
6892
+ var finalDistance = distance2 + 0 + i2 * 40;
6893
+ result.distances[desired2][originalSupported] = finalDistance;
6894
+ if (finalDistance < lowestDistance) {
6895
+ lowestDistance = finalDistance;
6896
+ result.matchedDesiredLocale = desired2;
6897
+ result.matchedSupportedLocale = originalSupported;
6807
6898
  }
6808
6899
  });
6809
6900
  });
@@ -6884,10 +6975,16 @@
6884
6975
  }
6885
6976
 
6886
6977
  // node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/abstract/BestAvailableLocale.js
6978
+ var availableLocalesSetCache = /* @__PURE__ */ new WeakMap();
6887
6979
  function BestAvailableLocale(availableLocales, locale) {
6980
+ var availableSet = availableLocalesSetCache.get(availableLocales);
6981
+ if (!availableSet) {
6982
+ availableSet = new Set(availableLocales);
6983
+ availableLocalesSetCache.set(availableLocales, availableSet);
6984
+ }
6888
6985
  var candidate = locale;
6889
6986
  while (true) {
6890
- if (availableLocales.indexOf(candidate) > -1) {
6987
+ if (availableSet.has(candidate)) {
6891
6988
  return candidate;
6892
6989
  }
6893
6990
  var pos = candidate.lastIndexOf("-");