1.2.1 • Published 7 years ago

walletjs v1.2.1

Weekly downloads
17
License
MIT
Repository
github
Last release
7 years ago

"Mo money, No problems" - walletjs

Build Status Coverage Status Code Climate

IMPORTANT: We use big.js to handle huge numbers.

Now you can handle money without headaches!

API Reference

Install

npm install --save walletjs
or
yarn add walletjs

Examples

import Wallet, { Money } from 'walletjs'

const money = Money.init(100)
const wallet = Wallet.init(money)
console.log(wallet.getAmount(money.currency))

const money2 = Money.init(100)
const newWallet = wallet.add(money2)
console.log(newWallet.getAmount(money2.currency))

convertCurrency

import Wallet, { Money } from 'walletjs'

const money = Money.init(100, { currency: 'BRL' } )
const brlWallet = Wallet.init(money)
const usdWallet = brlWallet.convertCurrency('BRL', 'USD', 3.09)

console.log(brlWallet.getAmount('BRL')) => '100.00'
console.log(brlWallet.getAmount('USD')) => '0.00'

console.log(usdWallet.getAmount('BRL')) => '0.00'
console.log(usdWallet.getAmount('USD')) => '309.00'

no problems with float errors

// on javascript
const a = 0.1
const b = 0.2
console.log(a + b) => 0.30000000000000004

// on walletjs
const money = Money.init(0.2)
money.add(0.1) => returns 0.3
1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago