Quiet Quiet TypeScript TS
โ†‘ 70 ?
fast-balance richie-rich90454/fast-balance

An exact-arithmetic stoichiometric equation balancer for JavaScript and TypeScript available as an npm package for both CJS and ESM imports.

https://richie-rich90454.github.io/fast-balance/ โ†—
HEALTH ? 70 / Stable
// solo builder// hidden gem// release machine balancerchemistry-formulaschemistry-solvercommonjses-modulenpm-packagescience-researchtypescriptawesome-toolscjs ?

// readme

fast-balance

Exact, fast stoichiometric equation balancing for JavaScript and TypeScript.
Conservation of mass and charge are solved with BigInt rational arithmetic โ€” no floating-point discrepancy, ever.


Features

  • Exact arithmetic โ€” the balancing kernel uses BigInt rationals, so results are always the smallest exact integer coefficients.
  • Linear-time core โ€” element symbols are validated against a fixed set, so elimination is O(mยฒยทn) with m = O(1): linear in the number of species.
  • Real chemistry โ€” nested ()/[], ionic charges, hydrates, state symbols, isotopes, nuclear mode, functional groups and common abbreviations.
  • Spectator species โ€” a species on both sides is balanced, not rejected (C3H8 + O2 + N2 -> CO2 + H2O + N2).
  • Underdetermined systems โ€” the minimal positive solution is returned and flagged; balanceAll returns every independent balance.
  • Honest errors โ€” typed BalanceError with stable codes; unknown elements, ambiguous input and unbalanceable equations are reported explicitly.
  • Small and tree-shakeable โ€” zero runtime dependencies, dual ESM/CommonJS build, TypeScript types, and "sideEffects": false soโ€ฆ