asr-math
v0.1.0
Published
Dependency-free TypeScript mathematics and geometry utilities for JavaScript and TypeScript projects.
Maintainers
Readme
asr-math
A dependency-free mathematics and geometry utility library for JavaScript and TypeScript.
The goal of asr-math is to make common mathematical formulas easy to use in Node.js, React, Vite, browser, and other JavaScript/TypeScript projects.
Features
- Zero runtime dependencies
- TypeScript-first API
- JavaScript compatible
- ESM package
- Geometry formulas
- Algebra utilities
- Trigonometry utilities
- Basic mathematical/statistical utilities
- Input validation with useful errors
- Generated TypeScript declarations
- Small, tree-shakeable functions
Installation
pnpm add asr-mathor:
npm install asr-mathUsage
import {
circleArea,
circleCircumference,
triangleArea,
solveQuadratic,
} from "asr-math";
console.log(circleArea(10));
// 314.1592653589793
console.log(circleCircumference(10));
// 62.83185307179586
console.log(triangleArea(10, 5));
// 25
console.log(solveQuadratic(1, -3, 2));
// { discriminant: 1, roots: [1, 2] }Geometry
import {
squareArea,
rectangleArea,
triangleArea,
circleArea,
circleCircumference,
trapezoidArea,
regularPolygonArea,
cubeVolume,
cylinderVolume,
sphereVolume,
} from "asr-math";Algebra
import {
factorial,
combination,
permutation,
solveLinear,
solveQuadratic,
power,
squareRoot,
} from "asr-math";Trigonometry
import {
sinDegrees,
cosDegrees,
tanDegrees,
asinDegrees,
acosDegrees,
atanDegrees,
pythagoreanHypotenuse,
} from "asr-math";Basic calculations
import {
percentage,
percentageChange,
average,
weightedAverage,
gcd,
lcm,
simpleInterest,
compoundInterest,
} from "asr-math";Development
Install development dependencies:
pnpm installBuild:
pnpm buildType-check:
pnpm typecheckRun tests:
pnpm testInspect exactly what npm will publish:
pnpm pack:checkDesign goals
- No runtime dependencies.
- Predictable function names.
- Strong TypeScript types.
- Clear validation errors.
- Small independent functions.
- Works in frontend and backend JavaScript/TypeScript projects.
- Avoid hidden state.
- Avoid unnecessary abstractions.
Roadmap
- [ ] More geometry formulas
- [ ] Coordinate geometry
- [ ] Statistics
- [ ] Probability
- [ ] Number theory
- [ ] Unit conversion
- [ ] Financial mathematics
- [ ] Combinatorics
- [ ] Matrix operations
- [ ] Complex numbers
- [ ] More advanced algebra
- [ ] Better documentation with formula references
- [ ] Browser/Node compatibility tests
- [ ] Automated npm publishing with GitHub Actions
- [ ] npm provenance
- [ ] Changelog/release automation
License
MIT
