Files
currency/README.md
George Suntres 4e023f06d4
Some checks failed
Node.js CI / build (18.x) (push) Has been cancelled
Node.js CI / build (20.x) (push) Has been cancelled
Node.js CI / build (22.x) (push) Has been cancelled
first commit
2026-05-11 16:02:02 -04:00

52 lines
922 B
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## Currency formatter based on Intl.NumberFormat
```@needme/currency``` offers a convenient way to format currencies using multiple configurations.
*Install*
```bash
npm i --save @needem/currency
```
*Basic use*
```js
import { currency } from '@needme/currency'
currency.add({
locale: 'en-US',
iso: 'usd'
})
console.log(currency.format(100.99))
// should display $100.00
```
You can configure multiple formatters in one go by using the ```init``` function.
Choose which one to use with the ```use``` function.
*Initialize with multiple locales*
```js
import { currency } from '@needme/currency'
currency.init({
default: 'fr',
configs: [{
locale: 'en-US',
iso: 'usd',
}, {
name: 'mx',
locale: 'es-MX',
iso: 'mxv'
}, {
locale: 'fr',
iso: 'eur',
fromCents: true
}]
})
currency.use('mx')
currency.format(120.56)
// should display MXV 120.56
```