mathfuse: TypeScript Math Utilities (Statistics, Vectors, Matrices) Zero Dependencies

Published: (April 3, 2026 at 12:41 PM EDT)
1 min read
Source: Dev.to

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 mathfuse

Statistics

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)); // 6

Vectors

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));             // -2

Key Features

  • Zero dependencies
  • Full TypeScript generics
  • Tree‑shakeable ESM/CJS builds
  • Works everywhere (Node.js, Bun, Deno, browsers)

Repository

GitHub – mathfuse

0 views
Back to Blog

Related posts

Read more »

TypeScript Type Guards

When you're building a payment system, “close enough” isn’t good enough A single undefined value or a mismatched object property can be the difference between...