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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@internet/maths

v0.1.2

Published

Maths utilities

Downloads

6

Readme

Maths utilities

:books: Documentation | :globe_with_meridians: Internet modules

Requirements

Module Installation

# using npm
$ npm install --save @internet/maths

# or using yarn
$ yarn add @internet/maths

API

Example

import { mod, map, lerp, ... } from '@internet/maths'

API

maths.mod(dividend, divisor) ⇒ number

Perform a modulo operation.

Kind: static method of maths
Returns: number - Result of the modulo operation

| Param | Type | Description | | --- | --- | --- | | dividend | number | A dividend | | divisor | number | A divisor |

Example

const resut = mod(-1, 5) // return 4

maths.map(value, start1, stop1, start2, stop2) ⇒ number

Re-maps a number from one range to another.

Kind: static method of maths

| Param | Type | Description | | --- | --- | --- | | value | number | The incoming value to be converted | | start1 | number | Lower bound of the value's current range | | stop1 | number | Upper bound of the value's current range | | start2 | number | Lower bound of the value`'s target range | | stop2 | number | Upper bound of the value's target range |


maths.clamp(value, min, max) ⇒ number

Constrains a value to not exceed a maximum and minimum value.

Kind: static method of maths

| Param | Type | Description | | --- | --- | --- | | value | number | The value to constrain | | min | number | Minimum limit | | max | number | Maximum limit |


maths.norm(value, min, max) ⇒ number

Normalizes a number from another range into a value between 0 and 1.

Kind: static method of maths
Returns: number - Normalized value

| Param | Type | Description | | --- | --- | --- | | value | number | The incoming value to be converted | | min | number | Lower bound of the value's current range | | max | number | Upper bound of the value's current range |


maths.lerp(start, end, amount) ⇒ number

Perform a linear interpolation between two values. Equivalent of mix in GLSL.

Kind: static method of maths
Returns: number - Lerped value

| Param | Type | Description | | --- | --- | --- | | start | number | Start of the range in which to interpolate | | end | number | End of the range in which to interpolate | | amount | number | Amount to lerp between the two number (from 0 to 1) |


maths.damp(source, target, smoothing, dt) ⇒ number

Frame-rate aware damping function

Kind: static method of maths
Returns: number - Damped value

| Param | Type | Description | | --- | --- | --- | | source | number | Initial value | | target | number | Target value | | smoothing | number | Smoothing rate | | dt | number | Delta-time (in milliseconds) |


maths.dist(x1, y1, x2, y2) ⇒ number

Calculates the distance between two points (2D)

Kind: static method of maths
Returns: number - Distance

| Param | Type | Description | | --- | --- | --- | | x1 | number | x-coordinate of the first point | | y1 | number | y-coordinate of the first point | | x2 | number | x-coordinate of the second point | | y2 | number | y-coordinate of the second point |


maths.sqdist(x1, y1, x2, y2) ⇒ number

Calculates the squared distance between two points (2D)

Kind: static method of maths
Returns: number - Distance

| Param | Type | Description | | --- | --- | --- | | x1 | number | x-coordinate of the first point | | y1 | number | y-coordinate of the first point | | x2 | number | x-coordinate of the second point | | y2 | number | y-coordinate of the second point |


maths.ang(x1, y1, x2, y2) ⇒ number

Calculates the angle between two points (2D)

Kind: static method of maths
Returns: number - Angle (in Radians)

| Param | Type | Description | | --- | --- | --- | | x1 | number | x-coordinate of the first point | | y1 | number | y-coordinate of the first point | | x2 | number | x-coordinate of the second point | | y2 | number | y-coordinate of the second point |


maths.polarToCart(radius, angle) ⇒ array

Calculates the angle between two points (2D)

Kind: static method of maths
Returns: array - Array containing the cartesian coordinates [x, y]

| Param | Type | Description | | --- | --- | --- | | radius | number | Radius / Distance | | angle | number | Angle |


maths.radToDeg(angle) ⇒ number

Convert angle from radians to degrees

Kind: static method of maths
Returns: number - Angle in degree

| Param | Type | Description | | --- | --- | --- | | angle | number | Angle in radian |


maths.degToRad(angle) ⇒ number

Convert angle from degrees to radians

Kind: static method of maths
Returns: number - Angle in radian

| Param | Type | Description | | --- | --- | --- | | angle | number | Angle in degree |


maths.mean(values) ⇒ number

Get the mean average of values

Kind: static method of maths
Returns: number - mean value

| Param | Type | | --- | --- | | values | array |


maths.median(values) ⇒ number

Get the median average of values

Kind: static method of maths
Returns: number - median value

| Param | Type | | --- | --- | | values | array |