@formatjs/intl-displaynames 6.6.2 → 6.6.3

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 +31 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-displaynames",
3
- "version": "6.6.2",
3
+ "version": "6.6.3",
4
4
  "description": "Polyfill for: https://tc39.es/proposal-intl-displaynames",
5
5
  "keywords": [
6
6
  "i18n",
@@ -22,12 +22,12 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "tslib": "^2.4.0",
25
- "@formatjs/ecma402-abstract": "1.17.3",
26
- "@formatjs/intl-localematcher": "0.5.0"
25
+ "@formatjs/ecma402-abstract": "1.17.4",
26
+ "@formatjs/intl-localematcher": "0.5.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@formatjs/intl-getcanonicallocales": "2.3.0",
30
- "@formatjs/intl-locale": "3.4.1"
29
+ "@formatjs/intl-locale": "3.4.2",
30
+ "@formatjs/intl-getcanonicallocales": "2.3.0"
31
31
  },
32
32
  "bugs": {
33
33
  "url": "https://github.com/formatjs/formatjs/issues"
package/polyfill.iife.js CHANGED
@@ -6919,23 +6919,34 @@
6919
6919
  return matchingDistance;
6920
6920
  }
6921
6921
  exports.findMatchingDistance = findMatchingDistance;
6922
- function findBestMatch(desired, supportedLocales, threshold) {
6922
+ function findBestMatch(requestedLocales, supportedLocales, threshold) {
6923
6923
  if (threshold === void 0) {
6924
6924
  threshold = DEFAULT_MATCHING_THRESHOLD;
6925
6925
  }
6926
- var bestMatch = void 0;
6927
6926
  var lowestDistance = Infinity;
6928
- supportedLocales.forEach(function(supported, i) {
6929
- var distance = findMatchingDistance(desired, supported) + i;
6930
- if (distance < lowestDistance) {
6931
- lowestDistance = distance;
6932
- bestMatch = supported;
6927
+ var result = {
6928
+ matchedDesiredLocale: "",
6929
+ distances: {}
6930
+ };
6931
+ requestedLocales.forEach(function(desired, i) {
6932
+ if (!result.distances[desired]) {
6933
+ result.distances[desired] = {};
6933
6934
  }
6935
+ supportedLocales.forEach(function(supported, j) {
6936
+ var distance = findMatchingDistance(desired, supported) + j + i * 40;
6937
+ result.distances[desired][supported] = distance;
6938
+ if (distance < lowestDistance) {
6939
+ lowestDistance = distance;
6940
+ result.matchedDesiredLocale = desired;
6941
+ result.matchedSupportedLocale = supported;
6942
+ }
6943
+ });
6934
6944
  });
6935
6945
  if (lowestDistance >= threshold) {
6936
- return;
6946
+ result.matchedDesiredLocale = void 0;
6947
+ result.matchedSupportedLocale = void 0;
6937
6948
  }
6938
- return bestMatch;
6949
+ return result;
6939
6950
  }
6940
6951
  exports.findBestMatch = findBestMatch;
6941
6952
  }
@@ -6951,15 +6962,17 @@
6951
6962
  function BestFitMatcher(availableLocales, requestedLocales, getDefaultLocale) {
6952
6963
  var foundLocale;
6953
6964
  var extension;
6954
- for (var _i = 0, requestedLocales_1 = requestedLocales; _i < requestedLocales_1.length; _i++) {
6955
- var l = requestedLocales_1[_i];
6956
- var matchedLocale = (0, utils_1.findBestMatch)(l.replace(utils_1.UNICODE_EXTENSION_SEQUENCE_REGEX, ""), availableLocales);
6957
- if (matchedLocale) {
6958
- foundLocale = matchedLocale;
6959
- var noExtensionLocale = l.replace(utils_1.UNICODE_EXTENSION_SEQUENCE_REGEX, "");
6960
- extension = l.slice(noExtensionLocale.length, l.length) || void 0;
6961
- break;
6962
- }
6965
+ var noExtensionLocales = [];
6966
+ var noExtensionLocaleMap = requestedLocales.reduce(function(all, l) {
6967
+ var noExtensionLocale = l.replace(utils_1.UNICODE_EXTENSION_SEQUENCE_REGEX, "");
6968
+ noExtensionLocales.push(noExtensionLocale);
6969
+ all[noExtensionLocale] = l;
6970
+ return all;
6971
+ }, {});
6972
+ var result = (0, utils_1.findBestMatch)(noExtensionLocales, availableLocales);
6973
+ if (result.matchedSupportedLocale && result.matchedDesiredLocale) {
6974
+ foundLocale = result.matchedSupportedLocale;
6975
+ extension = noExtensionLocaleMap[result.matchedDesiredLocale].slice(result.matchedDesiredLocale.length) || void 0;
6963
6976
  }
6964
6977
  if (!foundLocale) {
6965
6978
  return { locale: getDefaultLocale() };