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

numberstrings

v1.0.0

Published

A simple Javascript class that formats numeric values in a more readable format.

Downloads

1

Readme

NumberStrings.js

A simple Javascript class that formats numeric values into a more readable format.

By default it will format up to a septillion (1,000,000,000,000,000,000,000,000), however you can pass your own list of units to the constructor if you would like to overwrite/extend the default list of units (more on that below).

If you have any ideas;

  • for new features
  • to improve performance

please let me know by creating an issue/pull request!

Basic Usage:

Browser
var ns = new NumberStrings();
console.log('1,000 = ' + ns.format(1000)); // outputs: "1,000 = 1 thousand"
console.log('50,000,000 = ' + ns.format(50000000)); // outputs: "50,000,000 = 50 million"
console.log('999,999,999 = ' + ns.format(999999999)); // outputs: "999,999,999 = 999.999999 million"
NodeJS

To install using NPM:

npm install numberstrings

Then use as you would in the browser:

var NumberStrings = require('numberstrings');
var ns = new NumberStrings();

Advanced Usage:

The below methods are useful if you want to further format the decimal or unit name that is returned before they are concatinated into a string (default behavior of ns.format(integer)).

getName(integer):
var ns = new NumberStrings();
ns.getName(1000); // Returns the string "thousand"
getDecimal(integer):
var ns = new NumberStrings();
ns.getDecimal(1000); // Returns the decimal that goes in front of the unit name, in this case: 1
Formatting number of decimal places
var ns = new NumberStrings();
var magicNumber = 123456789;
console.log('Two decimal places: ' + ns.getDecimal(magicNumber).toFixed(2) + ' ' + ns.getName(magicNumber));
Overwriting/extending the list of units:

To overwrite/extend the default list of units, you can pass the below units option to the NumberStrings() constructor. The value is the lowest number that can possibly be counted as the specified unit name.

var ns = new NumberStrings({
        units: [
            {
                name: 'hundred',
                value: 100
            },
            {
                name: 'thousand',
                value: 1000
            },
            {
                name: 'million',
                value: 1000000
            }
            ...
        ]
    });