npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@accelint/math

v0.2.0

Published

A simple, lightweight JavaScript library that provides a collection of basic mathematical functions.

Downloads

1,543

Readme

@accelint/math

A simple, lightweight JavaScript library that provides a collection of basic mathematical functions.

Installation

npm install @accelint/math

Usage

Importing Functions

// Import all functions
import { clamp, random, randomInt, round, wrap } from '@accelint/math';

// Or import individually for tree-shaking
import { clamp } from '@accelint/math/clamp';
import { random, randomInt } from '@accelint/math/random';
import { round } from '@accelint/math/round';
import { wrap } from '@accelint/math/wrap';

Clamp

Clamps a number within the specified bounds.

import { clamp } from '@accelint/math/clamp';

clamp(5, 15, 10);  // 10 (within bounds)
clamp(5, 15, 2);   // 5  (below min, clamped to min)
clamp(5, 15, 20);  // 15 (above max, clamped to max)
clamp(15, 5, 10);  // RangeError: min exceeded max

Random

Generate a random number within the given bounds (inclusive).

import { random } from '@accelint/math/random';

const value = random(0, 10);
// Returns a random decimal between 0 and 10 (inclusive)

random(10, 0);  // RangeError: Min exceeded max

Random Integer

Generate a random integer within the given bounds (inclusive).

import { randomInt } from '@accelint/math/random';

const value = randomInt(1, 6);
// Returns a random integer between 1 and 6 (like a dice roll)

randomInt(10, 0);  // RangeError: Min exceeded max

Round

Rounds a number to a specified precision.

import { round } from '@accelint/math/round';

round(1, 1.2345);    // 1.2   (1 decimal place)
round(2, 1.2345);    // 1.23  (2 decimal places)
round(3, 1.2345);    // 1.235 (3 decimal places)
round(0, 1.2345);    // 1     (no decimal places)
round(-1, 1234.5);   // 1230  (round to nearest 10)
round(3.1, 1.2345);  // Error: Precision must be an integer

Wrap

Wraps a number into the half-open range [min, max), cycling out-of-range values back around instead of clamping them to the edge. Handles negative and multi-revolution inputs — useful for angles and longitudes.

import { wrap } from '@accelint/math/wrap';

wrap(0, 360, 370);     // 10   (past max, re-enters at min)
wrap(0, 360, -90);     // 270  (negative, wraps up into range)
wrap(-180, 180, 190);  // -170 (longitude past the antimeridian)
wrap(-180, 180, -180); // -180 (inclusive min bound)
wrap(0, 360, 720);     // 0    (multi-revolution)
wrap(360, 0, 10);      // RangeError: min must be less than max

API Reference

clamp(min: number, max: number, value: number): number

Clamps a number within the specified bounds.

Parameters:

  • min - The lower bound to clamp to
  • max - The upper bound to clamp to
  • value - The number value to clamp to the given range

Returns: The clamped value

Throws: RangeError if min > max

random(min: number, max: number): number

Generate a random number within the given bounds.

Parameters:

  • min - The minimum value in the range (inclusive)
  • max - The maximum value in the range (inclusive)

Returns: A random number between min and max (inclusive)

Throws: RangeError if min > max

randomInt(min: number, max: number): number

Generate a random integer within the given bounds.

Parameters:

  • min - The minimum value in the range (inclusive)
  • max - The maximum value in the range (inclusive)

Returns: A random integer between min and max (inclusive)

Throws: RangeError if min > max

round(precision: number, value: number): number

Rounds a number to a specified precision.

Parameters:

  • precision - The precision of the rounded output (must be an integer)
  • value - The value to round

Returns: The rounded value

Throws: Error if precision is not an integer

wrap(min: number, max: number, value: number): number

Wraps a number into the half-open range [min, max). Unlike clamp, which pins out-of-range values to the nearest bound, wrap treats the range as circular.

Parameters:

  • min - The inclusive lower bound of the range
  • max - The exclusive upper bound of the range
  • value - The number value to wrap into the given range

Returns: The wrapped value in [min, max)

Throws: RangeError if min >= max

TypeScript Support

All functions are fully typed and written in TypeScript. Type definitions are included in the package.

License

Apache-2.0