@formatjs/intl-numberformat 8.10.3 → 8.11.0

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/lib/src/core.js CHANGED
@@ -1,4 +1,4 @@
1
- import { CanonicalizeLocaleList, FormatNumericRange, FormatNumericRangeToParts, FormatNumericToParts, InitializeNumberFormat, OrdinaryHasInstance, SupportedLocales, ToNumber, defineProperty, invariant, } from '@formatjs/ecma402-abstract';
1
+ import { CanonicalizeLocaleList, FormatNumericRange, FormatNumericRangeToParts, FormatNumericToParts, InitializeNumberFormat, OrdinaryHasInstance, SupportedLocales, ToNumber, createMemoizedPluralRules, defineProperty, invariant, } from '@formatjs/ecma402-abstract';
2
2
  import { currencyDigitsData } from './currency-digits.generated';
3
3
  import { numberingSystemNames } from './numbering-systems.generated';
4
4
  // eslint-disable-next-line import/no-cycle
@@ -42,7 +42,7 @@ export var NumberFormat = function (locales, options) {
42
42
  var dataLocale = internalSlots.dataLocale;
43
43
  var dataLocaleData = NumberFormat.localeData[dataLocale];
44
44
  invariant(dataLocaleData !== undefined, "Cannot load locale-dependent data for ".concat(dataLocale, "."));
45
- internalSlots.pl = new Intl.PluralRules(dataLocale, {
45
+ internalSlots.pl = createMemoizedPluralRules(dataLocale, {
46
46
  minimumFractionDigits: internalSlots.minimumFractionDigits,
47
47
  maximumFractionDigits: internalSlots.maximumFractionDigits,
48
48
  minimumIntegerDigits: internalSlots.minimumIntegerDigits,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-numberformat",
3
- "version": "8.10.3",
3
+ "version": "8.11.0",
4
4
  "description": "Ponyfill for ES2020 Intl.NumberFormat",
5
5
  "keywords": [
6
6
  "polyfill",
@@ -24,12 +24,12 @@
24
24
  "dependencies": {
25
25
  "tslib": "^2.4.0",
26
26
  "@formatjs/intl-localematcher": "0.5.4",
27
- "@formatjs/ecma402-abstract": "2.0.0"
27
+ "@formatjs/ecma402-abstract": "2.1.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@formatjs/intl-pluralrules": "5.2.14",
31
- "@formatjs/intl-getcanonicallocales": "2.3.0",
32
- "@formatjs/intl-locale": "4.0.0"
30
+ "@formatjs/intl-locale": "4.0.1",
31
+ "@formatjs/intl-pluralrules": "5.2.15",
32
+ "@formatjs/intl-getcanonicallocales": "2.3.0"
33
33
  },
34
34
  "bugs": {
35
35
  "url": "https://github.com/formatjs/formatjs/issues"
package/polyfill.iife.js CHANGED
@@ -250,6 +250,105 @@
250
250
  return result;
251
251
  }
252
252
 
253
+ // ../../../../../../../../execroot/formatjs/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/tslib@2.4.0/node_modules/tslib/tslib.es6.js
254
+ var extendStatics = function(d, b) {
255
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
256
+ d2.__proto__ = b2;
257
+ } || function(d2, b2) {
258
+ for (var p in b2)
259
+ if (Object.prototype.hasOwnProperty.call(b2, p))
260
+ d2[p] = b2[p];
261
+ };
262
+ return extendStatics(d, b);
263
+ };
264
+ function __extends(d, b) {
265
+ if (typeof b !== "function" && b !== null)
266
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
267
+ extendStatics(d, b);
268
+ function __() {
269
+ this.constructor = d;
270
+ }
271
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
272
+ }
273
+ function __spreadArray(to, from, pack) {
274
+ if (pack || arguments.length === 2)
275
+ for (var i = 0, l = from.length, ar; i < l; i++) {
276
+ if (ar || !(i in from)) {
277
+ if (!ar)
278
+ ar = Array.prototype.slice.call(from, 0, i);
279
+ ar[i] = from[i];
280
+ }
281
+ }
282
+ return to.concat(ar || Array.prototype.slice.call(from));
283
+ }
284
+
285
+ // ../../../../../../../../execroot/formatjs/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/lib/index.js
286
+ function memoize(fn, options) {
287
+ var cache = options && options.cache ? options.cache : cacheDefault;
288
+ var serializer = options && options.serializer ? options.serializer : serializerDefault;
289
+ var strategy = options && options.strategy ? options.strategy : strategyDefault;
290
+ return strategy(fn, {
291
+ cache,
292
+ serializer
293
+ });
294
+ }
295
+ function isPrimitive(value) {
296
+ return value == null || typeof value === "number" || typeof value === "boolean";
297
+ }
298
+ function monadic(fn, cache, serializer, arg) {
299
+ var cacheKey = isPrimitive(arg) ? arg : serializer(arg);
300
+ var computedValue = cache.get(cacheKey);
301
+ if (typeof computedValue === "undefined") {
302
+ computedValue = fn.call(this, arg);
303
+ cache.set(cacheKey, computedValue);
304
+ }
305
+ return computedValue;
306
+ }
307
+ function variadic(fn, cache, serializer) {
308
+ var args = Array.prototype.slice.call(arguments, 3);
309
+ var cacheKey = serializer(args);
310
+ var computedValue = cache.get(cacheKey);
311
+ if (typeof computedValue === "undefined") {
312
+ computedValue = fn.apply(this, args);
313
+ cache.set(cacheKey, computedValue);
314
+ }
315
+ return computedValue;
316
+ }
317
+ function assemble(fn, context, strategy, cache, serialize) {
318
+ return strategy.bind(context, fn, cache, serialize);
319
+ }
320
+ function strategyDefault(fn, options) {
321
+ var strategy = fn.length === 1 ? monadic : variadic;
322
+ return assemble(fn, this, strategy, options.cache.create(), options.serializer);
323
+ }
324
+ function strategyVariadic(fn, options) {
325
+ return assemble(fn, this, variadic, options.cache.create(), options.serializer);
326
+ }
327
+ function strategyMonadic(fn, options) {
328
+ return assemble(fn, this, monadic, options.cache.create(), options.serializer);
329
+ }
330
+ var serializerDefault = function() {
331
+ return JSON.stringify(arguments);
332
+ };
333
+ function ObjectWithoutPrototypeCache() {
334
+ this.cache = /* @__PURE__ */ Object.create(null);
335
+ }
336
+ ObjectWithoutPrototypeCache.prototype.get = function(key) {
337
+ return this.cache[key];
338
+ };
339
+ ObjectWithoutPrototypeCache.prototype.set = function(key, value) {
340
+ this.cache[key] = value;
341
+ };
342
+ var cacheDefault = {
343
+ create: function create() {
344
+ return new ObjectWithoutPrototypeCache();
345
+ }
346
+ };
347
+ var strategies = {
348
+ variadic: strategyVariadic,
349
+ monadic: strategyMonadic
350
+ };
351
+
253
352
  // ../../../../../../../../execroot/formatjs/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/utils.js
254
353
  function getMagnitude(x) {
255
354
  return Math.floor(Math.log(x) * Math.LOG10E);
@@ -281,6 +380,56 @@
281
380
  throw new Err(message);
282
381
  }
283
382
  }
383
+ var createMemoizedNumberFormat = memoize(function() {
384
+ var _a;
385
+ var args = [];
386
+ for (var _i = 0; _i < arguments.length; _i++) {
387
+ args[_i] = arguments[_i];
388
+ }
389
+ return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
390
+ }, {
391
+ strategy: strategies.variadic
392
+ });
393
+ var createMemoizedDateTimeFormat = memoize(function() {
394
+ var _a;
395
+ var args = [];
396
+ for (var _i = 0; _i < arguments.length; _i++) {
397
+ args[_i] = arguments[_i];
398
+ }
399
+ return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
400
+ }, {
401
+ strategy: strategies.variadic
402
+ });
403
+ var createMemoizedPluralRules = memoize(function() {
404
+ var _a;
405
+ var args = [];
406
+ for (var _i = 0; _i < arguments.length; _i++) {
407
+ args[_i] = arguments[_i];
408
+ }
409
+ return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args, false)))();
410
+ }, {
411
+ strategy: strategies.variadic
412
+ });
413
+ var createMemoizedLocale = memoize(function() {
414
+ var _a;
415
+ var args = [];
416
+ for (var _i = 0; _i < arguments.length; _i++) {
417
+ args[_i] = arguments[_i];
418
+ }
419
+ return new ((_a = Intl.Locale).bind.apply(_a, __spreadArray([void 0], args, false)))();
420
+ }, {
421
+ strategy: strategies.variadic
422
+ });
423
+ var createMemoizedListFormat = memoize(function() {
424
+ var _a;
425
+ var args = [];
426
+ for (var _i = 0; _i < arguments.length; _i++) {
427
+ args[_i] = arguments[_i];
428
+ }
429
+ return new ((_a = Intl.ListFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
430
+ }, {
431
+ strategy: strategies.variadic
432
+ });
284
433
 
285
434
  // ../../../../../../../../execroot/formatjs/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/ComputeExponentForMagnitude.js
286
435
  function ComputeExponentForMagnitude(numberFormat, magnitude, _a) {
@@ -499,16 +648,6 @@
499
648
  return HasOwnProperty(currencyDigitsData2, c) ? currencyDigitsData2[c] : 2;
500
649
  }
501
650
 
502
- // ../../../../../../../../execroot/formatjs/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/FormatApproximately.js
503
- function FormatApproximately(numberFormat, result, _a) {
504
- var getInternalSlots2 = _a.getInternalSlots;
505
- var internalSlots = getInternalSlots2(numberFormat);
506
- var symbols = internalSlots.dataLocaleData.numbers.symbols[internalSlots.numberingSystem];
507
- var approximatelySign = symbols.approximatelySign;
508
- result.push({ type: "approximatelySign", value: approximatelySign });
509
- return result;
510
- }
511
-
512
651
  // ../../../../../../../../execroot/formatjs/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/regex.generated.js
513
652
  var S_UNICODE_REGEX = /[\$\+<->\^`\|~\xA2-\xA6\xA8\xA9\xAC\xAE-\xB1\xB4\xB8\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0384\u0385\u03F6\u0482\u058D-\u058F\u0606-\u0608\u060B\u060E\u060F\u06DE\u06E9\u06FD\u06FE\u07F6\u07FE\u07FF\u09F2\u09F3\u09FA\u09FB\u0AF1\u0B70\u0BF3-\u0BFA\u0C7F\u0D4F\u0D79\u0E3F\u0F01-\u0F03\u0F13\u0F15-\u0F17\u0F1A-\u0F1F\u0F34\u0F36\u0F38\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE\u0FCF\u0FD5-\u0FD8\u109E\u109F\u1390-\u1399\u166D\u17DB\u1940\u19DE-\u19FF\u1B61-\u1B6A\u1B74-\u1B7C\u1FBD\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF\u1FFD\u1FFE\u2044\u2052\u207A-\u207C\u208A-\u208C\u20A0-\u20BF\u2100\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F\u218A\u218B\u2190-\u2307\u230C-\u2328\u232B-\u2426\u2440-\u244A\u249C-\u24E9\u2500-\u2767\u2794-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2B73\u2B76-\u2B95\u2B97-\u2BFF\u2CE5-\u2CEA\u2E50\u2E51\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3004\u3012\u3013\u3020\u3036\u3037\u303E\u303F\u309B\u309C\u3190\u3191\u3196-\u319F\u31C0-\u31E3\u3200-\u321E\u322A-\u3247\u3250\u3260-\u327F\u328A-\u32B0\u32C0-\u33FF\u4DC0-\u4DFF\uA490-\uA4C6\uA700-\uA716\uA720\uA721\uA789\uA78A\uA828-\uA82B\uA836-\uA839\uAA77-\uAA79\uAB5B\uAB6A\uAB6B\uFB29\uFBB2-\uFBC1\uFDFC\uFDFD\uFE62\uFE64-\uFE66\uFE69\uFF04\uFF0B\uFF1C-\uFF1E\uFF3E\uFF40\uFF5C\uFF5E\uFFE0-\uFFE6\uFFE8-\uFFEE\uFFFC\uFFFD]|\uD800[\uDD37-\uDD3F\uDD79-\uDD89\uDD8C-\uDD8E\uDD90-\uDD9C\uDDA0\uDDD0-\uDDFC]|\uD802[\uDC77\uDC78\uDEC8]|\uD805\uDF3F|\uD807[\uDFD5-\uDFF1]|\uD81A[\uDF3C-\uDF3F\uDF45]|\uD82F\uDC9C|\uD834[\uDC00-\uDCF5\uDD00-\uDD26\uDD29-\uDD64\uDD6A-\uDD6C\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDDE8\uDE00-\uDE41\uDE45\uDF00-\uDF56]|\uD835[\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85\uDE86]|\uD838[\uDD4F\uDEFF]|\uD83B[\uDCAC\uDCB0\uDD2E\uDEF0\uDEF1]|\uD83C[\uDC00-\uDC2B\uDC30-\uDC93\uDCA0-\uDCAE\uDCB1-\uDCBF\uDCC1-\uDCCF\uDCD1-\uDCF5\uDD0D-\uDDAD\uDDE6-\uDE02\uDE10-\uDE3B\uDE40-\uDE48\uDE50\uDE51\uDE60-\uDE65\uDF00-\uDFFF]|\uD83D[\uDC00-\uDED7\uDEE0-\uDEEC\uDEF0-\uDEFC\uDF00-\uDF73\uDF80-\uDFD8\uDFE0-\uDFEB]|\uD83E[\uDC00-\uDC0B\uDC10-\uDC47\uDC50-\uDC59\uDC60-\uDC87\uDC90-\uDCAD\uDCB0\uDCB1\uDD00-\uDD78\uDD7A-\uDDCB\uDDCD-\uDE53\uDE60-\uDE6D\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6\uDF00-\uDF92\uDF94-\uDFCA]/;
514
653
 
@@ -1598,6 +1737,16 @@
1598
1737
  return rules[pl.select(x)] || rules.other;
1599
1738
  }
1600
1739
 
1740
+ // ../../../../../../../../execroot/formatjs/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/FormatApproximately.js
1741
+ function FormatApproximately(numberFormat, result, _a) {
1742
+ var getInternalSlots2 = _a.getInternalSlots;
1743
+ var internalSlots = getInternalSlots2(numberFormat);
1744
+ var symbols = internalSlots.dataLocaleData.numbers.symbols[internalSlots.numberingSystem];
1745
+ var approximatelySign = symbols.approximatelySign;
1746
+ result.push({ type: "approximatelySign", value: approximatelySign });
1747
+ return result;
1748
+ }
1749
+
1601
1750
  // ../../../../../../../../execroot/formatjs/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/PartitionNumberPattern.js
1602
1751
  function PartitionNumberPattern(numberFormat, x, _a) {
1603
1752
  var _b;
@@ -1736,38 +1885,6 @@
1736
1885
  return Intl.getCanonicalLocales(locales);
1737
1886
  }
1738
1887
 
1739
- // ../../../../../../../../execroot/formatjs/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/tslib@2.4.0/node_modules/tslib/tslib.es6.js
1740
- var extendStatics = function(d, b) {
1741
- extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
1742
- d2.__proto__ = b2;
1743
- } || function(d2, b2) {
1744
- for (var p in b2)
1745
- if (Object.prototype.hasOwnProperty.call(b2, p))
1746
- d2[p] = b2[p];
1747
- };
1748
- return extendStatics(d, b);
1749
- };
1750
- function __extends(d, b) {
1751
- if (typeof b !== "function" && b !== null)
1752
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1753
- extendStatics(d, b);
1754
- function __() {
1755
- this.constructor = d;
1756
- }
1757
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1758
- }
1759
- function __spreadArray(to, from, pack) {
1760
- if (pack || arguments.length === 2)
1761
- for (var i = 0, l = from.length, ar; i < l; i++) {
1762
- if (ar || !(i in from)) {
1763
- if (!ar)
1764
- ar = Array.prototype.slice.call(from, 0, i);
1765
- ar[i] = from[i];
1766
- }
1767
- }
1768
- return to.concat(ar || Array.prototype.slice.call(from));
1769
- }
1770
-
1771
1888
  // ../../../../../../../../execroot/formatjs/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/lib/abstract/languageMatching.js
1772
1889
  var data = {
1773
1890
  supplemental: {
@@ -6428,7 +6545,7 @@
6428
6545
  var dataLocale = internalSlots.dataLocale;
6429
6546
  var dataLocaleData = NumberFormat.localeData[dataLocale];
6430
6547
  invariant(dataLocaleData !== void 0, "Cannot load locale-dependent data for ".concat(dataLocale, "."));
6431
- internalSlots.pl = new Intl.PluralRules(dataLocale, {
6548
+ internalSlots.pl = createMemoizedPluralRules(dataLocale, {
6432
6549
  minimumFractionDigits: internalSlots.minimumFractionDigits,
6433
6550
  maximumFractionDigits: internalSlots.maximumFractionDigits,
6434
6551
  minimumIntegerDigits: internalSlots.minimumIntegerDigits,
package/src/core.js CHANGED
@@ -46,7 +46,7 @@ exports.NumberFormat = function (locales, options) {
46
46
  var dataLocale = internalSlots.dataLocale;
47
47
  var dataLocaleData = exports.NumberFormat.localeData[dataLocale];
48
48
  (0, ecma402_abstract_1.invariant)(dataLocaleData !== undefined, "Cannot load locale-dependent data for ".concat(dataLocale, "."));
49
- internalSlots.pl = new Intl.PluralRules(dataLocale, {
49
+ internalSlots.pl = (0, ecma402_abstract_1.createMemoizedPluralRules)(dataLocale, {
50
50
  minimumFractionDigits: internalSlots.minimumFractionDigits,
51
51
  maximumFractionDigits: internalSlots.maximumFractionDigits,
52
52
  minimumIntegerDigits: internalSlots.minimumIntegerDigits,