@formatjs/intl-displaynames 7.0.5 → 7.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-displaynames",
|
|
3
3
|
"description": "Polyfill for: https://tc39.es/proposal-intl-displaynames",
|
|
4
|
-
"version": "7.0.
|
|
4
|
+
"version": "7.0.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Linjie Ding <pyrocat101@users.noreply.github.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
|
"homepage": "https://github.com/formatjs/formatjs",
|
package/polyfill.iife.js
CHANGED
|
@@ -6771,7 +6771,7 @@
|
|
|
6771
6771
|
}
|
|
6772
6772
|
throw new Error("No matching distance found");
|
|
6773
6773
|
}
|
|
6774
|
-
function
|
|
6774
|
+
function findMatchingDistanceImpl(desired, supported) {
|
|
6775
6775
|
var desiredLocale = new Intl.Locale(desired).maximize();
|
|
6776
6776
|
var supportedLocale = new Intl.Locale(supported).maximize();
|
|
6777
6777
|
var desiredLSR = {
|
|
@@ -6813,7 +6813,26 @@
|
|
|
6813
6813
|
}
|
|
6814
6814
|
return matchingDistance;
|
|
6815
6815
|
}
|
|
6816
|
+
var findMatchingDistance = memoize(findMatchingDistanceImpl, {
|
|
6817
|
+
serializer: function(args) {
|
|
6818
|
+
return "".concat(args[0], "|").concat(args[1]);
|
|
6819
|
+
}
|
|
6820
|
+
});
|
|
6821
|
+
function getFallbackCandidates(locale) {
|
|
6822
|
+
var candidates = [];
|
|
6823
|
+
var current = locale;
|
|
6824
|
+
while (current) {
|
|
6825
|
+
candidates.push(current);
|
|
6826
|
+
var lastDash = current.lastIndexOf("-");
|
|
6827
|
+
if (lastDash === -1)
|
|
6828
|
+
break;
|
|
6829
|
+
current = current.substring(0, lastDash);
|
|
6830
|
+
}
|
|
6831
|
+
return candidates;
|
|
6832
|
+
}
|
|
6833
|
+
var canonicalizedSupportedCache = /* @__PURE__ */ new WeakMap();
|
|
6816
6834
|
function findBestMatch(requestedLocales, supportedLocales2, threshold) {
|
|
6835
|
+
var _a;
|
|
6817
6836
|
if (threshold === void 0) {
|
|
6818
6837
|
threshold = DEFAULT_MATCHING_THRESHOLD;
|
|
6819
6838
|
}
|
|
@@ -6822,17 +6841,84 @@
|
|
|
6822
6841
|
matchedDesiredLocale: "",
|
|
6823
6842
|
distances: {}
|
|
6824
6843
|
};
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6844
|
+
var canonicalizedSupportedLocales = canonicalizedSupportedCache.get(supportedLocales2);
|
|
6845
|
+
if (!canonicalizedSupportedLocales) {
|
|
6846
|
+
canonicalizedSupportedLocales = supportedLocales2.map(function(locale) {
|
|
6847
|
+
try {
|
|
6848
|
+
var canonical = Intl.getCanonicalLocales([locale]);
|
|
6849
|
+
return canonical[0] || locale;
|
|
6850
|
+
} catch (_a2) {
|
|
6851
|
+
return locale;
|
|
6852
|
+
}
|
|
6853
|
+
});
|
|
6854
|
+
canonicalizedSupportedCache.set(supportedLocales2, canonicalizedSupportedLocales);
|
|
6855
|
+
}
|
|
6856
|
+
var supportedSet = new Set(canonicalizedSupportedLocales);
|
|
6857
|
+
for (var i = 0; i < requestedLocales.length; i++) {
|
|
6858
|
+
var desired = requestedLocales[i];
|
|
6859
|
+
if (supportedSet.has(desired)) {
|
|
6860
|
+
var distance = 0 + i * 40;
|
|
6861
|
+
result.distances[desired] = (_a = {}, _a[desired] = distance, _a);
|
|
6832
6862
|
if (distance < lowestDistance) {
|
|
6833
6863
|
lowestDistance = distance;
|
|
6834
6864
|
result.matchedDesiredLocale = desired;
|
|
6835
|
-
result.matchedSupportedLocale =
|
|
6865
|
+
result.matchedSupportedLocale = desired;
|
|
6866
|
+
}
|
|
6867
|
+
if (i === 0) {
|
|
6868
|
+
return result;
|
|
6869
|
+
}
|
|
6870
|
+
}
|
|
6871
|
+
}
|
|
6872
|
+
for (var i = 0; i < requestedLocales.length; i++) {
|
|
6873
|
+
var desired = requestedLocales[i];
|
|
6874
|
+
try {
|
|
6875
|
+
var maximized = new Intl.Locale(desired).maximize().toString();
|
|
6876
|
+
if (maximized !== desired) {
|
|
6877
|
+
var maximizedCandidates = getFallbackCandidates(maximized);
|
|
6878
|
+
for (var j = 0; j < maximizedCandidates.length; j++) {
|
|
6879
|
+
var candidate = maximizedCandidates[j];
|
|
6880
|
+
if (candidate === desired)
|
|
6881
|
+
continue;
|
|
6882
|
+
if (supportedSet.has(candidate)) {
|
|
6883
|
+
var distance = void 0;
|
|
6884
|
+
try {
|
|
6885
|
+
var candidateMaximized = new Intl.Locale(candidate).maximize().toString();
|
|
6886
|
+
distance = candidateMaximized === maximized ? 0 + i * 40 : j * 10 + i * 40;
|
|
6887
|
+
} catch (_b) {
|
|
6888
|
+
distance = j * 10 + i * 40;
|
|
6889
|
+
}
|
|
6890
|
+
if (!result.distances[desired]) {
|
|
6891
|
+
result.distances[desired] = {};
|
|
6892
|
+
}
|
|
6893
|
+
result.distances[desired][candidate] = distance;
|
|
6894
|
+
if (distance < lowestDistance) {
|
|
6895
|
+
lowestDistance = distance;
|
|
6896
|
+
result.matchedDesiredLocale = desired;
|
|
6897
|
+
result.matchedSupportedLocale = candidate;
|
|
6898
|
+
}
|
|
6899
|
+
break;
|
|
6900
|
+
}
|
|
6901
|
+
}
|
|
6902
|
+
}
|
|
6903
|
+
} catch (_c) {
|
|
6904
|
+
}
|
|
6905
|
+
}
|
|
6906
|
+
if (result.matchedSupportedLocale && lowestDistance === 0) {
|
|
6907
|
+
return result;
|
|
6908
|
+
}
|
|
6909
|
+
requestedLocales.forEach(function(desired2, i2) {
|
|
6910
|
+
if (!result.distances[desired2]) {
|
|
6911
|
+
result.distances[desired2] = {};
|
|
6912
|
+
}
|
|
6913
|
+
canonicalizedSupportedLocales.forEach(function(canonicalLocale, supportedIndex) {
|
|
6914
|
+
var originalSupported = supportedLocales2[supportedIndex];
|
|
6915
|
+
var distance2 = findMatchingDistance(desired2, canonicalLocale);
|
|
6916
|
+
var finalDistance = distance2 + 0 + i2 * 40;
|
|
6917
|
+
result.distances[desired2][originalSupported] = finalDistance;
|
|
6918
|
+
if (finalDistance < lowestDistance) {
|
|
6919
|
+
lowestDistance = finalDistance;
|
|
6920
|
+
result.matchedDesiredLocale = desired2;
|
|
6921
|
+
result.matchedSupportedLocale = originalSupported;
|
|
6836
6922
|
}
|
|
6837
6923
|
});
|
|
6838
6924
|
});
|
|
@@ -6913,10 +6999,16 @@
|
|
|
6913
6999
|
}
|
|
6914
7000
|
|
|
6915
7001
|
// node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/abstract/BestAvailableLocale.js
|
|
7002
|
+
var availableLocalesSetCache = /* @__PURE__ */ new WeakMap();
|
|
6916
7003
|
function BestAvailableLocale(availableLocales, locale) {
|
|
7004
|
+
var availableSet = availableLocalesSetCache.get(availableLocales);
|
|
7005
|
+
if (!availableSet) {
|
|
7006
|
+
availableSet = new Set(availableLocales);
|
|
7007
|
+
availableLocalesSetCache.set(availableLocales, availableSet);
|
|
7008
|
+
}
|
|
6917
7009
|
var candidate = locale;
|
|
6918
7010
|
while (true) {
|
|
6919
|
-
if (
|
|
7011
|
+
if (availableSet.has(candidate)) {
|
|
6920
7012
|
return candidate;
|
|
6921
7013
|
}
|
|
6922
7014
|
var pos = candidate.lastIndexOf("-");
|