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

underscore.number

v0.1.3

Published

Number-related functions missing from underscore.js

Downloads

27

Readme

THIS REPOSITORY IS NO LONGER MAINTAINED.

Underscore.number

Number-related functions missing from underscore.js.

Installation

npm

npm install underscore.number

bower

bower install underscore.number

Functions

sign _.num.sign(num)

Returns a sign of num as -1, 0 or 1.

_.num.sign(-10); // -1
_.num.sign(0); // 0
_.num.sign(20); // 1

pinch _.num.pinch(num, min, max)

Puts num in a range of min to max.

Returns min if num is smaller than min, max if num is larger than max, and num itself if it’s already in a range of min to max.

_.num.pinch(12, 0, 10); // 10
_.num.pinch(5, 0, 10); // 5
_.num.pinch(-3, 0, 10); // 0

loop _.num.loop(num, min, max)

Converts num as it is in a circular range of min to max (excluding max).

Considering the expression, _.num.loop(480, 0, 360) as an angle calculation, it converts 480 degrees in a range of 0 to 360 degrees.

_.num.loop(480, 0, 360); // 120
_.num.loop(-480, 0, 360); // 240
_.num.loop(180, 0, 360); // 180
_.num.loop(0, 0, 360); // 0
_.num.loop(360, 0, 360); // 360
_.num.loop(-480, -180, 180); // -120

clockwise _.num.clockwise(from, to, range)

Returns the clockwise distance from from to to as they are in a circle of range. Useful to calculate angles.

_.num.clockwise(0, 100, 360); // 100
_.num.clockwise(0, -100, 360); // 260
_.num.clockwise(100, 100, 360); // 0
_.num.clockwise(101, 100, 360); // 359

nearer _.num.nearer(from, to, range)

Returns the nearer distance from from to to as they are in a circle of range. Useful to calculate angles.

_.num.nearer(0, 100, 360); // 100
_.num.nearer(0, -100, 360); // -100
_.num.nearer(100, 100, 360); // 0
_.num.nearer(101, 100, 360); // -1

average _.num.average(*nums)

Returns an average of nums

_.num.average(1, 2, 3, 4); // 2.5

round _.num.round(num, level)

Rounds num by specified level.

_.num.round(123.456, -3); // 0
_.num.round(123.456, -2); // 100
_.num.round(123.456, -1); // 120
_.num.round(123.456, 0); // 123 (same as Math.round(123.456))
_.num.round(123.456, 1); // 123.5
_.num.round(123.456, 2); // 123.46
_.num.round(123.456, 3); // 123.456

between _.num.between(from, to, ratio)

_.num.between(0, 100, 0); // 0
_.num.between(0, 100, 0.5); // 50
_.num.between(0, 100, 1); // 100

add _.num.add(*nums)

Adds nums.

_.num.add(1, 2, 3, 4); // 10

sub _.num.sub(base, *nums)

Subtracts nums from base.

_.num.sub(10, 1, 2, 3); // 4

mul _.num.mul(*nums)

Multiplies nums.

_.num.mul(3, 4, 5); // 60

div _.num.div(base, *nums)

Divides base by nums.

_.num.div(16, 2, 2); // 4

random _.num.random([a[, b]])

Returns a random number.

_.num.random(); // (same as Math.random())
_.num.random(5); // random number in range of 0 to 5 (excluding 5)
_.num.random(2, 4); // random number in range of 2 to 4 (excluding 4)

radToDeg _.num.radToDeg(radians)

Converts radians to degrees.

_.num.radToDeg(Math.PI); // 180

degToRad _.num.degToRad(degrees)

Converts degrees to radians.

_.num.degToRad(180); // 3.141592653589793 (Math.PI)

License

MIT