@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.
- package/package.json +3 -3
- 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.
|
|
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.
|
|
24
|
-
"@formatjs/ecma402-abstract": "1.17.
|
|
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(
|
|
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
|
-
|
|
8224
|
-
|
|
8225
|
-
|
|
8226
|
-
|
|
8227
|
-
|
|
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
|
-
|
|
8241
|
+
result.matchedDesiredLocale = void 0;
|
|
8242
|
+
result.matchedSupportedLocale = void 0;
|
|
8232
8243
|
}
|
|
8233
|
-
return
|
|
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
|
-
|
|
8250
|
-
|
|
8251
|
-
var
|
|
8252
|
-
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
|
|
8256
|
-
|
|
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() };
|