Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including @easymoney/currencies with all npm packages installed. Try it out:

var currencies = require("@easymoney/currencies")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@easymoney/currencies v1.0.2

Best way to do money in js


easy money logo

@easymoney/currencies

npm-currencies ![npm type definitions] deps-currencies size-currencies GitHub

Open in docs

Install

npm install @easymoney/currencies

or

yarn add @easymoney/currencies

or

CDN

Usage

import { createCurrencyList } from '@easymoney/currencies';

const currency = { minorUnit: 2, code: 'XBT' };
const currency1 = { minorUnit: 5, code: 'DXBT' };
const currencyArr = [currency, currency1];

const list = createCurrencyList(currencyArr);

const result = list.getCurrencies();
// =>   { XBT: {minorUnit: 2, code: "XBT"},
//       DXBT: {minorUnit: 5, code: "DXBT"} }

const resultLength = Object.keys(result).length === currencyArr.length ? true : false;
// => true

import { createCurrencyList, createAgregatedCurrencyList } from '@easymoney/currencies';

const currency = { minorUnit: 2, code: 'XBT' };
const currency1 = { minorUnit: 5, code: 'DXBT' };
const currencyArr = [currency, currency1];

const list = createCurrencyList(currencyArr);
const agregatedList = createAgregatedCurrencyList([list]);

const result = agregatedList.subUnitFor("XBT");
// => 2

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free