@formatjs/intl-relativetimeformat 13.0.0 → 13.0.2

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.
Files changed (2) hide show
  1. package/package.json +8 -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.0",
3
+ "version": "13.0.2",
4
4
  "description": "Formats JavaScript dates to relative time strings.",
5
5
  "keywords": [
6
6
  "date",
@@ -20,6 +20,12 @@
20
20
  "url": "git@github.com:formatjs/formatjs.git"
21
21
  },
22
22
  "type": "module",
23
+ "sideEffects": [
24
+ "./polyfill.js",
25
+ "./polyfill-force.js",
26
+ "./polyfill.iife.js",
27
+ "./locale-data/*.js"
28
+ ],
23
29
  "types": "index.d.ts",
24
30
  "exports": {
25
31
  ".": "./index.js",
@@ -30,6 +36,6 @@
30
36
  "./should-polyfill.js": "./should-polyfill.js"
31
37
  },
32
38
  "dependencies": {
33
- "@formatjs/intl-localematcher": "0.10.0"
39
+ "@formatjs/intl-localematcher": "0.10.1"
34
40
  }
35
41
  }
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
- const cached = availableLocaleArrays.get(available);
2862
- if (cached?.length === available.size) {
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 (cached[index++] !== locale) {
2865
- const result = Array.from(available);
2866
- availableLocaleArrays.set(available, result);
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
- const result = Array.from(available);
2872
- availableLocaleArrays.set(available, result);
2873
- return result;
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: ""