Skip to content

qxie11/tiny-math-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tiny-math-utils

A lightweight, modern, zero-dependency library for common mathematical operations.

Say goodbye to typing Math.max(Math.min(...)) and writing your own random integer generators. This micro-library provides the missing math utilities for your JavaScript/TypeScript projects.

Features

  • 🚀 Tiny: Zero dependencies, extremely small bundle footprint.
  • 💙 TypeScript: Written in TS with full type support.
  • 🌳 Tree-shakable: Import only what you need.

Installation

npm install tiny-math-utils

Usage

import { clamp, randomInt, roundTo, lerp, degToRad } from 'tiny-math-utils';

// Clamp a value
const volume = clamp(150, 0, 100); 
console.log(volume); // 100

// Random Integer (inclusive)
const diceRoll = randomInt(1, 6);
console.log(diceRoll); // 1 to 6

// Round to specific precision
const price = roundTo(19.99543, 2);
console.log(price); // 20

// Linear Interpolation (useful for animations)
const currentX = lerp(0, 100, 0.5);
console.log(currentX); // 50

// Conversions
const radians = degToRad(180); // 3.1415...

Available Functions

  • clamp(value, min, max)
  • randomInt(min, max)
  • randomFloat(min, max)
  • roundTo(value, precision)
  • lerp(start, end, amt)
  • degToRad(degrees)
  • radToDeg(radians)
  • inRange(value, min, max)
  • mapRange(value, inMin, inMax, outMin, outMax)
  • sum(...numbers)
  • average(...numbers)
  • distance(x1, y1, x2, y2)
  • Constants: PI, E

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors