@formatjs/intl-pluralrules 6.0.5 → 6.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-pluralrules",
|
|
3
3
|
"description": "Polyfill for Intl.PluralRules",
|
|
4
|
-
"version": "6.0.
|
|
4
|
+
"version": "6.0.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Long Ho <holevietlong@gmail.com>",
|
|
7
7
|
"type": "module",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"decimal.js": "^10.4.3",
|
|
18
18
|
"tslib": "^2.8.0",
|
|
19
|
-
"@formatjs/ecma402-abstract": "3.0.
|
|
20
|
-
"@formatjs/intl-localematcher": "0.7.
|
|
19
|
+
"@formatjs/ecma402-abstract": "3.0.5",
|
|
20
|
+
"@formatjs/intl-localematcher": "0.7.3"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@formatjs/intl-locale": "5.0.
|
|
23
|
+
"@formatjs/intl-locale": "5.0.6",
|
|
24
24
|
"@formatjs/intl-getcanonicallocales": "3.0.4"
|
|
25
25
|
},
|
|
26
26
|
"bugs": "https://github.com/formatjs/formatjs/issues",
|
package/polyfill.iife.js
CHANGED
|
@@ -7181,7 +7181,7 @@
|
|
|
7181
7181
|
}
|
|
7182
7182
|
throw new Error("No matching distance found");
|
|
7183
7183
|
}
|
|
7184
|
-
function
|
|
7184
|
+
function findMatchingDistanceImpl(desired, supported) {
|
|
7185
7185
|
var desiredLocale = new Intl.Locale(desired).maximize();
|
|
7186
7186
|
var supportedLocale = new Intl.Locale(supported).maximize();
|
|
7187
7187
|
var desiredLSR = {
|
|
@@ -7223,7 +7223,26 @@
|
|
|
7223
7223
|
}
|
|
7224
7224
|
return matchingDistance;
|
|
7225
7225
|
}
|
|
7226
|
+
var findMatchingDistance = memoize(findMatchingDistanceImpl, {
|
|
7227
|
+
serializer: function(args) {
|
|
7228
|
+
return "".concat(args[0], "|").concat(args[1]);
|
|
7229
|
+
}
|
|
7230
|
+
});
|
|
7231
|
+
function getFallbackCandidates(locale) {
|
|
7232
|
+
var candidates = [];
|
|
7233
|
+
var current = locale;
|
|
7234
|
+
while (current) {
|
|
7235
|
+
candidates.push(current);
|
|
7236
|
+
var lastDash = current.lastIndexOf("-");
|
|
7237
|
+
if (lastDash === -1)
|
|
7238
|
+
break;
|
|
7239
|
+
current = current.substring(0, lastDash);
|
|
7240
|
+
}
|
|
7241
|
+
return candidates;
|
|
7242
|
+
}
|
|
7243
|
+
var canonicalizedSupportedCache = /* @__PURE__ */ new WeakMap();
|
|
7226
7244
|
function findBestMatch(requestedLocales, supportedLocales2, threshold) {
|
|
7245
|
+
var _a;
|
|
7227
7246
|
if (threshold === void 0) {
|
|
7228
7247
|
threshold = DEFAULT_MATCHING_THRESHOLD;
|
|
7229
7248
|
}
|
|
@@ -7232,17 +7251,84 @@
|
|
|
7232
7251
|
matchedDesiredLocale: "",
|
|
7233
7252
|
distances: {}
|
|
7234
7253
|
};
|
|
7235
|
-
|
|
7236
|
-
|
|
7237
|
-
|
|
7238
|
-
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
7254
|
+
var canonicalizedSupportedLocales = canonicalizedSupportedCache.get(supportedLocales2);
|
|
7255
|
+
if (!canonicalizedSupportedLocales) {
|
|
7256
|
+
canonicalizedSupportedLocales = supportedLocales2.map(function(locale) {
|
|
7257
|
+
try {
|
|
7258
|
+
var canonical = Intl.getCanonicalLocales([locale]);
|
|
7259
|
+
return canonical[0] || locale;
|
|
7260
|
+
} catch (_a2) {
|
|
7261
|
+
return locale;
|
|
7262
|
+
}
|
|
7263
|
+
});
|
|
7264
|
+
canonicalizedSupportedCache.set(supportedLocales2, canonicalizedSupportedLocales);
|
|
7265
|
+
}
|
|
7266
|
+
var supportedSet = new Set(canonicalizedSupportedLocales);
|
|
7267
|
+
for (var i = 0; i < requestedLocales.length; i++) {
|
|
7268
|
+
var desired = requestedLocales[i];
|
|
7269
|
+
if (supportedSet.has(desired)) {
|
|
7270
|
+
var distance = 0 + i * 40;
|
|
7271
|
+
result.distances[desired] = (_a = {}, _a[desired] = distance, _a);
|
|
7242
7272
|
if (distance < lowestDistance) {
|
|
7243
7273
|
lowestDistance = distance;
|
|
7244
7274
|
result.matchedDesiredLocale = desired;
|
|
7245
|
-
result.matchedSupportedLocale =
|
|
7275
|
+
result.matchedSupportedLocale = desired;
|
|
7276
|
+
}
|
|
7277
|
+
if (i === 0) {
|
|
7278
|
+
return result;
|
|
7279
|
+
}
|
|
7280
|
+
}
|
|
7281
|
+
}
|
|
7282
|
+
for (var i = 0; i < requestedLocales.length; i++) {
|
|
7283
|
+
var desired = requestedLocales[i];
|
|
7284
|
+
try {
|
|
7285
|
+
var maximized = new Intl.Locale(desired).maximize().toString();
|
|
7286
|
+
if (maximized !== desired) {
|
|
7287
|
+
var maximizedCandidates = getFallbackCandidates(maximized);
|
|
7288
|
+
for (var j = 0; j < maximizedCandidates.length; j++) {
|
|
7289
|
+
var candidate = maximizedCandidates[j];
|
|
7290
|
+
if (candidate === desired)
|
|
7291
|
+
continue;
|
|
7292
|
+
if (supportedSet.has(candidate)) {
|
|
7293
|
+
var distance = void 0;
|
|
7294
|
+
try {
|
|
7295
|
+
var candidateMaximized = new Intl.Locale(candidate).maximize().toString();
|
|
7296
|
+
distance = candidateMaximized === maximized ? 0 + i * 40 : j * 10 + i * 40;
|
|
7297
|
+
} catch (_b) {
|
|
7298
|
+
distance = j * 10 + i * 40;
|
|
7299
|
+
}
|
|
7300
|
+
if (!result.distances[desired]) {
|
|
7301
|
+
result.distances[desired] = {};
|
|
7302
|
+
}
|
|
7303
|
+
result.distances[desired][candidate] = distance;
|
|
7304
|
+
if (distance < lowestDistance) {
|
|
7305
|
+
lowestDistance = distance;
|
|
7306
|
+
result.matchedDesiredLocale = desired;
|
|
7307
|
+
result.matchedSupportedLocale = candidate;
|
|
7308
|
+
}
|
|
7309
|
+
break;
|
|
7310
|
+
}
|
|
7311
|
+
}
|
|
7312
|
+
}
|
|
7313
|
+
} catch (_c) {
|
|
7314
|
+
}
|
|
7315
|
+
}
|
|
7316
|
+
if (result.matchedSupportedLocale && lowestDistance === 0) {
|
|
7317
|
+
return result;
|
|
7318
|
+
}
|
|
7319
|
+
requestedLocales.forEach(function(desired2, i2) {
|
|
7320
|
+
if (!result.distances[desired2]) {
|
|
7321
|
+
result.distances[desired2] = {};
|
|
7322
|
+
}
|
|
7323
|
+
canonicalizedSupportedLocales.forEach(function(canonicalLocale, supportedIndex) {
|
|
7324
|
+
var originalSupported = supportedLocales2[supportedIndex];
|
|
7325
|
+
var distance2 = findMatchingDistance(desired2, canonicalLocale);
|
|
7326
|
+
var finalDistance = distance2 + 0 + i2 * 40;
|
|
7327
|
+
result.distances[desired2][originalSupported] = finalDistance;
|
|
7328
|
+
if (finalDistance < lowestDistance) {
|
|
7329
|
+
lowestDistance = finalDistance;
|
|
7330
|
+
result.matchedDesiredLocale = desired2;
|
|
7331
|
+
result.matchedSupportedLocale = originalSupported;
|
|
7246
7332
|
}
|
|
7247
7333
|
});
|
|
7248
7334
|
});
|
|
@@ -7323,10 +7409,16 @@
|
|
|
7323
7409
|
}
|
|
7324
7410
|
|
|
7325
7411
|
// node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/abstract/BestAvailableLocale.js
|
|
7412
|
+
var availableLocalesSetCache = /* @__PURE__ */ new WeakMap();
|
|
7326
7413
|
function BestAvailableLocale(availableLocales, locale) {
|
|
7414
|
+
var availableSet = availableLocalesSetCache.get(availableLocales);
|
|
7415
|
+
if (!availableSet) {
|
|
7416
|
+
availableSet = new Set(availableLocales);
|
|
7417
|
+
availableLocalesSetCache.set(availableLocales, availableSet);
|
|
7418
|
+
}
|
|
7327
7419
|
var candidate = locale;
|
|
7328
7420
|
while (true) {
|
|
7329
|
-
if (
|
|
7421
|
+
if (availableSet.has(candidate)) {
|
|
7330
7422
|
return candidate;
|
|
7331
7423
|
}
|
|
7332
7424
|
var pos = candidate.lastIndexOf("-");
|