Git Product home page Git Product logo

number-extensions's Introduction

number-extensions

License Mocha tests

Collection of useful number functions to simplify your code. Written in and for ES6, can be compiled with Babel.js.

Install

# npm coming soon, for now, just clone the repo

Usage

Function usage

import { loop } from 'number-extensions';
console.log(loop(400, 360))
// > 40

Globals usage

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);

Functions

These are the functions that are included. Please read the comments on how and when to use them.

Cycle

console.log(1..cycle(3, [-2, 3]))

scale

console.log(0.75.scale(50, 150))

random

console.log(50..random())

floor

console.log(3.4.floor())

round

console.log(3.4.round())

ceil

console.log(3.4.ceil())

clamp

console.log(-4..clamp(0, 100));

toRad

console.log(90..toRad())

toDeg

console.log(1.5707963267948966.toDeg())

abs

console.log(-1..abs())

pow

console.log(2..pow(3))

sqrt

console.log(16..sqrt())

wholeCenter

console.log(5..wholeCenter(true))

loop

console.log(400..loop(360))

Tests

npm test

By Ioulian

MIT License

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.