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

money-formatter

v0.1.4

Published

Simple Javascript library for currency formatting

Downloads

3,160

Readme

money-formatter

Simple Javascript library for currency formatting.

It allows you to format currencies without specifying any formatting arguments besides the currency code and number value itself, thanks to rules from the currency-format package.

Travis build status npm version Bower version Dependency Status devDependency Status

Installation

Install from npm or bower

npm install money-formatter
# or bower install money-formatter

Usage

For Node.js, Browserify and Webpack

You can import whole module

var moneyFormatter = require('money-formatter');
// Or in ES6
// import moneyFormatter from 'money-formatter';
moneyFormatter.format('USD', 10); // => '$10.00'

Or use separate functions

import { format } from 'money-formatter';
format('EUR', 123); // => '€123.00'

Other

You can add UMD distribution (from dist/money-formatter.js) directly to HTML and use it with AMD loader or from the global object

<script src="path/to/dist/money-formatter.js"></script>
<script>
    var moneyFormatter = require('money-formatter');
    // Or use window.moneyFormatter if you are not using requirejs;
</script>

API

format(currencyCode, amount, [fractionSize=2, useAlphaCode=false]) => string

Formats number based on the specified currency params.

If fractionSize is not provided, the currency's fraction size from ISO 4217 will be used. It fallbacks to default value 2 if currency have no fraction size. useAlphaCode is a flag to use alphabetic code (e.g. 'USD') instead of commonly used symbol (e.g. '$') and apply basic formatting from formatSimple. You may want to use it in ASCII-only environments or if you want to align output layout.

moneyFormatter.format('USD', 1234567.89); // => '$1,234,567.89'
moneyFormatter.format('RUR', 10, 0); // => '10 ₽'
moneyFormatter.format('USD', 10, 0, true); // => '10 USD'

formatSimple(currencyName, amount, [fractionSize=2]) => string

moneyFormatter.formatSimple('$$$', 123, 0); // => '123 $$$'

formatToHTML(currencyCode, amount, [fractionSize=2, useAlphaCode=false]) => string

Same as format but outputs string with HTML element for proper bidirectional output in browsers.

moneyFormatter.formatToHTML('SAR', -10); // => '<span dir="rtl">-10.00 ﷼</span>'

It will look like -10.00 ﷼

Development

  1. Clone this repository
  2. Run npm install inside cloned repository directory to install dependencies
  3. To test the code during development run npm test to run tests once or use npm run watch to watch for changes and autorun tests
  4. Execute npm run build to build distributable files to the dist/ dir

License

The MIT License.

See LICENSE