Mint Statistics

Modern statistical computing for JavaScript

A lightweight, high-performance statistics library built for modern development. Zero dependencies, full TypeScript support, and blazingly fast algorithms optimized for real-world data analysis.

5.85×
Faster
3.7KB
Bundle Size
0
Dependencies

Features

Built for performance and developer experience

Lightning Fast

Uses Quickselect algorithm for median calculation. 5-10x faster than sort-based implementations on large datasets.

Type Safe

Built with TypeScript from day one. Full type inference and compile-time safety out of the box.

Lightweight

Zero dependencies. Just 3.7KB minified. Won't bloat your bundle size.

Tree-Shakeable

Modern ESM support. Import only what you need for optimal bundling.

Flexible API

Works with arrays of numbers or objects. Extract values by key effortlessly.

Battle Tested

Comprehensive error handling and edge case coverage for production use.

Examples

Get started in seconds with our simple API

import statistics from 'mintstats';

const scores = [85, 92, 78, 90, 88];

// Calculate basic statistics
const avg = statistics.mean(scores);        // 86.6
const mid = statistics.median(scores);      // 88
const spread = statistics.stdev(scores);   // 5.22
const range = statistics.range(scores);    // 14
import statistics from 'mintstats';

const students = [
  { name: 'Alice', score: 85 },
  { name: 'Bob', score: 92 },
  { name: 'Charlie', score: 78 },
  { name: 'Diana', score: 90 }
];

// Extract and calculate from object property
const avgScore = statistics.mean(students, 'score');     // 86.25
const medianScore = statistics.median(students, 'score');  // 87.5
const p75 = statistics.percentile(students, 75, 'score'); // 90.5
import statistics from 'mintstats';

const data = [2, 4, 6, 8, 10];

// Sample variance (default, n-1)
const sampleVar = statistics.variance(data);
// 10

// Population variance (n)
const popVar = statistics.variance(data, { isSample: false });
// 8

// With objects
const employees = [
  { name: 'John', salary: 50000 },
  { name: 'Jane', salary: 60000 }
];

const salaryStdev = statistics.stdev(employees, { 
  key: 'salary', 
  isSample: true 
});

API Reference

Complete documentation of all available functions

mean(arr, key?)

Calculates the arithmetic mean (average) of the data.

Parameters
arr: number[] | object[] — The data array
key?: string — Property name for object arrays

Returns number
statistics.mean([10, 20, 30]); // 20

median(arr, key?)

Calculates the median using Quickselect algorithm. O(n) average time complexity.

Parameters
arr: number[] | object[] — The data array
key?: string — Property name for object arrays

Returns number
statistics.median([10, 20, 30, 40]); // 25

mode(arr, key?)

Returns an array of the most frequently occurring value(s).

Parameters
arr: number[] | object[] — The data array
key?: string — Property name for object arrays

Returns number[]
statistics.mode([1, 2, 2, 3]); // [2]

range(arr, key?)

Calculates the range (difference between max and min).

Parameters
arr: number[] | object[] — The data array
key?: string — Property name for object arrays

Returns number
statistics.range([10, 20, 30]); // 20

variance(arr, options?)

Calculates the variance (sample or population).

Parameters
arr: number[] | object[] — The data array
options?: { key?: string, isSample?: boolean }
• key — Property name for object arrays
• isSample — Use sample (n-1) or population (n). Default: true

Returns number
statistics.variance([2, 4, 6], { isSample: false });

stdev(arr, options?)

Calculates the standard deviation (sample or population).

Parameters
arr: number[] | object[] — The data array
options?: { key?: string, isSample?: boolean }

Returns number
statistics.stdev([2, 4, 6, 8]); // 2.58

percentile(arr, p, key?)

Calculates the nth percentile (0-100) using linear interpolation.

Parameters
arr: number[] | object[] — The data array
p: number — Percentile (0-100)
key?: string — Property name for object arrays

Returns number
statistics.percentile([10, 20, 30, 40, 50], 75); // 40