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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mathp

v1.5.0

Published

Math utility (ES6 polyfills and additional methods)

Downloads

34

Readme

Mathp

Build Status NPM version

Math utility for node

Installing and testing

With npm do:

npm install mathp

To run the test suite, clone the repository and run the following command from the root directory:

npm test

Features

  • Can be used as a drop-in replacement for the Math object.
  • Provide implementations of missing ES6 methods.
  • Doesn't modify the actual Math object.
  • Doesn't modify the Number prototype or rely on boxing of any kind.
  • Works in Titanium.
  • Supports deep requires for low footprint in browserify projects.

Current methods

Polyfills

All polyfills are tested with mocha+chai against the specifications described by the 25th revision of the draft for the 6th Edition of the ECMAScript Language to ensure optimal compliance.

Additional methods

General

  • sign1(value)
  • copySign(value, sign)
  • lerp(value1, value2, ratio)
  • limit(value, min, max)
  • scale(value, origMin, origMax, destMin, destMax)
  • factorial(value)
  • step(edge, value)
  • smoothstep(min, max, value)
  • smootherstep(min, max, value)
  • roundToPrecision(number, precision)
  • euclideanModulo(dividend, divisor)
  • flooredModulo(dividend, divisor)
  • truncatedModulo(dividend, divisor)
  • fract(value)

Distance

  • euclideanDistance(x1, y1, x2, y2) : Euclidean distance
  • euclideanDistance3(x1, y1, z1, x2, y2, z2) : Euclidean distance for 3 dimensions
  • euclideanDistanceN(point1, point2) : Euclidean distance for N dimension(s)
  • manhattanDistance(x1, y1, x2, y2) : Manhattan distance
  • manhattanDistance3(x1, y1, z1, x2, y2, z2) : Manhattan distance for 3 dimensions
  • manhattanDistanceN(point1, point2) : Manhattan distance for N dimension(s)
  • chebyshevDistance(x1, y1, x2, y2) : Chebyshev distance
  • chebyshevDistance3(x1, y1, z1, x2, y2, z2) : Chebyshev distance for 3 dimensions
  • chebyshevDistanceN(point1, point2) : Chebyshev distance for N dimension(s)
  • minkowskiDistance(x1, y1, x2, y2, p) : Minkowski distance
  • minkowskiDistance3(x1, y1, z1, x2, y2, z2) : Minkowski distance for 3 dimensions
  • minkowskiDistanceN(point1, point2, p) : Minkowski distance for N dimension(s)

Trigonometry

  • sinc(value)
  • sec(value)
  • csc(value)
  • cot(value)
  • asec(value)
  • acsc(value)
  • acot(value)
  • sech(value)
  • csch(value)
  • coth(value)
  • asech(value)
  • acsch(value)
  • acoth(value)

Conversion

  • toDegrees(radians)
  • toRadians(degrees)

Mean

Checks

  • isNaN(value)
  • isZero(value)
  • isNegativeZero(value)
  • isPositiveZero(value)
  • isFinite(value)
  • isInfinity(value)
  • isNegativeInfinity(value)
  • isPositiveInfinity(value)
  • isInteger(value)
  • isSafeInteger(value)

Extras

  • wshaper(value, min, max, shape)

Examples

Basic usage

var mathp = require('mathp');

var taxiDist = mathp.manhattanDistance(0, 0, 12, 15);
var cos120degree = Math.cos(mathp.toRadians(120));

Replacing the native Math object

var Math = require('mathp');

var taxiDist = Math.manhattanDistance(0, 0, 12, 15);
var cos120degree = Math.cos(Math.toRadians(120));

With deep requires

var manhattanDistance = require('mathp/functions/manhattanDistance')),
    toRandians = require('mathp/functions/toRadians'));

var taxiDist = manhattanDistance(0, 0, 12, 15);
var cos120degree = Math.cos(toRadians(120));

Projects using deep requires will only include the code they actually need whe bundled with browserify instead of the whole module.

Potential use cases

  • Generative art.
  • Procedural heightmap / world generation.
  • Anything that may benefit from some maths, and a lot of things do.

Changelog

1.5.0 (2015.10.16) :

  • New implementation : fract.
  • Remove the test folder from the package downloaded from npm.
  • Updated dev dependencies.
  • Added automatic tests on the latest stable version of Node.js Travis.
  • Removed automatic tests on Node.js 0.10.x and iojs via Travis.

1.4.0 (2015.05.06) :

  • New implementations : euclideanDistance3, manhattanDistance3, chebyshevDistance3 and minkowskiDistance3 (much faster than the generic N dimensions functions).

1.3.2 (2015.03.28) :

  • Terseness refactor.

1.3.1 (2015.02.28) :

  • Add .editorconfig file.
  • Removed the builds and other unecessary files from the package downloaded from npm.
  • Updated dev dependencies.
  • Added automatic tests on Node.js 0.12.x and io.js via Travis.
  • Removed automatic tests on Node.js 0.11.x via Travis.

1.3.0 (2015.02.03) :

  • New implementations : isInteger, isSafeInteger.

Full history

Roadmap

  • Write better doc.

Acknowledgement

Most ES6 polyfills are taken from MDN where they were contributed by Mozilla Contributors under the Creative Commons CC-0 license (public domain). Minor improvements of said polyfills were contributed back to MDN.

License

MIT