A lightweight and fast statistics library for JavaScript and TypeScript.
- 5-10x faster than traditional implementations (Quickselect for median)
- Fully typed - Built with TypeScript from the ground up
- Zero dependencies - Size: 3.7KB
- Tree-shakeable - Import only what you need
npm install mintstatsimport statistics from "mintstats";
const scores = [85, 92, 78, 90, 88];
statistics.mean(scores); // 86.6
statistics.median(scores); // 88
statistics.stdev(scores); // 5.22
// Works with objects too
const students = [
{ name: "Alice", score: 85 },
{ name: "Bob", score: 92 },
];
statistics.mean(students, "score"); // 88.5
statistics.percentile(students, 75, "score"); // 90.5Basic Stats
mean(arr, key?)- Averagemedian(arr, key?)- Middle value (uses Quickselect - O(n))mode(arr, key?)- Most frequent value(s)range(arr, key?)- Max - Min
Variability
variance(arr, options?)- Variance (sample or population)stdev(arr, options?)- Standard deviationpercentile(arr, p, key?)- Nth percentile (0-100)
Options for variance/stdev:
{
key: 'propertyName', // for object arrays
isSample: true // sample (n-1) or population (n)
}Benchmark on 10,000 items:
Traditional (sort): 588 ops/sec
Mint Stats: 3,438 ops/sec -> 5.85x faster
Full type safety with automatic inference:
statistics.mean([1, 2, 3]); // Works
statistics.mean(objects, "value"); // Works
statistics.mean(objects); // Type error - key requiredMIT © Peakk