@formatjs/intl-locale 3.4.1 → 3.4.2

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 +4 -4
  2. package/polyfill.iife.js +31 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-locale",
3
- "version": "3.4.1",
3
+ "version": "3.4.2",
4
4
  "description": "Intl.Locale polyfill",
5
5
  "keywords": [
6
6
  "intl",
@@ -25,8 +25,8 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "tslib": "^2.4.0",
28
- "@formatjs/ecma402-abstract": "1.17.3",
29
- "@formatjs/intl-getcanonicallocales": "2.3.0",
30
- "@formatjs/intl-enumerator": "1.4.1"
28
+ "@formatjs/ecma402-abstract": "1.17.4",
29
+ "@formatjs/intl-enumerator": "1.4.2",
30
+ "@formatjs/intl-getcanonicallocales": "2.3.0"
31
31
  }
32
32
  }
package/polyfill.iife.js CHANGED
@@ -7233,23 +7233,34 @@
7233
7233
  return matchingDistance;
7234
7234
  }
7235
7235
  exports.findMatchingDistance = findMatchingDistance;
7236
- function findBestMatch(desired, supportedLocales, threshold) {
7236
+ function findBestMatch(requestedLocales, supportedLocales, threshold) {
7237
7237
  if (threshold === void 0) {
7238
7238
  threshold = DEFAULT_MATCHING_THRESHOLD;
7239
7239
  }
7240
- var bestMatch = void 0;
7241
7240
  var lowestDistance = Infinity;
7242
- supportedLocales.forEach(function(supported, i) {
7243
- var distance = findMatchingDistance(desired, supported) + i;
7244
- if (distance < lowestDistance) {
7245
- lowestDistance = distance;
7246
- bestMatch = supported;
7241
+ var result = {
7242
+ matchedDesiredLocale: "",
7243
+ distances: {}
7244
+ };
7245
+ requestedLocales.forEach(function(desired, i) {
7246
+ if (!result.distances[desired]) {
7247
+ result.distances[desired] = {};
7247
7248
  }
7249
+ supportedLocales.forEach(function(supported, j) {
7250
+ var distance = findMatchingDistance(desired, supported) + j + i * 40;
7251
+ result.distances[desired][supported] = distance;
7252
+ if (distance < lowestDistance) {
7253
+ lowestDistance = distance;
7254
+ result.matchedDesiredLocale = desired;
7255
+ result.matchedSupportedLocale = supported;
7256
+ }
7257
+ });
7248
7258
  });
7249
7259
  if (lowestDistance >= threshold) {
7250
- return;
7260
+ result.matchedDesiredLocale = void 0;
7261
+ result.matchedSupportedLocale = void 0;
7251
7262
  }
7252
- return bestMatch;
7263
+ return result;
7253
7264
  }
7254
7265
  exports.findBestMatch = findBestMatch;
7255
7266
  }
@@ -7265,15 +7276,17 @@
7265
7276
  function BestFitMatcher(availableLocales, requestedLocales, getDefaultLocale) {
7266
7277
  var foundLocale;
7267
7278
  var extension;
7268
- for (var _i = 0, requestedLocales_1 = requestedLocales; _i < requestedLocales_1.length; _i++) {
7269
- var l = requestedLocales_1[_i];
7270
- var matchedLocale = (0, utils_1.findBestMatch)(l.replace(utils_1.UNICODE_EXTENSION_SEQUENCE_REGEX, ""), availableLocales);
7271
- if (matchedLocale) {
7272
- foundLocale = matchedLocale;
7273
- var noExtensionLocale = l.replace(utils_1.UNICODE_EXTENSION_SEQUENCE_REGEX, "");
7274
- extension = l.slice(noExtensionLocale.length, l.length) || void 0;
7275
- break;
7276
- }
7279
+ var noExtensionLocales = [];
7280
+ var noExtensionLocaleMap = requestedLocales.reduce(function(all, l) {
7281
+ var noExtensionLocale = l.replace(utils_1.UNICODE_EXTENSION_SEQUENCE_REGEX, "");
7282
+ noExtensionLocales.push(noExtensionLocale);
7283
+ all[noExtensionLocale] = l;
7284
+ return all;
7285
+ }, {});
7286
+ var result = (0, utils_1.findBestMatch)(noExtensionLocales, availableLocales);
7287
+ if (result.matchedSupportedLocale && result.matchedDesiredLocale) {
7288
+ foundLocale = result.matchedSupportedLocale;
7289
+ extension = noExtensionLocaleMap[result.matchedDesiredLocale].slice(result.matchedDesiredLocale.length) || void 0;
7277
7290
  }
7278
7291
  if (!foundLocale) {
7279
7292
  return { locale: getDefaultLocale() };