-
Notifications
You must be signed in to change notification settings - Fork 9
API Reference
Create a new Wallet object.
{Map}
A key/value Map
with currency/value
import Wallet from 'walletjs'
const wallet = new Wallet()
Returns a new Wallet with initial money.
{Money []}
An array of money.
import Wallet, { Money } from 'walletjs'
const money1 = Money.init(100)
const money2 = Money.init(100)
const wallet1 = Wallet.init(money1, money2)
const wallet2 = Wallet.init.apply(this, [money1, money2])
Returns an amount by currency.
{string}
A money currency.
import Wallet, { Money } from 'walletjs'
const money1 = Money.init(100)
const money2 = Money.init(100)
const wallet = Wallet.init(money1, money2)
wallet.getAmount('USD')
wallet.getAmount(money1.currency)
Return a new Wallet with added Money.
{Money}
The money that will be added.
import Wallet, { Money } from 'walletjs'
const money = Money.init(100)
const wallet = Wallet.init()
wallet.add(money)
Return a new Wallet with subtracted Money.
{Money}
The money that will be subtracted.
import Wallet, { Money } from 'walletjs'
const money = Money.init(100)
const wallet = Wallet.init()
wallet.subtract(money)
Return a new Wallet with new currencies.
{currency}
{currency}
{number}
import Wallet, { Money } from 'walletjs'
const money = Money.init(100)
const wallet = Wallet.init()
wallet.convertCurrency('USD', 'BRL', 0.39)
Create a new Money object with the initial value.
{number}
The value to put on wallet
{number} [default=en]
The locale for this money
{number} [default=USD]
The currency to use in currency formatting.
{number} [default=2]
The currency fractionals to use in currency formatting
import { Money } from 'walletjs'
const amount = new Money(100, {
locale: 'en',
currency: 'USD',
currencyFractionals: 2,
})
A static
method to generate a new Money object with the initial value.
{number}
The value to put on wallet
{number} [default=en]
The locale for this money
{number} [default=USD]
The currency to use in currency formatting.
{number} [default=2]
The currency fractionals to use in currency formatting
import { Money } from 'walletjs'
const amount = Money.init(100, {
locale: 'en',
currency: 'USD',
currencyFractionals: 2,
})
A static
method to generate a new Money object from String.
{string}
The value to put on wallet
{number} [default=en]
The locale for this money
{number} [default=USD]
The currency to use in currency formatting.
{number} [default=2]
The currency fractionals to use in currency formatting
import { Money } from 'walletjs'
const amount = Money.fromString('100', {
locale: 'en',
currency: 'USD',
currencyFractionals: 2,
})
Adds a value to money entity. Returns a Money.
{number}
The value to put on wallet
import { Money } from 'walletjs'
const amount = Money.init(100)
const newAmount = amount.add(100)
Subtract a value from money entity. Returns a Money.
{number}
The value to remove from wallet
import { Money } from 'walletjs'
const amount = Money.init(100)
const newAmount = amount.subtract(100)
Multiply your money by value. Returns a Money.
{number}
The value to multiply your money
import { Money } from 'walletjs'
const amount = Money.init(100)
const newAmount = amount.multiplyBy(2)
Divide your money by value. Returns a Money.
{number}
The value to divide your money
import { Money } from 'walletjs'
const amount = Money.init(100)
const newAmount = amount.divideBy(2)
Return the current value on Money
import { Money } from 'walletjs'
const amount = Money.init(100)
console.log(amount.getValue())
Return Money locale
import { Money } from 'walletjs'
const amount = Money.init(100, { locale: 'pt-BR' } )
console.log(amount.getLocale()) => 'pt-BR'
Return a formatted currency of Money
{string} [default=symbol]
How to display the value in currency formatting. Available formats: [symbol, code, name]
import { Money } from 'walletjs'
const amount = Money.init(100)
console.log(amount.toCurrency())
Return a formatted value of Money
import { Money } from 'walletjs'
const amount = Money.init(100)
console.log(amount.toString())