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

gammamoney

v0.0.2

Published

Library for handling the money values. This is a fork from bigmoney.js Based on big.js library for arbitrary-precision decimal arithmetic. Support multiple currencies.

Downloads

5

Readme

bigmoney.js

Library for handling the money values. Support multiple currencies. Based on big.js library for arbitrary-precision decimal arithmetic.

Load

The library is the single JavaScript file bigmoney.js (or bigmoney-all.min.js, which is bigmoney.js with all dependencies and minified).

It can be loaded via a script tag in an HTML document for the browser

<script src='./relative/path/to/bigmoney-all.min.js'></script>

or as a CommonJS, Node.js or AMD module using require.

For Node, put it in a node_modules directory within the directory and use require('bigmoney').

To load with AMD loader libraries such as requireJS:

require(['bigmoney'], function(BigMoney) {
    // Use BigMoney here in local scope. No global Big.
});

Use

Setup settings

Money.settings = {
    base: "USD",
    rates: {
        USD : 1, //this is base. Other rates relative to the base.
        RUB: 35.2448,
        EUR: 1/1.3485,
        JPY: 102.02
    },
    format: "%decimal %currency"
}

Constructor

var eur  = Money(100, 'EUR');
var usd  = Money(100, 'EUR').convert('USD');
var usd2 = Money(250);   //equal Money(250, Money.settings.base);

//get numeric value

usd.valueOf();             //134.85

//get string value

usd.toString();            //"134.85"

//get formatted string

usd.format();             //"134.85 USD"
usd.format("$ %decimal"); //"$ 134.85"

Convert currency

var usd = eur.convert('USD');
//or
var usd = Money(100, 'EUR').convert('USD')
//or
console.log( Money(100, 'EUR').convert('USD').format() )  //"134.85 USD"

Setup custom formatter

Money.formatter = function(decimal, currency, formatParam) {
    switch(currency) {
        case 'USD': return "$" + decimal;
        case 'EUR': return "€" + decimal;
        case 'JPY': return "¥" + decimal;
        default: return decimal + " " + currency;
    }
}

Money(100, 'EUR').format();                //"€100"
Money(100, 'EUR').convert("JPY").format(); //"¥13757.4"
Money(100, 'EUR').convert("RUB").format(); //"4752.76 RUB"

Arbitrary-precision decimal arithmetic provided by big.js library

usd.valueOf();             //134.85
usd.plus(100).valueOf();   //234.85
usd.minus(100).valueOf();  //34.85
usd.times(2).valueOf();    //269.7
usd.div(2).valueOf();      //67.43
usd.mod(1).valueOf();      //0.85

Build

For Node, if uglify-js is installed globally ( npm install uglify-js -g ) then

cat node_modules/big.js/big.js bigmoney.js | uglifyjs -o bigmoney-all.min.js

Author

Eugene Demchenko [email protected] skype: demchenkoe

Licence

See LICENCE.

Thanks

Big thanks for Michael Mclaughlin (author of big.js library).