Collection of useful number functions to simplify your code. Written in and for ES6, can be compiled with Babel.js.
# npm coming soon, for now, just clone the repo
import { loop } from 'number-extensions';
console.log(loop(400, 360))
// > 40
Keep in mind that extending native objects is not a good idea, but can simplify your code if used with caution.
import { setGlobals } from 'number-extensions';
setGlobals();
400..loop(360) // or (400).loop(360)
// > 40
By default setGlobals() does not overwrite default prototype functions if they exist, but if you really want it, you can pass a force parameter.
setGlobals(true);
These are the functions that are included. Please read the comments on how and when to use them.
console.log(1..cycle(3, [-2, 3]))
console.log(0.75.scale(50, 150))
console.log(50..random())
console.log(3.4.floor())
console.log(3.4.round())
console.log(3.4.ceil())
console.log(-4..clamp(0, 100));
console.log(90..toRad())
console.log(1.5707963267948966.toDeg())
console.log(-1..abs())
console.log(2..pow(3))
console.log(16..sqrt())
console.log(5..wholeCenter(true))
console.log(400..loop(360))
npm test
By Ioulian