@formatjs/intl-segmenter 12.0.4 → 12.0.5
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 +102 -10
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl-segmenter",
|
|
3
3
|
"description": "Polyfill for Intl.Segmenter",
|
|
4
|
-
"version": "12.0.
|
|
4
|
+
"version": "12.0.5",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Matija Gaspar <matijagaspar@gmail.com>",
|
|
7
7
|
"type": "module",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"tslib": "^2.8.0",
|
|
15
|
-
"@formatjs/
|
|
16
|
-
"@formatjs/
|
|
15
|
+
"@formatjs/intl-localematcher": "0.7.3",
|
|
16
|
+
"@formatjs/ecma402-abstract": "3.0.5"
|
|
17
17
|
},
|
|
18
18
|
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
19
19
|
"homepage": "https://github.com/formatjs/formatjs",
|
package/polyfill.iife.js
CHANGED
|
@@ -6740,7 +6740,7 @@
|
|
|
6740
6740
|
}
|
|
6741
6741
|
throw new Error("No matching distance found");
|
|
6742
6742
|
}
|
|
6743
|
-
function
|
|
6743
|
+
function findMatchingDistanceImpl(desired, supported) {
|
|
6744
6744
|
var desiredLocale = new Intl.Locale(desired).maximize();
|
|
6745
6745
|
var supportedLocale = new Intl.Locale(supported).maximize();
|
|
6746
6746
|
var desiredLSR = {
|
|
@@ -6782,7 +6782,26 @@
|
|
|
6782
6782
|
}
|
|
6783
6783
|
return matchingDistance;
|
|
6784
6784
|
}
|
|
6785
|
+
var findMatchingDistance = memoize(findMatchingDistanceImpl, {
|
|
6786
|
+
serializer: function(args) {
|
|
6787
|
+
return "".concat(args[0], "|").concat(args[1]);
|
|
6788
|
+
}
|
|
6789
|
+
});
|
|
6790
|
+
function getFallbackCandidates(locale) {
|
|
6791
|
+
var candidates = [];
|
|
6792
|
+
var current = locale;
|
|
6793
|
+
while (current) {
|
|
6794
|
+
candidates.push(current);
|
|
6795
|
+
var lastDash = current.lastIndexOf("-");
|
|
6796
|
+
if (lastDash === -1)
|
|
6797
|
+
break;
|
|
6798
|
+
current = current.substring(0, lastDash);
|
|
6799
|
+
}
|
|
6800
|
+
return candidates;
|
|
6801
|
+
}
|
|
6802
|
+
var canonicalizedSupportedCache = /* @__PURE__ */ new WeakMap();
|
|
6785
6803
|
function findBestMatch(requestedLocales, supportedLocales, threshold) {
|
|
6804
|
+
var _a;
|
|
6786
6805
|
if (threshold === void 0) {
|
|
6787
6806
|
threshold = DEFAULT_MATCHING_THRESHOLD;
|
|
6788
6807
|
}
|
|
@@ -6791,17 +6810,84 @@
|
|
|
6791
6810
|
matchedDesiredLocale: "",
|
|
6792
6811
|
distances: {}
|
|
6793
6812
|
};
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6813
|
+
var canonicalizedSupportedLocales = canonicalizedSupportedCache.get(supportedLocales);
|
|
6814
|
+
if (!canonicalizedSupportedLocales) {
|
|
6815
|
+
canonicalizedSupportedLocales = supportedLocales.map(function(locale) {
|
|
6816
|
+
try {
|
|
6817
|
+
var canonical = Intl.getCanonicalLocales([locale]);
|
|
6818
|
+
return canonical[0] || locale;
|
|
6819
|
+
} catch (_a2) {
|
|
6820
|
+
return locale;
|
|
6821
|
+
}
|
|
6822
|
+
});
|
|
6823
|
+
canonicalizedSupportedCache.set(supportedLocales, canonicalizedSupportedLocales);
|
|
6824
|
+
}
|
|
6825
|
+
var supportedSet = new Set(canonicalizedSupportedLocales);
|
|
6826
|
+
for (var i = 0; i < requestedLocales.length; i++) {
|
|
6827
|
+
var desired = requestedLocales[i];
|
|
6828
|
+
if (supportedSet.has(desired)) {
|
|
6829
|
+
var distance = 0 + i * 40;
|
|
6830
|
+
result.distances[desired] = (_a = {}, _a[desired] = distance, _a);
|
|
6801
6831
|
if (distance < lowestDistance) {
|
|
6802
6832
|
lowestDistance = distance;
|
|
6803
6833
|
result.matchedDesiredLocale = desired;
|
|
6804
|
-
result.matchedSupportedLocale =
|
|
6834
|
+
result.matchedSupportedLocale = desired;
|
|
6835
|
+
}
|
|
6836
|
+
if (i === 0) {
|
|
6837
|
+
return result;
|
|
6838
|
+
}
|
|
6839
|
+
}
|
|
6840
|
+
}
|
|
6841
|
+
for (var i = 0; i < requestedLocales.length; i++) {
|
|
6842
|
+
var desired = requestedLocales[i];
|
|
6843
|
+
try {
|
|
6844
|
+
var maximized = new Intl.Locale(desired).maximize().toString();
|
|
6845
|
+
if (maximized !== desired) {
|
|
6846
|
+
var maximizedCandidates = getFallbackCandidates(maximized);
|
|
6847
|
+
for (var j = 0; j < maximizedCandidates.length; j++) {
|
|
6848
|
+
var candidate = maximizedCandidates[j];
|
|
6849
|
+
if (candidate === desired)
|
|
6850
|
+
continue;
|
|
6851
|
+
if (supportedSet.has(candidate)) {
|
|
6852
|
+
var distance = void 0;
|
|
6853
|
+
try {
|
|
6854
|
+
var candidateMaximized = new Intl.Locale(candidate).maximize().toString();
|
|
6855
|
+
distance = candidateMaximized === maximized ? 0 + i * 40 : j * 10 + i * 40;
|
|
6856
|
+
} catch (_b) {
|
|
6857
|
+
distance = j * 10 + i * 40;
|
|
6858
|
+
}
|
|
6859
|
+
if (!result.distances[desired]) {
|
|
6860
|
+
result.distances[desired] = {};
|
|
6861
|
+
}
|
|
6862
|
+
result.distances[desired][candidate] = distance;
|
|
6863
|
+
if (distance < lowestDistance) {
|
|
6864
|
+
lowestDistance = distance;
|
|
6865
|
+
result.matchedDesiredLocale = desired;
|
|
6866
|
+
result.matchedSupportedLocale = candidate;
|
|
6867
|
+
}
|
|
6868
|
+
break;
|
|
6869
|
+
}
|
|
6870
|
+
}
|
|
6871
|
+
}
|
|
6872
|
+
} catch (_c) {
|
|
6873
|
+
}
|
|
6874
|
+
}
|
|
6875
|
+
if (result.matchedSupportedLocale && lowestDistance === 0) {
|
|
6876
|
+
return result;
|
|
6877
|
+
}
|
|
6878
|
+
requestedLocales.forEach(function(desired2, i2) {
|
|
6879
|
+
if (!result.distances[desired2]) {
|
|
6880
|
+
result.distances[desired2] = {};
|
|
6881
|
+
}
|
|
6882
|
+
canonicalizedSupportedLocales.forEach(function(canonicalLocale, supportedIndex) {
|
|
6883
|
+
var originalSupported = supportedLocales[supportedIndex];
|
|
6884
|
+
var distance2 = findMatchingDistance(desired2, canonicalLocale);
|
|
6885
|
+
var finalDistance = distance2 + 0 + i2 * 40;
|
|
6886
|
+
result.distances[desired2][originalSupported] = finalDistance;
|
|
6887
|
+
if (finalDistance < lowestDistance) {
|
|
6888
|
+
lowestDistance = finalDistance;
|
|
6889
|
+
result.matchedDesiredLocale = desired2;
|
|
6890
|
+
result.matchedSupportedLocale = originalSupported;
|
|
6805
6891
|
}
|
|
6806
6892
|
});
|
|
6807
6893
|
});
|
|
@@ -6882,10 +6968,16 @@
|
|
|
6882
6968
|
}
|
|
6883
6969
|
|
|
6884
6970
|
// node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/abstract/BestAvailableLocale.js
|
|
6971
|
+
var availableLocalesSetCache = /* @__PURE__ */ new WeakMap();
|
|
6885
6972
|
function BestAvailableLocale(availableLocales, locale) {
|
|
6973
|
+
var availableSet = availableLocalesSetCache.get(availableLocales);
|
|
6974
|
+
if (!availableSet) {
|
|
6975
|
+
availableSet = new Set(availableLocales);
|
|
6976
|
+
availableLocalesSetCache.set(availableLocales, availableSet);
|
|
6977
|
+
}
|
|
6886
6978
|
var candidate = locale;
|
|
6887
6979
|
while (true) {
|
|
6888
|
-
if (
|
|
6980
|
+
if (availableSet.has(candidate)) {
|
|
6889
6981
|
return candidate;
|
|
6890
6982
|
}
|
|
6891
6983
|
var pos = candidate.lastIndexOf("-");
|