@formatjs/intl-listformat 8.0.5 → 8.0.6
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 +4 -4
- package/polyfill.iife.js +102 -10
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl-listformat",
|
|
3
3
|
"description": "Formats JS list in a i18n-safe way",
|
|
4
|
-
"version": "8.0.
|
|
4
|
+
"version": "8.0.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Long Ho <holevietlong@gmail.com>",
|
|
7
7
|
"type": "module",
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"tslib": "^2.8.0",
|
|
18
|
-
"@formatjs/
|
|
19
|
-
"@formatjs/
|
|
18
|
+
"@formatjs/ecma402-abstract": "3.0.5",
|
|
19
|
+
"@formatjs/intl-localematcher": "0.7.3"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@formatjs/intl-getcanonicallocales": "3.0.4",
|
|
23
|
-
"@formatjs/intl-locale": "5.0.
|
|
23
|
+
"@formatjs/intl-locale": "5.0.6"
|
|
24
24
|
},
|
|
25
25
|
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
26
26
|
"gitHead": "a7842673d8ad205171ad7c8cb8bb2f318b427c0c",
|
package/polyfill.iife.js
CHANGED
|
@@ -6756,7 +6756,7 @@
|
|
|
6756
6756
|
}
|
|
6757
6757
|
throw new Error("No matching distance found");
|
|
6758
6758
|
}
|
|
6759
|
-
function
|
|
6759
|
+
function findMatchingDistanceImpl(desired, supported) {
|
|
6760
6760
|
var desiredLocale = new Intl.Locale(desired).maximize();
|
|
6761
6761
|
var supportedLocale = new Intl.Locale(supported).maximize();
|
|
6762
6762
|
var desiredLSR = {
|
|
@@ -6798,7 +6798,26 @@
|
|
|
6798
6798
|
}
|
|
6799
6799
|
return matchingDistance;
|
|
6800
6800
|
}
|
|
6801
|
+
var findMatchingDistance = memoize(findMatchingDistanceImpl, {
|
|
6802
|
+
serializer: function(args) {
|
|
6803
|
+
return "".concat(args[0], "|").concat(args[1]);
|
|
6804
|
+
}
|
|
6805
|
+
});
|
|
6806
|
+
function getFallbackCandidates(locale) {
|
|
6807
|
+
var candidates = [];
|
|
6808
|
+
var current = locale;
|
|
6809
|
+
while (current) {
|
|
6810
|
+
candidates.push(current);
|
|
6811
|
+
var lastDash = current.lastIndexOf("-");
|
|
6812
|
+
if (lastDash === -1)
|
|
6813
|
+
break;
|
|
6814
|
+
current = current.substring(0, lastDash);
|
|
6815
|
+
}
|
|
6816
|
+
return candidates;
|
|
6817
|
+
}
|
|
6818
|
+
var canonicalizedSupportedCache = /* @__PURE__ */ new WeakMap();
|
|
6801
6819
|
function findBestMatch(requestedLocales, supportedLocales2, threshold) {
|
|
6820
|
+
var _a;
|
|
6802
6821
|
if (threshold === void 0) {
|
|
6803
6822
|
threshold = DEFAULT_MATCHING_THRESHOLD;
|
|
6804
6823
|
}
|
|
@@ -6807,17 +6826,84 @@
|
|
|
6807
6826
|
matchedDesiredLocale: "",
|
|
6808
6827
|
distances: {}
|
|
6809
6828
|
};
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6829
|
+
var canonicalizedSupportedLocales = canonicalizedSupportedCache.get(supportedLocales2);
|
|
6830
|
+
if (!canonicalizedSupportedLocales) {
|
|
6831
|
+
canonicalizedSupportedLocales = supportedLocales2.map(function(locale) {
|
|
6832
|
+
try {
|
|
6833
|
+
var canonical = Intl.getCanonicalLocales([locale]);
|
|
6834
|
+
return canonical[0] || locale;
|
|
6835
|
+
} catch (_a2) {
|
|
6836
|
+
return locale;
|
|
6837
|
+
}
|
|
6838
|
+
});
|
|
6839
|
+
canonicalizedSupportedCache.set(supportedLocales2, canonicalizedSupportedLocales);
|
|
6840
|
+
}
|
|
6841
|
+
var supportedSet = new Set(canonicalizedSupportedLocales);
|
|
6842
|
+
for (var i = 0; i < requestedLocales.length; i++) {
|
|
6843
|
+
var desired = requestedLocales[i];
|
|
6844
|
+
if (supportedSet.has(desired)) {
|
|
6845
|
+
var distance = 0 + i * 40;
|
|
6846
|
+
result.distances[desired] = (_a = {}, _a[desired] = distance, _a);
|
|
6817
6847
|
if (distance < lowestDistance) {
|
|
6818
6848
|
lowestDistance = distance;
|
|
6819
6849
|
result.matchedDesiredLocale = desired;
|
|
6820
|
-
result.matchedSupportedLocale =
|
|
6850
|
+
result.matchedSupportedLocale = desired;
|
|
6851
|
+
}
|
|
6852
|
+
if (i === 0) {
|
|
6853
|
+
return result;
|
|
6854
|
+
}
|
|
6855
|
+
}
|
|
6856
|
+
}
|
|
6857
|
+
for (var i = 0; i < requestedLocales.length; i++) {
|
|
6858
|
+
var desired = requestedLocales[i];
|
|
6859
|
+
try {
|
|
6860
|
+
var maximized = new Intl.Locale(desired).maximize().toString();
|
|
6861
|
+
if (maximized !== desired) {
|
|
6862
|
+
var maximizedCandidates = getFallbackCandidates(maximized);
|
|
6863
|
+
for (var j = 0; j < maximizedCandidates.length; j++) {
|
|
6864
|
+
var candidate = maximizedCandidates[j];
|
|
6865
|
+
if (candidate === desired)
|
|
6866
|
+
continue;
|
|
6867
|
+
if (supportedSet.has(candidate)) {
|
|
6868
|
+
var distance = void 0;
|
|
6869
|
+
try {
|
|
6870
|
+
var candidateMaximized = new Intl.Locale(candidate).maximize().toString();
|
|
6871
|
+
distance = candidateMaximized === maximized ? 0 + i * 40 : j * 10 + i * 40;
|
|
6872
|
+
} catch (_b) {
|
|
6873
|
+
distance = j * 10 + i * 40;
|
|
6874
|
+
}
|
|
6875
|
+
if (!result.distances[desired]) {
|
|
6876
|
+
result.distances[desired] = {};
|
|
6877
|
+
}
|
|
6878
|
+
result.distances[desired][candidate] = distance;
|
|
6879
|
+
if (distance < lowestDistance) {
|
|
6880
|
+
lowestDistance = distance;
|
|
6881
|
+
result.matchedDesiredLocale = desired;
|
|
6882
|
+
result.matchedSupportedLocale = candidate;
|
|
6883
|
+
}
|
|
6884
|
+
break;
|
|
6885
|
+
}
|
|
6886
|
+
}
|
|
6887
|
+
}
|
|
6888
|
+
} catch (_c) {
|
|
6889
|
+
}
|
|
6890
|
+
}
|
|
6891
|
+
if (result.matchedSupportedLocale && lowestDistance === 0) {
|
|
6892
|
+
return result;
|
|
6893
|
+
}
|
|
6894
|
+
requestedLocales.forEach(function(desired2, i2) {
|
|
6895
|
+
if (!result.distances[desired2]) {
|
|
6896
|
+
result.distances[desired2] = {};
|
|
6897
|
+
}
|
|
6898
|
+
canonicalizedSupportedLocales.forEach(function(canonicalLocale, supportedIndex) {
|
|
6899
|
+
var originalSupported = supportedLocales2[supportedIndex];
|
|
6900
|
+
var distance2 = findMatchingDistance(desired2, canonicalLocale);
|
|
6901
|
+
var finalDistance = distance2 + 0 + i2 * 40;
|
|
6902
|
+
result.distances[desired2][originalSupported] = finalDistance;
|
|
6903
|
+
if (finalDistance < lowestDistance) {
|
|
6904
|
+
lowestDistance = finalDistance;
|
|
6905
|
+
result.matchedDesiredLocale = desired2;
|
|
6906
|
+
result.matchedSupportedLocale = originalSupported;
|
|
6821
6907
|
}
|
|
6822
6908
|
});
|
|
6823
6909
|
});
|
|
@@ -6898,10 +6984,16 @@
|
|
|
6898
6984
|
}
|
|
6899
6985
|
|
|
6900
6986
|
// node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/abstract/BestAvailableLocale.js
|
|
6987
|
+
var availableLocalesSetCache = /* @__PURE__ */ new WeakMap();
|
|
6901
6988
|
function BestAvailableLocale(availableLocales, locale) {
|
|
6989
|
+
var availableSet = availableLocalesSetCache.get(availableLocales);
|
|
6990
|
+
if (!availableSet) {
|
|
6991
|
+
availableSet = new Set(availableLocales);
|
|
6992
|
+
availableLocalesSetCache.set(availableLocales, availableSet);
|
|
6993
|
+
}
|
|
6902
6994
|
var candidate = locale;
|
|
6903
6995
|
while (true) {
|
|
6904
|
-
if (
|
|
6996
|
+
if (availableSet.has(candidate)) {
|
|
6905
6997
|
return candidate;
|
|
6906
6998
|
}
|
|
6907
6999
|
var pos = candidate.lastIndexOf("-");
|