@formatjs/intl-pluralrules 7.0.0 → 7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-pluralrules",
3
- "version": "7.0.0",
3
+ "version": "7.0.2",
4
4
  "description": "Polyfill for Intl.PluralRules",
5
5
  "keywords": [
6
6
  "PluralRules",
@@ -29,7 +29,7 @@
29
29
  "./should-polyfill.js": "./should-polyfill.js"
30
30
  },
31
31
  "dependencies": {
32
- "@formatjs/bigdecimal": "0.2.8",
33
- "@formatjs/intl-localematcher": "0.10.0"
32
+ "@formatjs/bigdecimal": "0.2.10",
33
+ "@formatjs/intl-localematcher": "0.10.1"
34
34
  }
35
35
  }
package/polyfill-force.js CHANGED
@@ -765,19 +765,15 @@ function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
765
765
  return r2;
766
766
  }
767
767
  // packages/ecma402-abstract/NumberFormat/decimal-cache.js
768
- /**
769
- * Cached function to compute powers of 10 for Decimal.js operations.
770
- * This cache significantly reduces overhead in ComputeExponent and ToRawFixed
771
- * by memoizing expensive Decimal.pow(10, n) calculations.
772
- *
773
- * Common exponents (e.g., -20 to 20) are used repeatedly in number formatting,
774
- * so caching provides substantial performance benefits.
775
- *
776
- * @param exponent - Can be a number or Decimal. If Decimal, it will be converted to string for cache key.
777
- */
778
- const getPowerOf10 = memoize((exponent) => {
779
- return Decimal.pow(10, exponent);
780
- });
768
+ const powersOfTen = /* @__PURE__ */ new Map();
769
+ function getPowerOf10(exponent) {
770
+ const n = typeof exponent === "number" ? exponent : exponent.toNumber();
771
+ const cached = powersOfTen.get(n);
772
+ if (cached !== void 0) return cached;
773
+ const power = Decimal.pow(10, n);
774
+ if (Number.isInteger(n) && n >= -324 && n <= 324) powersOfTen.set(n, power);
775
+ return power;
776
+ }
781
777
  // packages/ecma402-abstract/NumberFormat/ToRawFixed.js
782
778
  function ToRawFixedFn(n, f) {
783
779
  return n.times(getPowerOf10(-f));
@@ -799,10 +795,19 @@ function findN2R2(x, f, roundingIncrement) {
799
795
  /**
800
796
  * https://tc39.es/ecma402/#sec-torawfixed
801
797
  * @param x a finite non-negative Number or BigInt
802
- * @param minFraction an integer between 0 and 20
803
- * @param maxFraction an integer between 0 and 20
798
+ * @param minFraction an integer between 0 and 100
799
+ * @param maxFraction an integer between 0 and 100
804
800
  */
805
801
  function ToRawFixed(x, minFraction, maxFraction, roundingIncrement, unsignedRoundingMode) {
802
+ if (roundingIncrement === 1 && x.isInteger()) {
803
+ const integer = x.toString();
804
+ return {
805
+ formattedString: integer + (minFraction === 0 ? "" : "." + repeat("0", minFraction)),
806
+ roundedNumber: x,
807
+ integerDigitsCount: integer.length,
808
+ roundingMagnitude: -maxFraction
809
+ };
810
+ }
806
811
  const f = maxFraction;
807
812
  const { n1, r1 } = findN1R1(x, f, roundingIncrement);
808
813
  const { n2, r2 } = findN2R2(x, f, roundingIncrement);