@formatjs/intl-segmenter 11.5.1 → 11.5.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 +3 -3
  2. package/polyfill.iife.js +31 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-segmenter",
3
- "version": "11.5.1",
3
+ "version": "11.5.2",
4
4
  "description": "Polyfill for Intl.Segmenter",
5
5
  "keywords": [
6
6
  "intl",
@@ -20,8 +20,8 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "tslib": "^2.4.0",
23
- "@formatjs/intl-localematcher": "0.5.0",
24
- "@formatjs/ecma402-abstract": "1.17.3"
23
+ "@formatjs/intl-localematcher": "0.5.1",
24
+ "@formatjs/ecma402-abstract": "1.17.4"
25
25
  },
26
26
  "main": "index.js",
27
27
  "types": "index.d.ts",
package/polyfill.iife.js CHANGED
@@ -8214,23 +8214,34 @@
8214
8214
  return matchingDistance;
8215
8215
  }
8216
8216
  exports.findMatchingDistance = findMatchingDistance;
8217
- function findBestMatch(desired, supportedLocales, threshold) {
8217
+ function findBestMatch(requestedLocales, supportedLocales, threshold) {
8218
8218
  if (threshold === void 0) {
8219
8219
  threshold = DEFAULT_MATCHING_THRESHOLD;
8220
8220
  }
8221
- var bestMatch = void 0;
8222
8221
  var lowestDistance = Infinity;
8223
- supportedLocales.forEach(function(supported, i) {
8224
- var distance = findMatchingDistance(desired, supported) + i;
8225
- if (distance < lowestDistance) {
8226
- lowestDistance = distance;
8227
- bestMatch = supported;
8222
+ var result = {
8223
+ matchedDesiredLocale: "",
8224
+ distances: {}
8225
+ };
8226
+ requestedLocales.forEach(function(desired, i) {
8227
+ if (!result.distances[desired]) {
8228
+ result.distances[desired] = {};
8228
8229
  }
8230
+ supportedLocales.forEach(function(supported, j) {
8231
+ var distance = findMatchingDistance(desired, supported) + j + i * 40;
8232
+ result.distances[desired][supported] = distance;
8233
+ if (distance < lowestDistance) {
8234
+ lowestDistance = distance;
8235
+ result.matchedDesiredLocale = desired;
8236
+ result.matchedSupportedLocale = supported;
8237
+ }
8238
+ });
8229
8239
  });
8230
8240
  if (lowestDistance >= threshold) {
8231
- return;
8241
+ result.matchedDesiredLocale = void 0;
8242
+ result.matchedSupportedLocale = void 0;
8232
8243
  }
8233
- return bestMatch;
8244
+ return result;
8234
8245
  }
8235
8246
  exports.findBestMatch = findBestMatch;
8236
8247
  }
@@ -8246,15 +8257,17 @@
8246
8257
  function BestFitMatcher(availableLocales, requestedLocales, getDefaultLocale) {
8247
8258
  var foundLocale;
8248
8259
  var extension;
8249
- for (var _i = 0, requestedLocales_1 = requestedLocales; _i < requestedLocales_1.length; _i++) {
8250
- var l = requestedLocales_1[_i];
8251
- var matchedLocale = (0, utils_1.findBestMatch)(l.replace(utils_1.UNICODE_EXTENSION_SEQUENCE_REGEX, ""), availableLocales);
8252
- if (matchedLocale) {
8253
- foundLocale = matchedLocale;
8254
- var noExtensionLocale = l.replace(utils_1.UNICODE_EXTENSION_SEQUENCE_REGEX, "");
8255
- extension = l.slice(noExtensionLocale.length, l.length) || void 0;
8256
- break;
8257
- }
8260
+ var noExtensionLocales = [];
8261
+ var noExtensionLocaleMap = requestedLocales.reduce(function(all, l) {
8262
+ var noExtensionLocale = l.replace(utils_1.UNICODE_EXTENSION_SEQUENCE_REGEX, "");
8263
+ noExtensionLocales.push(noExtensionLocale);
8264
+ all[noExtensionLocale] = l;
8265
+ return all;
8266
+ }, {});
8267
+ var result = (0, utils_1.findBestMatch)(noExtensionLocales, availableLocales);
8268
+ if (result.matchedSupportedLocale && result.matchedDesiredLocale) {
8269
+ foundLocale = result.matchedSupportedLocale;
8270
+ extension = noExtensionLocaleMap[result.matchedDesiredLocale].slice(result.matchedDesiredLocale.length) || void 0;
8258
8271
  }
8259
8272
  if (!foundLocale) {
8260
8273
  return { locale: getDefaultLocale() };