2.0.0 • Published 4 years ago

monetary-value v2.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

monetary-value

Returns Money not NaN. Money parsing and manipulation library with currency support.

Install

Through npm:

npm i monetary-value

Thorugh CDN:

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/monetary-value@1"></script>

Usage

Simple API:

const Money = require('monetary-value')

const price = new Money(123.45, 'USD')
// %12 discount
price.discount(12)
// %7 increase
price.increase(7)
// show final price to the user
price.asString() // "USD 116.24"
price.asNumber() // 116.24
price.asFancyString() // $ 116.24

See tests folder for more examples.

Exchange Rates

Exchange rates can be set by:

price.exchangeRates = {
  USD: 1,
  EUR: 0.92
  /* others */
}
// then we can exchange
price.exchange('EUR').asNumber()