math-essential
v0.0.1
Published
A lightweight JavaScript math utilities library for basic mathematical operations
Maintainers
Readme
🧮 math-essential
The JavaScript math library you've been waiting for.
Simple, fast, and powerful mathematical utilities for JavaScript developers. Zero dependencies, TypeScript ready.
✨ Why math-essential?
- 🚀 Blazing Fast - Optimized for performance
- 🪶 Lightweight - Zero dependencies, minimal bundle size
- 🎯 TypeScript Ready - Full type definitions included
- 🧪 Well Tested - 100% test coverage
- 📚 Comprehensive - Everything you need for math operations
- 🔧 Tree Shakeable - Import only what you need
🚀 Quick Start
npm install math-essentialconst { sum, mean, isPrime } = require('math-essential');
// Basic arithmetic
sum(1, 2, 3, 4, 5); // 15
// Statistics
mean([1, 2, 3, 4, 5]); // 3
// Number theory
isPrime(17); // trueThat's it! You're ready to crunch numbers like a pro.
🎯 Features
🧮 Basic Math
const { sum, multiply, power, round } = require('math-essential');
sum(1, 2, 3, 4); // 10
multiply(2, 3, 4); // 24
power(2, 8); // 256
round(3.14159, 2); // 3.14📊 Statistics
const { mean, median, mode, standardDeviation } = require('math-essential');
const data = [1, 2, 2, 3, 4, 4, 4, 5];
mean(data); // 3.125
median(data); // 3.5
mode(data); // [4]
standardDeviation(data); // 1.356📐 Geometry
const { circleArea, distance, triangleArea } = require('math-essential');
circleArea(5); // 78.54
distance(0, 0, 3, 4); // 5
triangleArea(10, 8); // 40🔢 Number Theory
const { isPrime, factorial, gcd, fibonacci } = require('math-essential');
isPrime(17); // true
factorial(5); // 120
gcd(48, 18); // 6
fibonacci(10); // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]🔄 Unit Conversion
const { degreesToRadians, celsiusToFahrenheit } = require('math-essential');
degreesToRadians(90); // 1.5708
celsiusToFahrenheit(25); // 77💡 Real-world Examples
Calculate compound interest
const { power, round } = require('math-essential');
function compoundInterest(principal, rate, time) {
return round(principal * power(1 + rate/100, time), 2);
}
compoundInterest(1000, 5, 10); // 1628.89Analyze test scores
const { mean, median, standardDeviation } = require('math-essential');
const scores = [85, 92, 78, 96, 88, 91, 87, 93];
console.log(`Average: ${mean(scores)}`); // 88.75
console.log(`Median: ${median(scores)}`); // 89.5
console.log(`Std Dev: ${standardDeviation(scores)}`); // 5.77Generate Fibonacci sequence for UI animations
const { fibonacci } = require('math-essential');
const delays = fibonacci(8).map(n => n * 100);
// [0, 100, 100, 200, 300, 500, 800, 1300] ms delays🎨 Tree Shaking Support
Import only what you need:
// ESM
import { sum, mean } from 'math-essential';
// CommonJS
const { sum, mean } = require('math-essential');
// Webpack will automatically tree-shake unused functions📚 Full API Reference
Basic Math
sum(...numbers)- Add multiple numbersmultiply(...numbers)- Multiply multiple numberspower(base, exponent)- Calculate powerround(number, decimals)- Round to decimal placesabs(number)- Absolute value
Statistics
mean(array)- Calculate averagemedian(array)- Find median valuemode(array)- Find most frequent value(s)standardDeviation(array)- Calculate standard deviationminMax(array)- Find min and max values
Geometry
circleArea(radius)- Circle arearectangleArea(length, width)- Rectangle areatriangleArea(base, height)- Triangle areadistance(x1, y1, x2, y2)- Distance between pointssphereVolume(radius)- Sphere volume
Number Theory
isPrime(number)- Check if primefactorial(number)- Calculate factorialgcd(a, b)- Greatest common divisorlcm(a, b)- Least common multiplefibonacci(n)- Generate Fibonacci sequence
Converters
degreesToRadians(degrees)- Convert degrees to radiansradiansToDegrees(radians)- Convert radians to degreescelsiusToFahrenheit(celsius)- Temperature conversionfahrenheitToCelsius(fahrenheit)- Temperature conversion
🤝 Contributing
We love contributions! Please read our Contributing Guide to get started.
📄 License
MIT
🌟 Support
If you found this library helpful, please consider:
- ⭐ Starring the repo
- 🐛 Reporting bugs
- 💡 Suggesting new features
- 🔀 Contributing code
Made with ❤️ for the JavaScript community
Stop reinventing the wheel. Start building amazing things.
