@formatjs/intl-getcanonicallocales 3.2.8 → 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formatjs/intl-getcanonicallocales",
3
3
  "description": "Intl.getCanonicalLocales polyfill",
4
- "version": "3.2.8",
4
+ "version": "3.2.9",
5
5
  "license": "MIT",
6
6
  "author": "Long Ho <holevietlong@gmail.com>",
7
7
  "type": "module",
package/polyfill-force.js CHANGED
@@ -9345,17 +9345,97 @@ function getCanonicalLocales(locales) {
9345
9345
  return CanonicalizeLocaleList(locales);
9346
9346
  }
9347
9347
  //#endregion
9348
- //#region packages/intl-getcanonicallocales/polyfill-force.ts
9349
- if (typeof Intl === "undefined") {
9350
- if (typeof window !== "undefined") Object.defineProperty(window, "Intl", { value: {} });
9351
- else if (typeof global !== "undefined") Object.defineProperty(global, "Intl", { value: {} });
9348
+ //#region node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js
9349
+ function memoize(fn, options) {
9350
+ const cache = options && options.cache ? options.cache : cacheDefault;
9351
+ const serializer = options && options.serializer ? options.serializer : serializerDefault;
9352
+ return (options && options.strategy ? options.strategy : strategyDefault)(fn, {
9353
+ cache,
9354
+ serializer
9355
+ });
9356
+ }
9357
+ function isPrimitive(value) {
9358
+ return value == null || typeof value === "number" || typeof value === "boolean";
9359
+ }
9360
+ function monadic(fn, cache, serializer, arg) {
9361
+ const cacheKey = isPrimitive(arg) ? arg : serializer(arg);
9362
+ let computedValue = cache.get(cacheKey);
9363
+ if (typeof computedValue === "undefined") {
9364
+ computedValue = fn.call(this, arg);
9365
+ cache.set(cacheKey, computedValue);
9366
+ }
9367
+ return computedValue;
9368
+ }
9369
+ function variadic(fn, cache, serializer) {
9370
+ const args = Array.prototype.slice.call(arguments, 3);
9371
+ const cacheKey = serializer(args);
9372
+ let computedValue = cache.get(cacheKey);
9373
+ if (typeof computedValue === "undefined") {
9374
+ computedValue = fn.apply(this, args);
9375
+ cache.set(cacheKey, computedValue);
9376
+ }
9377
+ return computedValue;
9352
9378
  }
9353
- Object.defineProperty(Intl, "getCanonicalLocales", {
9354
- value: getCanonicalLocales,
9355
- writable: true,
9356
- enumerable: false,
9357
- configurable: true
9358
- });
9379
+ function assemble(fn, context, strategy, cache, serialize) {
9380
+ return strategy.bind(context, fn, cache, serialize);
9381
+ }
9382
+ function strategyDefault(fn, options) {
9383
+ const strategy = fn.length === 1 ? monadic : variadic;
9384
+ return assemble(fn, this, strategy, options.cache.create(), options.serializer);
9385
+ }
9386
+ function strategyVariadic(fn, options) {
9387
+ return assemble(fn, this, variadic, options.cache.create(), options.serializer);
9388
+ }
9389
+ function strategyMonadic(fn, options) {
9390
+ return assemble(fn, this, monadic, options.cache.create(), options.serializer);
9391
+ }
9392
+ const serializerDefault = function() {
9393
+ return JSON.stringify(arguments);
9394
+ };
9395
+ var ObjectWithoutPrototypeCache = class {
9396
+ constructor() {
9397
+ this.cache = Object.create(null);
9398
+ }
9399
+ get(key) {
9400
+ return this.cache[key];
9401
+ }
9402
+ set(key, value) {
9403
+ this.cache[key] = value;
9404
+ }
9405
+ };
9406
+ const cacheDefault = { create: function create() {
9407
+ return new ObjectWithoutPrototypeCache();
9408
+ } };
9409
+ const strategies = {
9410
+ variadic: strategyVariadic,
9411
+ monadic: strategyMonadic
9412
+ };
9413
+ //#endregion
9414
+ //#region packages/ecma402-abstract/utils.js
9415
+ function defineProperty(target, name, { value }) {
9416
+ Object.defineProperty(target, name, {
9417
+ configurable: true,
9418
+ enumerable: false,
9419
+ writable: true,
9420
+ value
9421
+ });
9422
+ }
9423
+ function ensureIntl() {
9424
+ if (typeof Intl === "undefined") Object.defineProperty(globalThis, "Intl", {
9425
+ configurable: true,
9426
+ enumerable: false,
9427
+ writable: true,
9428
+ value: {}
9429
+ });
9430
+ return Intl;
9431
+ }
9432
+ memoize((...args) => new Intl.NumberFormat(...args), { strategy: strategies.variadic });
9433
+ memoize((...args) => new Intl.PluralRules(...args), { strategy: strategies.variadic });
9434
+ memoize((...args) => new Intl.Locale(...args), { strategy: strategies.variadic });
9435
+ memoize((...args) => new Intl.ListFormat(...args), { strategy: strategies.variadic });
9436
+ //#endregion
9437
+ //#region packages/intl-getcanonicallocales/polyfill-force.ts
9438
+ defineProperty(ensureIntl(), "getCanonicalLocales", { value: getCanonicalLocales });
9359
9439
  //#endregion
9360
9440
 
9361
9441
  //# sourceMappingURL=polyfill-force.js.map