@formatjs/intl-getcanonicallocales 3.2.7 → 3.2.9

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/polyfill.iife.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { languageAlias, scriptAlias, territoryAlias, variantAlias } from "@formatjs_generated/cldr.core/aliases.js";
2
2
  import { likelySubtags } from "@formatjs_generated/cldr.core/likelySubtags.js";
3
+ import { defineProperty, ensureIntl } from "#packages/ecma402-abstract/utils.js";
3
4
  //#region packages/intl-getcanonicallocales/emitter.ts
4
5
  function emitUnicodeLanguageId(lang) {
5
6
  if (!lang) return "";
@@ -410,16 +411,8 @@ function shouldPolyfill() {
410
411
  }
411
412
  //#endregion
412
413
  //#region packages/intl-getcanonicallocales/polyfill.ts
413
- if (typeof Intl === "undefined") {
414
- if (typeof window !== "undefined") Object.defineProperty(window, "Intl", { value: {} });
415
- else if (typeof global !== "undefined") Object.defineProperty(global, "Intl", { value: {} });
416
- }
417
- if (shouldPolyfill()) Object.defineProperty(Intl, "getCanonicalLocales", {
418
- value: getCanonicalLocales,
419
- writable: true,
420
- enumerable: false,
421
- configurable: true
422
- });
414
+ const intl = ensureIntl();
415
+ if (shouldPolyfill()) defineProperty(intl, "getCanonicalLocales", { value: getCanonicalLocales });
423
416
  //#endregion
424
417
 
425
418
  //# sourceMappingURL=polyfill.iife.js.map
package/polyfill.js CHANGED
@@ -9350,17 +9350,98 @@ function shouldPolyfill() {
9350
9350
  return typeof Intl === "undefined" || !("getCanonicalLocales" in Intl) || Intl.getCanonicalLocales("und-x-private")[0] === "x-private";
9351
9351
  }
9352
9352
  //#endregion
9353
- //#region packages/intl-getcanonicallocales/polyfill.ts
9354
- if (typeof Intl === "undefined") {
9355
- if (typeof window !== "undefined") Object.defineProperty(window, "Intl", { value: {} });
9356
- else if (typeof global !== "undefined") Object.defineProperty(global, "Intl", { value: {} });
9353
+ //#region node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js
9354
+ function memoize(fn, options) {
9355
+ const cache = options && options.cache ? options.cache : cacheDefault;
9356
+ const serializer = options && options.serializer ? options.serializer : serializerDefault;
9357
+ return (options && options.strategy ? options.strategy : strategyDefault)(fn, {
9358
+ cache,
9359
+ serializer
9360
+ });
9361
+ }
9362
+ function isPrimitive(value) {
9363
+ return value == null || typeof value === "number" || typeof value === "boolean";
9364
+ }
9365
+ function monadic(fn, cache, serializer, arg) {
9366
+ const cacheKey = isPrimitive(arg) ? arg : serializer(arg);
9367
+ let computedValue = cache.get(cacheKey);
9368
+ if (typeof computedValue === "undefined") {
9369
+ computedValue = fn.call(this, arg);
9370
+ cache.set(cacheKey, computedValue);
9371
+ }
9372
+ return computedValue;
9373
+ }
9374
+ function variadic(fn, cache, serializer) {
9375
+ const args = Array.prototype.slice.call(arguments, 3);
9376
+ const cacheKey = serializer(args);
9377
+ let computedValue = cache.get(cacheKey);
9378
+ if (typeof computedValue === "undefined") {
9379
+ computedValue = fn.apply(this, args);
9380
+ cache.set(cacheKey, computedValue);
9381
+ }
9382
+ return computedValue;
9357
9383
  }
9358
- if (shouldPolyfill()) Object.defineProperty(Intl, "getCanonicalLocales", {
9359
- value: getCanonicalLocales,
9360
- writable: true,
9361
- enumerable: false,
9362
- configurable: true
9363
- });
9384
+ function assemble(fn, context, strategy, cache, serialize) {
9385
+ return strategy.bind(context, fn, cache, serialize);
9386
+ }
9387
+ function strategyDefault(fn, options) {
9388
+ const strategy = fn.length === 1 ? monadic : variadic;
9389
+ return assemble(fn, this, strategy, options.cache.create(), options.serializer);
9390
+ }
9391
+ function strategyVariadic(fn, options) {
9392
+ return assemble(fn, this, variadic, options.cache.create(), options.serializer);
9393
+ }
9394
+ function strategyMonadic(fn, options) {
9395
+ return assemble(fn, this, monadic, options.cache.create(), options.serializer);
9396
+ }
9397
+ const serializerDefault = function() {
9398
+ return JSON.stringify(arguments);
9399
+ };
9400
+ var ObjectWithoutPrototypeCache = class {
9401
+ constructor() {
9402
+ this.cache = Object.create(null);
9403
+ }
9404
+ get(key) {
9405
+ return this.cache[key];
9406
+ }
9407
+ set(key, value) {
9408
+ this.cache[key] = value;
9409
+ }
9410
+ };
9411
+ const cacheDefault = { create: function create() {
9412
+ return new ObjectWithoutPrototypeCache();
9413
+ } };
9414
+ const strategies = {
9415
+ variadic: strategyVariadic,
9416
+ monadic: strategyMonadic
9417
+ };
9418
+ //#endregion
9419
+ //#region packages/ecma402-abstract/utils.js
9420
+ function defineProperty(target, name, { value }) {
9421
+ Object.defineProperty(target, name, {
9422
+ configurable: true,
9423
+ enumerable: false,
9424
+ writable: true,
9425
+ value
9426
+ });
9427
+ }
9428
+ function ensureIntl() {
9429
+ if (typeof Intl === "undefined") Object.defineProperty(globalThis, "Intl", {
9430
+ configurable: true,
9431
+ enumerable: false,
9432
+ writable: true,
9433
+ value: {}
9434
+ });
9435
+ return Intl;
9436
+ }
9437
+ memoize((...args) => new Intl.NumberFormat(...args), { strategy: strategies.variadic });
9438
+ memoize((...args) => new Intl.PluralRules(...args), { strategy: strategies.variadic });
9439
+ memoize((...args) => new Intl.Locale(...args), { strategy: strategies.variadic });
9440
+ memoize((...args) => new Intl.ListFormat(...args), { strategy: strategies.variadic });
9441
+ //#endregion
9442
+ //#region packages/intl-getcanonicallocales/polyfill.ts
9443
+ const intl = ensureIntl();
9444
+ if (shouldPolyfill()) defineProperty(intl, "getCanonicalLocales", { value: getCanonicalLocales });
9364
9445
  //#endregion
9365
9446
 
9366
9447
  //# sourceMappingURL=polyfill.js.map