@formatjs/intl-numberformat 9.0.6 → 9.0.7
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 +5 -5
- package/polyfill.iife.js +102 -10
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl-numberformat",
|
|
3
3
|
"description": "Ponyfill for ES2020 Intl.NumberFormat",
|
|
4
|
-
"version": "9.0.
|
|
4
|
+
"version": "9.0.7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "index.d.ts",
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"decimal.js": "^10.4.3",
|
|
17
17
|
"tslib": "^2.8.0",
|
|
18
|
-
"@formatjs/intl-localematcher": "0.7.
|
|
19
|
-
"@formatjs/ecma402-abstract": "3.0.
|
|
18
|
+
"@formatjs/intl-localematcher": "0.7.3",
|
|
19
|
+
"@formatjs/ecma402-abstract": "3.0.5"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@formatjs/intl-getcanonicallocales": "3.0.4",
|
|
23
|
-
"@formatjs/intl-locale": "5.0.
|
|
24
|
-
"@formatjs/intl-pluralrules": "6.0.
|
|
23
|
+
"@formatjs/intl-locale": "5.0.6",
|
|
24
|
+
"@formatjs/intl-pluralrules": "6.0.6"
|
|
25
25
|
},
|
|
26
26
|
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
27
27
|
"contributors": [
|
package/polyfill.iife.js
CHANGED
|
@@ -8616,7 +8616,7 @@
|
|
|
8616
8616
|
}
|
|
8617
8617
|
throw new Error("No matching distance found");
|
|
8618
8618
|
}
|
|
8619
|
-
function
|
|
8619
|
+
function findMatchingDistanceImpl(desired, supported) {
|
|
8620
8620
|
var desiredLocale = new Intl.Locale(desired).maximize();
|
|
8621
8621
|
var supportedLocale = new Intl.Locale(supported).maximize();
|
|
8622
8622
|
var desiredLSR = {
|
|
@@ -8658,7 +8658,26 @@
|
|
|
8658
8658
|
}
|
|
8659
8659
|
return matchingDistance;
|
|
8660
8660
|
}
|
|
8661
|
+
var findMatchingDistance = memoize(findMatchingDistanceImpl, {
|
|
8662
|
+
serializer: function(args) {
|
|
8663
|
+
return "".concat(args[0], "|").concat(args[1]);
|
|
8664
|
+
}
|
|
8665
|
+
});
|
|
8666
|
+
function getFallbackCandidates(locale) {
|
|
8667
|
+
var candidates = [];
|
|
8668
|
+
var current = locale;
|
|
8669
|
+
while (current) {
|
|
8670
|
+
candidates.push(current);
|
|
8671
|
+
var lastDash = current.lastIndexOf("-");
|
|
8672
|
+
if (lastDash === -1)
|
|
8673
|
+
break;
|
|
8674
|
+
current = current.substring(0, lastDash);
|
|
8675
|
+
}
|
|
8676
|
+
return candidates;
|
|
8677
|
+
}
|
|
8678
|
+
var canonicalizedSupportedCache = /* @__PURE__ */ new WeakMap();
|
|
8661
8679
|
function findBestMatch(requestedLocales, supportedLocales2, threshold) {
|
|
8680
|
+
var _a;
|
|
8662
8681
|
if (threshold === void 0) {
|
|
8663
8682
|
threshold = DEFAULT_MATCHING_THRESHOLD;
|
|
8664
8683
|
}
|
|
@@ -8667,17 +8686,84 @@
|
|
|
8667
8686
|
matchedDesiredLocale: "",
|
|
8668
8687
|
distances: {}
|
|
8669
8688
|
};
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
|
|
8689
|
+
var canonicalizedSupportedLocales = canonicalizedSupportedCache.get(supportedLocales2);
|
|
8690
|
+
if (!canonicalizedSupportedLocales) {
|
|
8691
|
+
canonicalizedSupportedLocales = supportedLocales2.map(function(locale) {
|
|
8692
|
+
try {
|
|
8693
|
+
var canonical = Intl.getCanonicalLocales([locale]);
|
|
8694
|
+
return canonical[0] || locale;
|
|
8695
|
+
} catch (_a2) {
|
|
8696
|
+
return locale;
|
|
8697
|
+
}
|
|
8698
|
+
});
|
|
8699
|
+
canonicalizedSupportedCache.set(supportedLocales2, canonicalizedSupportedLocales);
|
|
8700
|
+
}
|
|
8701
|
+
var supportedSet = new Set(canonicalizedSupportedLocales);
|
|
8702
|
+
for (var i = 0; i < requestedLocales.length; i++) {
|
|
8703
|
+
var desired = requestedLocales[i];
|
|
8704
|
+
if (supportedSet.has(desired)) {
|
|
8705
|
+
var distance = 0 + i * 40;
|
|
8706
|
+
result.distances[desired] = (_a = {}, _a[desired] = distance, _a);
|
|
8677
8707
|
if (distance < lowestDistance) {
|
|
8678
8708
|
lowestDistance = distance;
|
|
8679
8709
|
result.matchedDesiredLocale = desired;
|
|
8680
|
-
result.matchedSupportedLocale =
|
|
8710
|
+
result.matchedSupportedLocale = desired;
|
|
8711
|
+
}
|
|
8712
|
+
if (i === 0) {
|
|
8713
|
+
return result;
|
|
8714
|
+
}
|
|
8715
|
+
}
|
|
8716
|
+
}
|
|
8717
|
+
for (var i = 0; i < requestedLocales.length; i++) {
|
|
8718
|
+
var desired = requestedLocales[i];
|
|
8719
|
+
try {
|
|
8720
|
+
var maximized = new Intl.Locale(desired).maximize().toString();
|
|
8721
|
+
if (maximized !== desired) {
|
|
8722
|
+
var maximizedCandidates = getFallbackCandidates(maximized);
|
|
8723
|
+
for (var j = 0; j < maximizedCandidates.length; j++) {
|
|
8724
|
+
var candidate = maximizedCandidates[j];
|
|
8725
|
+
if (candidate === desired)
|
|
8726
|
+
continue;
|
|
8727
|
+
if (supportedSet.has(candidate)) {
|
|
8728
|
+
var distance = void 0;
|
|
8729
|
+
try {
|
|
8730
|
+
var candidateMaximized = new Intl.Locale(candidate).maximize().toString();
|
|
8731
|
+
distance = candidateMaximized === maximized ? 0 + i * 40 : j * 10 + i * 40;
|
|
8732
|
+
} catch (_b) {
|
|
8733
|
+
distance = j * 10 + i * 40;
|
|
8734
|
+
}
|
|
8735
|
+
if (!result.distances[desired]) {
|
|
8736
|
+
result.distances[desired] = {};
|
|
8737
|
+
}
|
|
8738
|
+
result.distances[desired][candidate] = distance;
|
|
8739
|
+
if (distance < lowestDistance) {
|
|
8740
|
+
lowestDistance = distance;
|
|
8741
|
+
result.matchedDesiredLocale = desired;
|
|
8742
|
+
result.matchedSupportedLocale = candidate;
|
|
8743
|
+
}
|
|
8744
|
+
break;
|
|
8745
|
+
}
|
|
8746
|
+
}
|
|
8747
|
+
}
|
|
8748
|
+
} catch (_c) {
|
|
8749
|
+
}
|
|
8750
|
+
}
|
|
8751
|
+
if (result.matchedSupportedLocale && lowestDistance === 0) {
|
|
8752
|
+
return result;
|
|
8753
|
+
}
|
|
8754
|
+
requestedLocales.forEach(function(desired2, i2) {
|
|
8755
|
+
if (!result.distances[desired2]) {
|
|
8756
|
+
result.distances[desired2] = {};
|
|
8757
|
+
}
|
|
8758
|
+
canonicalizedSupportedLocales.forEach(function(canonicalLocale, supportedIndex) {
|
|
8759
|
+
var originalSupported = supportedLocales2[supportedIndex];
|
|
8760
|
+
var distance2 = findMatchingDistance(desired2, canonicalLocale);
|
|
8761
|
+
var finalDistance = distance2 + 0 + i2 * 40;
|
|
8762
|
+
result.distances[desired2][originalSupported] = finalDistance;
|
|
8763
|
+
if (finalDistance < lowestDistance) {
|
|
8764
|
+
lowestDistance = finalDistance;
|
|
8765
|
+
result.matchedDesiredLocale = desired2;
|
|
8766
|
+
result.matchedSupportedLocale = originalSupported;
|
|
8681
8767
|
}
|
|
8682
8768
|
});
|
|
8683
8769
|
});
|
|
@@ -8758,10 +8844,16 @@
|
|
|
8758
8844
|
}
|
|
8759
8845
|
|
|
8760
8846
|
// node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/abstract/BestAvailableLocale.js
|
|
8847
|
+
var availableLocalesSetCache = /* @__PURE__ */ new WeakMap();
|
|
8761
8848
|
function BestAvailableLocale(availableLocales, locale) {
|
|
8849
|
+
var availableSet = availableLocalesSetCache.get(availableLocales);
|
|
8850
|
+
if (!availableSet) {
|
|
8851
|
+
availableSet = new Set(availableLocales);
|
|
8852
|
+
availableLocalesSetCache.set(availableLocales, availableSet);
|
|
8853
|
+
}
|
|
8762
8854
|
var candidate = locale;
|
|
8763
8855
|
while (true) {
|
|
8764
|
-
if (
|
|
8856
|
+
if (availableSet.has(candidate)) {
|
|
8765
8857
|
return candidate;
|
|
8766
8858
|
}
|
|
8767
8859
|
var pos = candidate.lastIndexOf("-");
|