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

numformat.js

v0.2.0

Published

number, decimal, integer, money and currency formatting library, with two way custom format/unformat symbols and patterns

Downloads

2

Readme

numformat.js

Build Status

numformat.js is a tiny JavaScript library for number, decimal, integer, money and currency formatting/unformatting.

The library allows two way format and unformat function with custom symbols and patterns.
The unformat functions use the original format options to parse formatted values.

The library is lightweight and works great client-side or server-side.

Install

NPM

npm install numformat.js

Bower

bower install numformat.js

How to use

var nf = require('numformat.js');

###format Functions

  • value integer/float value to format
  • options override default language options [see available options]

####formatCurrency

//value = 1234.123
var formattedString = nf.formatCurrency(value [, options]); //1,234.12$

####formatNumber

//value = 1234.567
var formattedString = nf.formatNumber(value [, options]); //1,234.12

####formatInteger

//value = 1234.123
var formattedString = nf.formatInteger(value [, options]); //1,234

###unformat Functions

  • value integer/float value to format
  • options override default language options [see available options]
  • toFixed
    • false [default] unformat functions do not apply a fixed number of decimal places to the unformatted value
    • true use decimalPlaces option to apply a fixed number of decimal places to the unformatted value

####unformatCurrency

//value="1,234.123$"
var floatValue = nf.unformatNumber(value [, options] [, toFixed=false]); //1234.123

####unformatNumber

//value="1,234.123"
var floatValue = nf.unformatNumber(value [, options] [, toFixed=false]); //1234.123

####unformatInteger

//value="1,234.123"
var intValue = nf.unformatInteger(value [, options] [, toFixed=false]); //1234

###available options

  • decimalPlaces - decimal places
  • decimalSeparator - decimal separator symbol
  • thousandSeparator - thousand separator symbol
  • currencySymbol - currency symbol
  • negativeSymbol - negative symbol
  • pattern - pattern used to replace placeholders with number and symbol parts
    • %n - negative symbol placeholder
    • %i - integer part placeholder
    • %s - decimal separator placeholder
    • %d - decimal part placeholder
    • %c - currency symbol placeholder
  • emptyValue - value to return when the value is empty
  • toFixed - [only format functions]
    • true [default] format functions apply fixed number of decimalPlaces
    • false format functions ignore decimalPlaces option

##Localization

A few locale files are available in /i18n folder.
Locale can be dinamically customized by adding and completely/partially overriding existing ones, using the loadLanguage method:

nf.loadLanguage('en', {
  integer: {
      decimalPlaces: 0,
      decimalSeparator: '.',
      thousandSeparator: ',',
      currencySymbol: '',
      negativeSymbol: '-',
      pattern: '%n%i%s%d%c',
      emptyValue: '',
      toFixed: true
  },
  number: {
      decimalPlaces: 2,
      decimalSeparator: '.',
      thousandSeparator: ',',
      currencySymbol: '',
      negativeSymbol: '-',
      pattern: '%n%i%s%d%c',
      emptyValue: '',
      toFixed: true
  },
  currency: {
      decimalPlaces: 2,
      decimalSeparator: '.',
      thousandSeparator: ',',
      currencySymbol: '$',
      negativeSymbol: '-',
      pattern: '%n%i%s%d%c',
      emptyValue: '',
      toFixed: true
  }
});

loadLanguage immediately sets the current language to the loaded language key.
To manually set the current language use:

nf.language = 'en';