@jdsalasc/solvejs-numbers
v1.8.0
Published
Safer TypeScript number utilities for forms, analytics, pricing, percentages, rounding, currency formatting, and strict numeric parsing.
Downloads
428
Maintainers
Readme
@jdsalasc/solvejs-numbers
Zero-dependency number utilities for JavaScript and TypeScript.
Utilities
clamp,roundTo,sum,average,medianpercent,percentChangecalculateTaxAmount,applyDiscount,grossMarginsafeDivide,isBetweentoCurrency,toNumber,randomInt
When to use this package
Use it when you need safer business math and stricter number parsing for forms, analytics, and pricing logic.
Limitations and Constraints
- Results use IEEE-754 floating-point arithmetic.
- Money workflows should enforce explicit rounding boundaries per domain rules.
Install
npm i @jdsalasc/solvejs-numbersQuick example
import { toNumber, safeDivide, percentChange, calculateTaxAmount, applyDiscount, grossMargin } from "@jdsalasc/solvejs-numbers";
const revenue = toNumber("12,500");
const invalid = toNumber("1,2,3"); // null
const ratio = safeDivide(50, 0, 0);
const growth = percentChange(120, 100); // 20
const tax = calculateTaxAmount(199.99, 19); // 38
const discounted = applyDiscount(199.99, 15); // 169.99
const margin = grossMargin(1000, 700); // 30Precision note
JavaScript numbers are floating-point. For money-sensitive flows, apply explicit rounding steps (for example roundTo(value, 2)) at domain boundaries (tax, subtotal, invoice total).
