Getting Started

easymoney is javascript library for working with monetary values

Installation

npm install --save @easymoney/money
yarn add @easymoney/money

For more details, see the Installation page.

Help and Discussion

You can also ask questions on Stack Overflow using the #easymoney tag.

If you have a bug report or need to leave other feedback, please file an issue on the Github repo

Basic examples of api

Math operations

Add

import { createMoney } from '@easymoney/money';
const money1 = createMoney({ amount: 100, currency: 'USD' });
const money2 = createMoney({ amount: 106, currency: 'USD' });
const money3 = money1.add(money2).getAmount();
// => 206

Multiplication

import { createMoney } from '@easymoney/money';
const money1 = createMoney({ amount: 100, currency: 'USD' });
const money2 = createMoney({ amount: 2, currency: 'USD' });
const money3 = money1.multiply(money2).getAmount();
// => 200

Currencies

import { createCurrencyList, isoCurrencyList, currencies } from '@easymoney/currencies';
/* it's equal already prepared isoCurrencyList, but here just for example */
const handmadeCurrencyList = createCurrencyList(currencies);
// check if list contains XBT
const isXBTExist = isoCurrencyList.contains({ minorUnit: 2, code: 'XBT' });
// => false
// check if list contains USD
const isUSDExist = isoCurrencyList.contains({ minorUnit: 2, code: 'USD' });
// => true