@formatjs/intl-displaynames 8.0.0 → 8.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-displaynames",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "Polyfill for: https://tc39.es/proposal-intl-displaynames",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Intl",
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
"./should-polyfill.js": "./should-polyfill.js"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@formatjs/intl-localematcher": "0.10.
|
|
33
|
+
"@formatjs/intl-localematcher": "0.10.1"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/polyfill.iife.js
CHANGED
|
@@ -2397,16 +2397,23 @@ function distance(desired, supported) {
|
|
|
2397
2397
|
/** ICU language/script/region distance, including fractional explicit-subtag ties. */
|
|
2398
2398
|
const findMatchingDistance = memoize((desired, supported) => distance(maximal(canonicalize(desired)), maximal(canonicalize(supported))), { serializer: (args) => `${args[0]}|${args[1]}` });
|
|
2399
2399
|
const supportedCache = /* @__PURE__ */ new WeakMap();
|
|
2400
|
+
const immutableLocaleLists = /* @__PURE__ */ new WeakSet();
|
|
2400
2401
|
let paradigms;
|
|
2402
|
+
function createLocaleListSnapshot(locales) {
|
|
2403
|
+
const snapshot = Object.freeze(Array.from(locales));
|
|
2404
|
+
immutableLocaleLists.add(snapshot);
|
|
2405
|
+
return snapshot;
|
|
2406
|
+
}
|
|
2401
2407
|
function equivalentKey(lsr) {
|
|
2402
2408
|
return `${lsr.language}|${lsr.script}|${lsr.region}`;
|
|
2403
2409
|
}
|
|
2404
2410
|
function prepare(locales) {
|
|
2411
|
+
const immutable = immutableLocaleLists.has(locales);
|
|
2405
2412
|
let result = supportedCache.get(locales);
|
|
2406
|
-
if (result && (result.original.length !== locales.length || result.original.some((tag, index) => tag !== locales[index]))) result = void 0;
|
|
2413
|
+
if (result && !immutable && (result.original.length !== locales.length || result.original.some((tag, index) => tag !== locales[index]))) result = void 0;
|
|
2407
2414
|
if (!result) {
|
|
2408
2415
|
result = {
|
|
2409
|
-
original: Array.from(locales),
|
|
2416
|
+
original: immutable ? locales : Array.from(locales),
|
|
2410
2417
|
tags: [],
|
|
2411
2418
|
raw: /* @__PURE__ */ new Map(),
|
|
2412
2419
|
orders: /* @__PURE__ */ new Map(),
|
|
@@ -2912,22 +2919,28 @@ function UnicodeExtensionComponents(extension) {
|
|
|
2912
2919
|
};
|
|
2913
2920
|
}
|
|
2914
2921
|
const availableLocaleArrays = /* @__PURE__ */ new WeakMap();
|
|
2915
|
-
function localeArray(locales) {
|
|
2922
|
+
function localeArray(locales, bestFit) {
|
|
2916
2923
|
if (Array.isArray(locales)) return locales;
|
|
2917
2924
|
const available = locales;
|
|
2918
|
-
|
|
2919
|
-
if (cached?.length
|
|
2925
|
+
let cached = availableLocaleArrays.get(available);
|
|
2926
|
+
if (cached?.original.length !== available.size) cached = void 0;
|
|
2927
|
+
if (cached) {
|
|
2928
|
+
const original = cached.original;
|
|
2920
2929
|
let index = 0;
|
|
2921
|
-
for (const locale of available) if (
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
return result;
|
|
2930
|
+
for (const locale of available) if (original[index++] !== locale) {
|
|
2931
|
+
cached = void 0;
|
|
2932
|
+
break;
|
|
2925
2933
|
}
|
|
2926
|
-
return cached;
|
|
2927
2934
|
}
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2935
|
+
if (!cached) {
|
|
2936
|
+
cached = {
|
|
2937
|
+
original: Array.from(available),
|
|
2938
|
+
snapshot: void 0
|
|
2939
|
+
};
|
|
2940
|
+
availableLocaleArrays.set(available, cached);
|
|
2941
|
+
}
|
|
2942
|
+
if (!bestFit) return cached.original;
|
|
2943
|
+
return cached.snapshot ??= createLocaleListSnapshot(cached.original);
|
|
2931
2944
|
}
|
|
2932
2945
|
/**
|
|
2933
2946
|
* https://tc39.es/ecma402/#sec-resolvelocale
|
|
@@ -2935,8 +2948,8 @@ function localeArray(locales) {
|
|
|
2935
2948
|
function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale) {
|
|
2936
2949
|
const matcher = options.localeMatcher;
|
|
2937
2950
|
let r;
|
|
2938
|
-
if (matcher === "lookup") r = LookupMatcher(localeArray(availableLocales), requestedLocales, getDefaultLocale);
|
|
2939
|
-
else r = BestFitMatcher(localeArray(availableLocales), requestedLocales, getDefaultLocale);
|
|
2951
|
+
if (matcher === "lookup") r = LookupMatcher(localeArray(availableLocales, false), requestedLocales, getDefaultLocale);
|
|
2952
|
+
else r = BestFitMatcher(localeArray(availableLocales, true), requestedLocales, getDefaultLocale);
|
|
2940
2953
|
if (r == null) r = {
|
|
2941
2954
|
locale: getDefaultLocale(),
|
|
2942
2955
|
extension: ""
|