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

math-safe

v1.1.0

Published

Math with all the necessary polyfills and additional functions

Downloads

6

Readme

math-safe

Math with all the necessary polyfills and additional functions

What for?

In older browsers, methods such as imul, hypot, fround, etc, may not exist. There are polyfills in this library so that everything works even in the "IE".

All of polyfills were taken from the core-js or MDN

A few more additional methods have been added and more may be added.

tree-shaking is work.

ecma methods

All standard js methods like Math, but some contain polyfills:

import { round, random, abs, sign... } from 'math-safe';
// or
import * as MathSafeFull from 'math-safe'
// or
import * as MathSafe from 'math-safe/ecma' // like Math origin
// or
import random from 'math-safe/ecma/random'
// or
const random = require('math-safe').random
// or
const random = require('math-safe/ecma/random').default

extra methods

There are 4 methods in total:

import { randomExtra, ceilExtra, floorExtra, roundExtra } from 'math-safe';
// or
import randomExtra from 'math-safe/extra/random'

// random
// The method "Math.random" can return 0.
// This method "random" will never return 0
randomExtra() // => a float number between 0 and 1
randomExtra(5) // => a float number between 0 and 5
randomExtra(-5, 5) // => a float number between -5 and 5

// ceil, round and floor
ceilExtra(4.006) // => 5 (like Math.ceil)
ceilExtra(6.004, 2) // => 6.01
ceilExtra(6040, -2) // => 6100

floorExtra(4.006) // => 4 (like Math.floor)
floorExtra(0.046, 2) // => 0.04
floorExtra(4060, -2) // => 4000

roundExtra(4.006) // => 4 (like Math.round)
roundExtra(4.006, 2) // => 4.01
roundExtra(4060, -2) // => 4100

esnext methods

See proposal https://rwaldron.github.io/proposal-math-extensions

There are 5 methods and 2 constants in total:

// Convert to degrees and to radians:
import { degrees, radians, DEG_PER_RAD, RAD_PER_DEG } from 'math-safe';
// or
import degrees from 'math-safe/esnext/degrees'

DEG_PER_RAD // Math.PI / 180
RAD_PER_DEG // 180 / Math.PI

degrees(1.5) // => 1.5 * RAD_PER_DEG
radians(180) // => 180 * DEG_PER_RAD

// Other:
import { clamp, scale, fscale} from 'math-safe';

// returns a "value" if it is between "min" and "max"
// otherwise it will return "min" or "max"
clamp(value, min, max)

adv. methods

There are 5:

import { mean, mul, div, sum, sub } from 'math-safe';
// or
import mean from 'math-safe/adv/mean'

// returns the average value of all arguments
mean(1, 2, 3, 4) // => 2.5

// returns the multiply of all arguments
mul(1, 2, 3, 4) // => 24

// returns the divide of all arguments
div(12, 3, 2) // => 12 / 3 / 2 = 2

// returns the sum of all arguments
sum(1, 2, 3, 4) // => 10

// returns the substract of all arguments
sub(5, 2, 1) // => 5 - 2 - 1 = 2

License

MIT