@formatjs/intl-relativetimeformat 13.0.0 → 13.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-relativetimeformat",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.1",
|
|
4
4
|
"description": "Formats JavaScript dates to relative time strings.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"date",
|
|
@@ -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
|
@@ -2340,16 +2340,23 @@ function distance(desired, supported) {
|
|
|
2340
2340
|
/** ICU language/script/region distance, including fractional explicit-subtag ties. */
|
|
2341
2341
|
const findMatchingDistance = memoize((desired, supported) => distance(maximal(canonicalize(desired)), maximal(canonicalize(supported))), { serializer: (args) => `${args[0]}|${args[1]}` });
|
|
2342
2342
|
const supportedCache = /* @__PURE__ */ new WeakMap();
|
|
2343
|
+
const immutableLocaleLists = /* @__PURE__ */ new WeakSet();
|
|
2343
2344
|
let paradigms;
|
|
2345
|
+
function createLocaleListSnapshot(locales) {
|
|
2346
|
+
const snapshot = Object.freeze(Array.from(locales));
|
|
2347
|
+
immutableLocaleLists.add(snapshot);
|
|
2348
|
+
return snapshot;
|
|
2349
|
+
}
|
|
2344
2350
|
function equivalentKey(lsr) {
|
|
2345
2351
|
return `${lsr.language}|${lsr.script}|${lsr.region}`;
|
|
2346
2352
|
}
|
|
2347
2353
|
function prepare(locales) {
|
|
2354
|
+
const immutable = immutableLocaleLists.has(locales);
|
|
2348
2355
|
let result = supportedCache.get(locales);
|
|
2349
|
-
if (result && (result.original.length !== locales.length || result.original.some((tag, index) => tag !== locales[index]))) result = void 0;
|
|
2356
|
+
if (result && !immutable && (result.original.length !== locales.length || result.original.some((tag, index) => tag !== locales[index]))) result = void 0;
|
|
2350
2357
|
if (!result) {
|
|
2351
2358
|
result = {
|
|
2352
|
-
original: Array.from(locales),
|
|
2359
|
+
original: immutable ? locales : Array.from(locales),
|
|
2353
2360
|
tags: [],
|
|
2354
2361
|
raw: /* @__PURE__ */ new Map(),
|
|
2355
2362
|
orders: /* @__PURE__ */ new Map(),
|
|
@@ -2855,22 +2862,28 @@ function UnicodeExtensionComponents(extension) {
|
|
|
2855
2862
|
};
|
|
2856
2863
|
}
|
|
2857
2864
|
const availableLocaleArrays = /* @__PURE__ */ new WeakMap();
|
|
2858
|
-
function localeArray(locales) {
|
|
2865
|
+
function localeArray(locales, bestFit) {
|
|
2859
2866
|
if (Array.isArray(locales)) return locales;
|
|
2860
2867
|
const available = locales;
|
|
2861
|
-
|
|
2862
|
-
if (cached?.length
|
|
2868
|
+
let cached = availableLocaleArrays.get(available);
|
|
2869
|
+
if (cached?.original.length !== available.size) cached = void 0;
|
|
2870
|
+
if (cached) {
|
|
2871
|
+
const original = cached.original;
|
|
2863
2872
|
let index = 0;
|
|
2864
|
-
for (const locale of available) if (
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
return result;
|
|
2873
|
+
for (const locale of available) if (original[index++] !== locale) {
|
|
2874
|
+
cached = void 0;
|
|
2875
|
+
break;
|
|
2868
2876
|
}
|
|
2869
|
-
return cached;
|
|
2870
2877
|
}
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2878
|
+
if (!cached) {
|
|
2879
|
+
cached = {
|
|
2880
|
+
original: Array.from(available),
|
|
2881
|
+
snapshot: void 0
|
|
2882
|
+
};
|
|
2883
|
+
availableLocaleArrays.set(available, cached);
|
|
2884
|
+
}
|
|
2885
|
+
if (!bestFit) return cached.original;
|
|
2886
|
+
return cached.snapshot ??= createLocaleListSnapshot(cached.original);
|
|
2874
2887
|
}
|
|
2875
2888
|
/**
|
|
2876
2889
|
* https://tc39.es/ecma402/#sec-resolvelocale
|
|
@@ -2878,8 +2891,8 @@ function localeArray(locales) {
|
|
|
2878
2891
|
function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale) {
|
|
2879
2892
|
const matcher = options.localeMatcher;
|
|
2880
2893
|
let r;
|
|
2881
|
-
if (matcher === "lookup") r = LookupMatcher(localeArray(availableLocales), requestedLocales, getDefaultLocale);
|
|
2882
|
-
else r = BestFitMatcher(localeArray(availableLocales), requestedLocales, getDefaultLocale);
|
|
2894
|
+
if (matcher === "lookup") r = LookupMatcher(localeArray(availableLocales, false), requestedLocales, getDefaultLocale);
|
|
2895
|
+
else r = BestFitMatcher(localeArray(availableLocales, true), requestedLocales, getDefaultLocale);
|
|
2883
2896
|
if (r == null) r = {
|
|
2884
2897
|
locale: getDefaultLocale(),
|
|
2885
2898
|
extension: ""
|