mathfuse: TypeScript Math Utilities (Statistics, Vectors, Matrices) Zero Dependencies
Source: Dev.to
Overview
Tired of pulling in huge math libraries just to compute a mean or dot product? mathfuse provides a lean, tree‑shakeable TypeScript math toolkit with zero dependencies. It offers typed utilities for statistics, vectors, matrices, and more.
Installation
npm install mathfuse
# or
bun add mathfuseStatistics
import { mean, median, stddev, percentile } from 'mathfuse';
const data = [2, 4, 4, 4, 5, 5, 7, 9];
console.log(mean(data)); // 5
console.log(median(data)); // 4.5
console.log(stddev(data)); // 2
console.log(percentile(data, 75)); // 6Vectors
import { dot, magnitude, normalize } from 'mathfuse';
const v1 = [1, 2, 3];
const v2 = [4, 5, 6];
console.log(dot(v1, v2)); // 32
console.log(magnitude(v1)); // 3.74
console.log(normalize(v1)); // [0.27, 0.53, 0.80]Matrices
import { matmul, transpose, determinant } from 'mathfuse';
const A = [
[1, 2],
[3, 4],
];
console.log(matmul(A, [[5, 6], [7, 8]])); // [[19, 22], [43, 50]]
console.log(determinant(A)); // -2Key Features
- Zero dependencies
- Full TypeScript generics
- Tree‑shakeable ESM/CJS builds
- Works everywhere (Node.js, Bun, Deno, browsers)