@formatjs/intl-pluralrules 7.0.0 → 7.0.1

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/index.js CHANGED
@@ -748,19 +748,15 @@ function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
748
748
  return r2;
749
749
  }
750
750
  // packages/ecma402-abstract/NumberFormat/decimal-cache.js
751
- /**
752
- * Cached function to compute powers of 10 for Decimal.js operations.
753
- * This cache significantly reduces overhead in ComputeExponent and ToRawFixed
754
- * by memoizing expensive Decimal.pow(10, n) calculations.
755
- *
756
- * Common exponents (e.g., -20 to 20) are used repeatedly in number formatting,
757
- * so caching provides substantial performance benefits.
758
- *
759
- * @param exponent - Can be a number or Decimal. If Decimal, it will be converted to string for cache key.
760
- */
761
- const getPowerOf10 = memoize((exponent) => {
762
- return Decimal.pow(10, exponent);
763
- });
751
+ const powersOfTen = /* @__PURE__ */ new Map();
752
+ function getPowerOf10(exponent) {
753
+ const n = typeof exponent === "number" ? exponent : exponent.toNumber();
754
+ const cached = powersOfTen.get(n);
755
+ if (cached !== void 0) return cached;
756
+ const power = Decimal.pow(10, n);
757
+ if (Number.isInteger(n) && n >= -324 && n <= 324) powersOfTen.set(n, power);
758
+ return power;
759
+ }
764
760
  // packages/ecma402-abstract/NumberFormat/ToRawFixed.js
765
761
  function ToRawFixedFn(n, f) {
766
762
  return n.times(getPowerOf10(-f));
@@ -782,10 +778,19 @@ function findN2R2(x, f, roundingIncrement) {
782
778
  /**
783
779
  * https://tc39.es/ecma402/#sec-torawfixed
784
780
  * @param x a finite non-negative Number or BigInt
785
- * @param minFraction an integer between 0 and 20
786
- * @param maxFraction an integer between 0 and 20
781
+ * @param minFraction an integer between 0 and 100
782
+ * @param maxFraction an integer between 0 and 100
787
783
  */
788
784
  function ToRawFixed(x, minFraction, maxFraction, roundingIncrement, unsignedRoundingMode) {
785
+ if (roundingIncrement === 1 && x.isInteger()) {
786
+ const integer = x.toString();
787
+ return {
788
+ formattedString: integer + (minFraction === 0 ? "" : "." + repeat("0", minFraction)),
789
+ roundedNumber: x,
790
+ integerDigitsCount: integer.length,
791
+ roundingMagnitude: -maxFraction
792
+ };
793
+ }
789
794
  const f = maxFraction;
790
795
  const { n1, r1 } = findN1R1(x, f, roundingIncrement);
791
796
  const { n2, r2 } = findN2R2(x, f, roundingIncrement);