@formatjs/intl-listformat 9.0.0 → 9.0.1
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 +2 -2
- package/polyfill.iife.js +28 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl-listformat",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"description": "Formats JS list in a i18n-safe way",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"format",
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"./should-polyfill.js": "./should-polyfill.js"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@formatjs/intl-localematcher": "0.10.
|
|
32
|
+
"@formatjs/intl-localematcher": "0.10.1"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/polyfill.iife.js
CHANGED
|
@@ -2449,16 +2449,23 @@ function distance(desired, supported) {
|
|
|
2449
2449
|
/** ICU language/script/region distance, including fractional explicit-subtag ties. */
|
|
2450
2450
|
const findMatchingDistance = memoize((desired, supported) => distance(maximal(canonicalize(desired)), maximal(canonicalize(supported))), { serializer: (args) => `${args[0]}|${args[1]}` });
|
|
2451
2451
|
const supportedCache = /* @__PURE__ */ new WeakMap();
|
|
2452
|
+
const immutableLocaleLists = /* @__PURE__ */ new WeakSet();
|
|
2452
2453
|
let paradigms;
|
|
2454
|
+
function createLocaleListSnapshot(locales) {
|
|
2455
|
+
const snapshot = Object.freeze(Array.from(locales));
|
|
2456
|
+
immutableLocaleLists.add(snapshot);
|
|
2457
|
+
return snapshot;
|
|
2458
|
+
}
|
|
2453
2459
|
function equivalentKey(lsr) {
|
|
2454
2460
|
return `${lsr.language}|${lsr.script}|${lsr.region}`;
|
|
2455
2461
|
}
|
|
2456
2462
|
function prepare(locales) {
|
|
2463
|
+
const immutable = immutableLocaleLists.has(locales);
|
|
2457
2464
|
let result = supportedCache.get(locales);
|
|
2458
|
-
if (result && (result.original.length !== locales.length || result.original.some((tag, index) => tag !== locales[index]))) result = void 0;
|
|
2465
|
+
if (result && !immutable && (result.original.length !== locales.length || result.original.some((tag, index) => tag !== locales[index]))) result = void 0;
|
|
2459
2466
|
if (!result) {
|
|
2460
2467
|
result = {
|
|
2461
|
-
original: Array.from(locales),
|
|
2468
|
+
original: immutable ? locales : Array.from(locales),
|
|
2462
2469
|
tags: [],
|
|
2463
2470
|
raw: /* @__PURE__ */ new Map(),
|
|
2464
2471
|
orders: /* @__PURE__ */ new Map(),
|
|
@@ -2964,22 +2971,28 @@ function UnicodeExtensionComponents(extension) {
|
|
|
2964
2971
|
};
|
|
2965
2972
|
}
|
|
2966
2973
|
const availableLocaleArrays = /* @__PURE__ */ new WeakMap();
|
|
2967
|
-
function localeArray(locales) {
|
|
2974
|
+
function localeArray(locales, bestFit) {
|
|
2968
2975
|
if (Array.isArray(locales)) return locales;
|
|
2969
2976
|
const available = locales;
|
|
2970
|
-
|
|
2971
|
-
if (cached?.length
|
|
2977
|
+
let cached = availableLocaleArrays.get(available);
|
|
2978
|
+
if (cached?.original.length !== available.size) cached = void 0;
|
|
2979
|
+
if (cached) {
|
|
2980
|
+
const original = cached.original;
|
|
2972
2981
|
let index = 0;
|
|
2973
|
-
for (const locale of available) if (
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
return result;
|
|
2982
|
+
for (const locale of available) if (original[index++] !== locale) {
|
|
2983
|
+
cached = void 0;
|
|
2984
|
+
break;
|
|
2977
2985
|
}
|
|
2978
|
-
return cached;
|
|
2979
2986
|
}
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2987
|
+
if (!cached) {
|
|
2988
|
+
cached = {
|
|
2989
|
+
original: Array.from(available),
|
|
2990
|
+
snapshot: void 0
|
|
2991
|
+
};
|
|
2992
|
+
availableLocaleArrays.set(available, cached);
|
|
2993
|
+
}
|
|
2994
|
+
if (!bestFit) return cached.original;
|
|
2995
|
+
return cached.snapshot ??= createLocaleListSnapshot(cached.original);
|
|
2983
2996
|
}
|
|
2984
2997
|
/**
|
|
2985
2998
|
* https://tc39.es/ecma402/#sec-resolvelocale
|
|
@@ -2987,8 +3000,8 @@ function localeArray(locales) {
|
|
|
2987
3000
|
function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale) {
|
|
2988
3001
|
const matcher = options.localeMatcher;
|
|
2989
3002
|
let r;
|
|
2990
|
-
if (matcher === "lookup") r = LookupMatcher(localeArray(availableLocales), requestedLocales, getDefaultLocale);
|
|
2991
|
-
else r = BestFitMatcher(localeArray(availableLocales), requestedLocales, getDefaultLocale);
|
|
3003
|
+
if (matcher === "lookup") r = LookupMatcher(localeArray(availableLocales, false), requestedLocales, getDefaultLocale);
|
|
3004
|
+
else r = BestFitMatcher(localeArray(availableLocales, true), requestedLocales, getDefaultLocale);
|
|
2992
3005
|
if (r == null) r = {
|
|
2993
3006
|
locale: getDefaultLocale(),
|
|
2994
3007
|
extension: ""
|