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

number-formatter

v1.2.0

Published

Lightweight & Fast JavaScript Number Formatter

Downloads

20,044

Readme

Javascript Number Formatter

Lightweight & Fast JavaScript Number Formatter

Build Status

Introduction

This standalone number formatter is intended to be short and fast. As they are the main factors for a high performance JavaScript app. Development release is as short as < 120 lines including license info, blank lines and comments. And production release is less than 1,200 bytes.

numberFormatter( "#,##0.####", 1234567.890 );  // output: "1,234,567.89"
numberFormatter( "$ #,###.00", -1234567.890 ); // output: "$ -1,234,567.89"

Features

  • Short, fast, flexible yet standalone.
  • Accept standard number formatting like #,##0.00 or with negation -000.####.
  • Accept any country format like # ##0,00, #,###.##, #'###.## or any type of non-numbering symbol.
  • Accept any numbers of digit grouping. #,##,#0.000 or #,###0.## are all valid.
  • Accept any redundant/fool-proof formatting. ##,###,##.# or 0#,#00#.###0# are all OK.
  • Auto number rounding.
  • Simple interface, just supply mask & value like this: numberFormatter( "0.0000", 3.141592).
  • Include a prefix & suffix with the mask

Limitations

  • No scientific/engineering formatting.
  • Not for date or phone formation.
  • No color control.
  • No prefix or suffix is allowed except leading negation symbol. So $#,##0.00 or #,###.##USD will not yield expected outcome. Use '$'+numberFormatter('#,##0.00', 123.45) or numberFormatter('#,##0.00', 456.789) + 'USD'
  • The prefix or suffix can not include any numbers (0-9), dashes (-), or plus signs (+).

Installation

npm

$ npm install --save number-formatter

bower

$ bower install --save number-formatter

Note

When there's only one symbol is supplied, system will always treat the single symbol as Decimal. For instance, numberFormatter( '#,###', 1234567.890) will output 1234567,890. To force a single symbol as Separator, add a trailing dot to the end like this: numberFormatter( '#,###.', 1234567.890) which will then output 1,234,567.

A demo/sample page with few examples is provided (DEMO). The code is safe to be minimized using Google Compiler in Advanced mode.

Version

V1.1.5 (1/26/2015)

  • Change name in bower.json & package.json to "number-format.js".
  • Update readme with installation instructions.

v1.1.4 (1/26/2015)

  • Add AMD & NodeJS compatibility (UMD). Thanks MadMG!
  • Renamed variables & code cleanup to make it more readable.

v1.1.3 (11/12/2014)

  • Fix bower link to point to the production version. Thanks marcelboettcher!
  • Minor code & demo cleanup.

v1.1.2 (6/22/2014)

  • Remove negative sign from results with a value of zero.
  • Added more examples to demo page.