Now you can handle money without headaches!
npm install --save walletjs
import walletjs from 'walletjs'
const wallet = walletjs.init(100)
console.log(wallet.toString()) => '100,00'
console.log(wallet.currency()) => '$100,00'
constructor(value, locale, currency)
Create a new Wallet object with the initial value.
- {number} value - The value to put on wallet
- {number} [locale=en] - The locale for this wallet
- {number} [currency=USD] - The currency to use in currency formatting.
import Wallet from 'walletjs'
const amount = new Wallet(100)
static init(value, [ locale, currency ]) -> Wallet
Create a new Wallet object with the initial value.
- {number} value - A value to put on wallet
- {number} [locale=en] - The locale for this wallet
- {number} [currency=USD] - The currency to use in currency formatting.
import Wallet from 'walletjs'
const amount = Wallet.init(100)
static fromString(value, [ locale, currency ]) -> Wallet
Create a new Wallet object from String value
- {string} value - A value to put on wallet
- {number} [locale=en] - The locale for this wallet
- {number} [currency=USD] - The currency to use in currency formatting.
import Wallet from 'walletjs'
const amount = Wallet.fromString(100)
add(value) -> Wallet
Adds a value to wallet
- {string} value - A value to put on wallet
import Wallet from 'walletjs'
const amount = Wallet.fromString(100)
const newAmount = amount.add(100)
subtract(value) -> Wallet
Subtract a value to wallet
- {string} value - A value to remove from wallet
import Wallet from 'walletjs'
const amount = Wallet.fromString(100)
const newAmount = amount.subtract(100)
toCurrency([currencyDisplay, { currency }]) -> String
Return a formatted currency of Wallet
- {number} [currencyDisplay=symbol] - How to display the currency in currency formatting.
- {number} [currency=USD] - The currency to use in currency formatting.
import Wallet from 'walletjs'
const amount = Wallet.init(100)
amount.toCurrency() // => $100.00
toString() -> String
Return a formatted value of Wallet
import Wallet from 'walletjs'
const amount = Wallet.init(100)
amount.toString() // => 100.00
- USD: Dollar
- BRL: Real
- EUR: Euro
import { CURRENCY_BRL, CURRENCY_USD, CURRENCY_EUR} from 'walletjs'
- DISPLAY_CODE: 'USD'
- DISPLAY_SYMBOL: '$'
- DISPLAY_NAME: 'Dollar'
import { DISPLAY_CODE, DISPLAY_SYMBOL, DISPLAY_NAME} from 'walletjs'