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

@rrainpath/num-format

v0.1.0

Published

Number Format library

Downloads

2

Readme

num-format

Number format library

Usage

  1. Create instance: const format = new NumFormat()
  2. Set your format (or not to be default) (you can set only necessary parts of format): format.setFormat({round: { scale: 2, mode: "half-up" }})
  3. Set number: format.setValue(1234.6678)
  4. Format it! const formattedNumber = format.format()

Full Usage

const f = new NumFormat()
f.setFormat({
    intDelim: { delim:"**", step: 3}, // integer part delimiter (any string and step)
    fracDelim: { delim:"'", step: 4}, // fraction part delimiter (any string and step)

    point: "||", // point (any string)

    round: { scale: 6, mode: "half-up" }, // round mode

    minIntChars: 0, // minimum chars in integer part (if lower then zeros)
    minFracChars: 8, // minimum chars in fraction part (if lower then zeros)
    // if both is zero - zero value will be represent as ""

    nan: "NOT A NUMBER", // NaN symbol
    inf: "INFINITY", // Infinity symbol

    prefix: "@ ", // any string prefix
    suffix: " %" // any string suffix
})

let v
console.log((v=0)+": "+ f.setValue(v).format())
console.log((v=-0)+": "+ f.setValue(v).format())
console.log((v=1)+": "+ f.setValue(v).format())
console.log((v=1.1)+": "+ f.setValue(v).format())
console.log((v=-1.1)+": "+ f.setValue(v).format())
console.log((v=0.21215)+": "+ f.setValue(v).format())
console.log((v=0.0002)+": "+ f.setValue(v).format())
console.log((v=0.03e+30)+": "+ f.setValue(v).format()) //
console.log((v=1214564.4564654)+": "+ f.setValue(v).format())
console.log((v=3e30)+": "+ f.setValue(v).format())
console.log((v=+90000)+": "+ f.setValue(v).format())
console.log((v=.2154)+": "+ f.setValue(v).format())
console.log((v=.5655)+": "+ f.setValue(v).format())
console.log((v=-.08754)+": "+ f.setValue(v).format())
console.log((v=-1546546500000.087554564540000)+": "+ f.setValue(v).format())
console.log((v=999999.99)+": "+ f.setValue(v).format())
console.log((v=1234567890123456789012345678901234567890n)+": "+ f.setValue(v).format())
console.log((v=NaN)+": "+ f.setValue(v).format())
console.log((v=+Infinity)+": "+ f.setValue(v).format())
console.log((v=-Infinity)+": "+ f.setValue(v).format())
/*
OUTPUT:
0: @ ||0000'0000 %
0: @ ||0000'0000 %
1: @ 1||0000'0000 %
1.1: @ 1||1000'0000 %
-1.1: @ -1||1000'0000 %
0.21215: @ ||2121'5000 %
0.0002: @ ||0002'0000 %
3e+28: @ 30**000**000**000**000**000**000**000**000**000||0000'0000 %
1214564.4564654: @ 1**214**564||4564'6500 %
3e+30: @ 3**000**000**000**000**000**000**000**000**000**000||0000'0000 %
90000: @ 90**000||0000'0000 %
0.2154: @ ||2154'0000 %
0.5655: @ ||5655'0000 %
-0.08754: @ -||0875'4000 %
-1546546500000.0876: @ -1**546**546**500**000||0876'0000 %
999999.99: @ 999**999||9900'0000 %
1234567890123456789012345678901234567890: @ 1**234**567**890**123**456**789**012**345**678**901**234**567**890||0000'0000 %
NaN: @ NOT A NUMBER %
Infinity: @ INFINITY %
-Infinity: @ -INFINITY %

*/


f.setFormat() // set empty format makes it reset to default
f.setFormat({
    intDelim: { delim:" ", step: 3},

    point: ".",

    round: { scale: 8, mode: "half-up" },

    minIntChars: 1,
    minFracChars: 0,
})

console.log((v=0)+": "+ f.setValue(v).format())
console.log((v=-0)+": "+ f.setValue(v).format())
console.log((v=1)+": "+ f.setValue(v).format())
console.log((v=1.1)+": "+ f.setValue(v).format())
console.log((v=-1.1)+": "+ f.setValue(v).format())
console.log((v=0.21215)+": "+ f.setValue(v).format())
console.log((v=0.0002)+": "+ f.setValue(v).format())
console.log((v=0.03e+30)+": "+ f.setValue(v).format()) //
console.log((v=1214564.4564654)+": "+ f.setValue(v).format())
console.log((v=3e30)+": "+ f.setValue(v).format())
console.log((v=+90000)+": "+ f.setValue(v).format())
console.log((v=.2154)+": "+ f.setValue(v).format())
console.log((v=.5655)+": "+ f.setValue(v).format())
console.log((v=-.08754)+": "+ f.setValue(v).format())
console.log((v=-1546546500000.087554564540000)+": "+ f.setValue(v).format())
console.log((v=999999.99)+": "+ f.setValue(v).format())
console.log((v=1234567890123456789012345678901234567890n)+": "+ f.setValue(v).format())
console.log((v=NaN)+": "+ f.setValue(v).format())
console.log((v=+Infinity)+": "+ f.setValue(v).format())
console.log((v=-Infinity)+": "+ f.setValue(v).format())
/*
OUTPUT:
0: 0
0: 0
1: 1
1.1: 1.1
-1.1: -1.1
0.21215: 0.21215
0.0002: 0.0002
3e+28: 30 000 000 000 000 000 000 000 000 000
1214564.4564654: 1 214 564.4564654
3e+30: 3 000 000 000 000 000 000 000 000 000 000
90000: 90 000
0.2154: 0.2154
0.5655: 0.5655
-0.08754: -0.08754
-1546546500000.0876: -1 546 546 500 000.0876
999999.99: 999 999.99
1234567890123456789012345678901234567890: 1 234 567 890 123 456 789 012 345 678 901 234 567 890
NaN: nan
Infinity: ∞
-Infinity: -∞
*/


console.log(NumFormat.defaultOutFormat)
/*
OUTPUT:
{
  intDelim: null,
  fracDelim: null,
  point: '.',
  round: { scale: 8, mode: 'half-up' },
  minIntChars: 1,
  minFracChars: 0,
  nan: 'nan',
  inf: '∞',
  prefix: null,
  suffix: null
}

*/