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

@schwingbat/math2

v1.1.0

Published

A collection of helpful math functions that should have been included in the JS standard library.

Downloads

4

Readme

Math2.js

A simple collection of utility functions that should be in the JS Math object but aren't. I'll be adding to the list as I need them.

The current functions available are:

range

Math2.range(low, high[, round])

Returns a number between specified low and high ranges. Optionally rounded if the third parameter is true.

Math2.range(1, 10) // => 3.6221051
Math2.range(1, 50, true) // => 44

// It's essentially the same as:
Math.random() * (high - low) + low;
// ...but much easier to remember.

clamp

Math2.clamp(number, low, high)

Takes a number, a low bound and a high bound and clamps the number within that range.

// It's shorthand for this:
Math.min(10, Math.max(1, 16))

// because people always reverse the numbers and it requires some mental overhead to figure it out (at least for me).

// So if you want to make sure a number is limited to a range between 1 and 10, you can do this instead:
Math2.clamp(16, 1, 10);

encomma

Math2.encomma(number[, delimiter])

Adds commas (or other delimiter of choice) at proper spaces to make larger numbers easier to read. Takes a number or a string and returns a string.

It also strips commas as part of its process, which has the nice side effect of fixing improperly placed commas.

Also there might be a real name for this process. If you know it, let me know.

Math2.encomma(100000000) // => 100,000,000
Math2.encomma("1,23456,7", "!") // => 1!234!567

decomma

Math2.decomma(number)

Takes a string and strips the commas, returning a number. It's like encomma in reverse.

Math2.decomma("100,000,000") // => 100000000