Skip to content

Releases: itsmnthn/big-utils

v2.0.0

27 Aug 05:18

Choose a tag to compare

Highlights

  • Arithmetic: New fixed-point math utilities (bigMulDivTrunc, bigMulDivRound, bigMulScaled, bigDivScaled, bigSqrtInt, bigSqrtScaled, bigPowIntScaled) with robust rounding via ROUND_MODES.
  • Scaling: Introduced bigScale, bigUnscale, bigRescale, bigAlignScales and compatibility wrappers scale, unScale, unScaleToBase.
  • Core: Added bigAbs, bigClamp, bigMin, bigMax, bigGcd, bigPow10, bigSign.
  • Formatting: formatWithComma, formatNumberCompact, formatSmallest, shortenDecimals, formatAmount, formatAmountCompact.
  • Units: Reworked calcTotalPrice, calcUnitPrice, calcUnits; added sqrtPrice helpers; improved percentage utilities (calcPercentOf, calcPercentFrom, increaseByPercent, decreaseByPercent, multiplyByFactor, divideByFactor).
  • Utils: BigInt JSON support (monkeyPatchBigInt, unPatchBigInt, parseWithBigInt, stringifyWithBigInt), string helpers, timers, ranges, IDs, trimming.
  • Structure: Clear modules core, arithmetic, scaling, formatting, units, utils; consolidated constants in utils/zro.
  • Build: Migrated from unbuild to tsdown; CJS/ESM outputs, DTS, clean builds; updated repo scripts.

Breaking changes

  • File and export reorganization: many v1 functions moved into dedicated modules; top-level re-exports preserved via src/index.ts but direct deep imports from v1 locations will break.
  • Removal/renames: src/formatter.ts, src/units/formatter.ts, src/units/scale.ts, src/units/unscale.ts, and other legacy single-file utilities replaced by modular formatting/ and scaling/ APIs.
  • Rounding is explicit for fixed-point helpers: functions like bigMulScaled, bigDivScaled, bigPowIntScaled, and bigSqrtScaled require a ROUND_MODES argument where applicable.

Migration guide

Imports

// v1 (old)
// import { scale, unScale } from '@itsmnthn/big-utils/units/scale'
// import { formatWithComma } from '@itsmnthn/big-utils/formatter'

// v2 (new)
import {
  // Core math
  bigAbs, bigPow10, bigGcd,
  // Fixed-point arithmetic
  bigMulDivTrunc, bigMulDivRound, bigMulScaled, bigDivScaled, bigSqrtScaled, bigPowIntScaled,
  ROUND_MODES,
  // Scaling
  bigScale, bigUnscale, bigRescale, bigAlignScales, scale, unScale, unScaleToBase,
  // Formatting
  formatWithComma, formatAmount, formatAmountCompact, formatNumberCompact, formatSmallest, shortenDecimals,
  // Units
  calcTotalPrice, calcUnitPrice, calcUnits,
  // Utils
  parseWithBigInt, stringifyWithBigInt, monkeyPatchBigInt, unPatchBigInt,
} from '@itsmnthn/big-utils'

Behavioral notes

  • Price and percent helpers validate inputs and return 0n for zero magnitudes where appropriate; invalid arguments throw typed errors (RangeError, TypeError).
  • scale/unScale remain available for backward compatibility but now delegate to new big* functions.
  • Rounding defaults: bigScale defaults to HALF_AWAY_ZERO; bigUnscale/bigRescale default to TRUNC.

DX and build

  • Build: tsdown with multi-format output, dts, and exports map; engines.node set to ^22.
  • Scripts: build, stub, test, lint, lint:fix, release, prepare.
  • Package exports: ESM/CJS entry points with types at dist/.

Tests

  • 15 spec files, 292 tests passing.
  • Coverage spans arithmetic, scaling, formatting, units, utils, and BigInt JSON.

Changelog (squashed from commits)

  • feat: advanced BigInt math and rounding utilities
  • feat: BigInt JSON stringify/parse and monkey patching helpers
  • feat: compact number formatting and new formatting helpers
  • refactor: reorganize exports, regroup features into modules; consolidate constants
  • refactor: improve error handling/validation in price and formatting
  • refactor: scale/unscale to use bigScale/bigUnscale (backward compatible)
  • chore: migrate unbuild → tsdown; update dependencies; ignore docs

Notes

  • No runtime deps; all utilities are pure BigInt/TS.
  • Docs for v2 to follow; v1 docs remain at https://big-utils.pages.dev/.

Full Changelog: v1.0.0...v2.0.0

v1.0.0

12 Sep 08:54

Choose a tag to compare

    First Release

    View changes on GitHub