@formatjs/intl-datetimeformat 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-datetimeformat",
|
|
3
3
|
"description": "Intl.DateTimeFormat polyfill",
|
|
4
|
-
"version": "7.0.
|
|
4
|
+
"version": "7.0.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Long Ho <holevietlong@gmail.com>",
|
|
7
7
|
"type": "module",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"decimal.js": "^10.4.3",
|
|
20
20
|
"tslib": "^2.8.0",
|
|
21
|
-
"@formatjs/
|
|
22
|
-
"@formatjs/
|
|
21
|
+
"@formatjs/ecma402-abstract": "3.0.5",
|
|
22
|
+
"@formatjs/intl-localematcher": "0.7.3"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@formatjs/intl-getcanonicallocales": "3.0.4",
|
|
26
|
-
"@formatjs/intl-locale": "5.0.
|
|
26
|
+
"@formatjs/intl-locale": "5.0.6"
|
|
27
27
|
},
|
|
28
28
|
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
29
29
|
"homepage": "https://github.com/formatjs/formatjs#readme",
|
package/polyfill.iife.js
CHANGED
|
@@ -7053,7 +7053,7 @@
|
|
|
7053
7053
|
}
|
|
7054
7054
|
throw new Error("No matching distance found");
|
|
7055
7055
|
}
|
|
7056
|
-
function
|
|
7056
|
+
function findMatchingDistanceImpl(desired, supported) {
|
|
7057
7057
|
var desiredLocale = new Intl.Locale(desired).maximize();
|
|
7058
7058
|
var supportedLocale = new Intl.Locale(supported).maximize();
|
|
7059
7059
|
var desiredLSR = {
|
|
@@ -7095,7 +7095,26 @@
|
|
|
7095
7095
|
}
|
|
7096
7096
|
return matchingDistance;
|
|
7097
7097
|
}
|
|
7098
|
+
var findMatchingDistance = memoize(findMatchingDistanceImpl, {
|
|
7099
|
+
serializer: function(args) {
|
|
7100
|
+
return "".concat(args[0], "|").concat(args[1]);
|
|
7101
|
+
}
|
|
7102
|
+
});
|
|
7103
|
+
function getFallbackCandidates(locale) {
|
|
7104
|
+
var candidates = [];
|
|
7105
|
+
var current = locale;
|
|
7106
|
+
while (current) {
|
|
7107
|
+
candidates.push(current);
|
|
7108
|
+
var lastDash = current.lastIndexOf("-");
|
|
7109
|
+
if (lastDash === -1)
|
|
7110
|
+
break;
|
|
7111
|
+
current = current.substring(0, lastDash);
|
|
7112
|
+
}
|
|
7113
|
+
return candidates;
|
|
7114
|
+
}
|
|
7115
|
+
var canonicalizedSupportedCache = /* @__PURE__ */ new WeakMap();
|
|
7098
7116
|
function findBestMatch(requestedLocales, supportedLocales2, threshold) {
|
|
7117
|
+
var _a;
|
|
7099
7118
|
if (threshold === void 0) {
|
|
7100
7119
|
threshold = DEFAULT_MATCHING_THRESHOLD;
|
|
7101
7120
|
}
|
|
@@ -7104,17 +7123,84 @@
|
|
|
7104
7123
|
matchedDesiredLocale: "",
|
|
7105
7124
|
distances: {}
|
|
7106
7125
|
};
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
|
|
7113
|
-
|
|
7126
|
+
var canonicalizedSupportedLocales = canonicalizedSupportedCache.get(supportedLocales2);
|
|
7127
|
+
if (!canonicalizedSupportedLocales) {
|
|
7128
|
+
canonicalizedSupportedLocales = supportedLocales2.map(function(locale) {
|
|
7129
|
+
try {
|
|
7130
|
+
var canonical = Intl.getCanonicalLocales([locale]);
|
|
7131
|
+
return canonical[0] || locale;
|
|
7132
|
+
} catch (_a2) {
|
|
7133
|
+
return locale;
|
|
7134
|
+
}
|
|
7135
|
+
});
|
|
7136
|
+
canonicalizedSupportedCache.set(supportedLocales2, canonicalizedSupportedLocales);
|
|
7137
|
+
}
|
|
7138
|
+
var supportedSet = new Set(canonicalizedSupportedLocales);
|
|
7139
|
+
for (var i = 0; i < requestedLocales.length; i++) {
|
|
7140
|
+
var desired = requestedLocales[i];
|
|
7141
|
+
if (supportedSet.has(desired)) {
|
|
7142
|
+
var distance = 0 + i * 40;
|
|
7143
|
+
result.distances[desired] = (_a = {}, _a[desired] = distance, _a);
|
|
7114
7144
|
if (distance < lowestDistance) {
|
|
7115
7145
|
lowestDistance = distance;
|
|
7116
7146
|
result.matchedDesiredLocale = desired;
|
|
7117
|
-
result.matchedSupportedLocale =
|
|
7147
|
+
result.matchedSupportedLocale = desired;
|
|
7148
|
+
}
|
|
7149
|
+
if (i === 0) {
|
|
7150
|
+
return result;
|
|
7151
|
+
}
|
|
7152
|
+
}
|
|
7153
|
+
}
|
|
7154
|
+
for (var i = 0; i < requestedLocales.length; i++) {
|
|
7155
|
+
var desired = requestedLocales[i];
|
|
7156
|
+
try {
|
|
7157
|
+
var maximized = new Intl.Locale(desired).maximize().toString();
|
|
7158
|
+
if (maximized !== desired) {
|
|
7159
|
+
var maximizedCandidates = getFallbackCandidates(maximized);
|
|
7160
|
+
for (var j = 0; j < maximizedCandidates.length; j++) {
|
|
7161
|
+
var candidate = maximizedCandidates[j];
|
|
7162
|
+
if (candidate === desired)
|
|
7163
|
+
continue;
|
|
7164
|
+
if (supportedSet.has(candidate)) {
|
|
7165
|
+
var distance = void 0;
|
|
7166
|
+
try {
|
|
7167
|
+
var candidateMaximized = new Intl.Locale(candidate).maximize().toString();
|
|
7168
|
+
distance = candidateMaximized === maximized ? 0 + i * 40 : j * 10 + i * 40;
|
|
7169
|
+
} catch (_b) {
|
|
7170
|
+
distance = j * 10 + i * 40;
|
|
7171
|
+
}
|
|
7172
|
+
if (!result.distances[desired]) {
|
|
7173
|
+
result.distances[desired] = {};
|
|
7174
|
+
}
|
|
7175
|
+
result.distances[desired][candidate] = distance;
|
|
7176
|
+
if (distance < lowestDistance) {
|
|
7177
|
+
lowestDistance = distance;
|
|
7178
|
+
result.matchedDesiredLocale = desired;
|
|
7179
|
+
result.matchedSupportedLocale = candidate;
|
|
7180
|
+
}
|
|
7181
|
+
break;
|
|
7182
|
+
}
|
|
7183
|
+
}
|
|
7184
|
+
}
|
|
7185
|
+
} catch (_c) {
|
|
7186
|
+
}
|
|
7187
|
+
}
|
|
7188
|
+
if (result.matchedSupportedLocale && lowestDistance === 0) {
|
|
7189
|
+
return result;
|
|
7190
|
+
}
|
|
7191
|
+
requestedLocales.forEach(function(desired2, i2) {
|
|
7192
|
+
if (!result.distances[desired2]) {
|
|
7193
|
+
result.distances[desired2] = {};
|
|
7194
|
+
}
|
|
7195
|
+
canonicalizedSupportedLocales.forEach(function(canonicalLocale, supportedIndex) {
|
|
7196
|
+
var originalSupported = supportedLocales2[supportedIndex];
|
|
7197
|
+
var distance2 = findMatchingDistance(desired2, canonicalLocale);
|
|
7198
|
+
var finalDistance = distance2 + 0 + i2 * 40;
|
|
7199
|
+
result.distances[desired2][originalSupported] = finalDistance;
|
|
7200
|
+
if (finalDistance < lowestDistance) {
|
|
7201
|
+
lowestDistance = finalDistance;
|
|
7202
|
+
result.matchedDesiredLocale = desired2;
|
|
7203
|
+
result.matchedSupportedLocale = originalSupported;
|
|
7118
7204
|
}
|
|
7119
7205
|
});
|
|
7120
7206
|
});
|
|
@@ -7195,10 +7281,16 @@
|
|
|
7195
7281
|
}
|
|
7196
7282
|
|
|
7197
7283
|
// node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/abstract/BestAvailableLocale.js
|
|
7284
|
+
var availableLocalesSetCache = /* @__PURE__ */ new WeakMap();
|
|
7198
7285
|
function BestAvailableLocale(availableLocales, locale) {
|
|
7286
|
+
var availableSet = availableLocalesSetCache.get(availableLocales);
|
|
7287
|
+
if (!availableSet) {
|
|
7288
|
+
availableSet = new Set(availableLocales);
|
|
7289
|
+
availableLocalesSetCache.set(availableLocales, availableSet);
|
|
7290
|
+
}
|
|
7199
7291
|
var candidate = locale;
|
|
7200
7292
|
while (true) {
|
|
7201
|
-
if (
|
|
7293
|
+
if (availableSet.has(candidate)) {
|
|
7202
7294
|
return candidate;
|
|
7203
7295
|
}
|
|
7204
7296
|
var pos = candidate.lastIndexOf("-");
|