https://github.com/bettercart/rescript-dinero
https://github.com/bettercart/rescript-dinero
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bettercart/rescript-dinero
- Owner: bettercart
- Created: 2021-01-20T20:32:05.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-10T17:37:28.000Z (almost 3 years ago)
- Last Synced: 2025-04-18T12:19:36.840Z (9 months ago)
- Language: ReScript
- Size: 10.7 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-list - rescript-dinero
README
# rescript-dinero
[dinero.js](https://dinerojs.com/) bindings for ReScript
## Installation
Using NPM:
```sh
npm install --save @bettercart/rescript-dinero
```
Using Yarn:
```sh
yarn add @bettercart/rescript-dinero
```
Then add `@bettercart/rescript-dinero` to `bs-dependencies` in your `bsconfig.json`:
```js
{
...
"bs-dependencies": ["@bettercart/rescript-dinero"]
}
```
## Usage
```res
type currency = [
| #USD
| #CAD
| #EUR
]
type money = {
amount: int,
currency: currency,
}
let money = {
amount: 100,
currency: #USD
}
let dinero = Dinero.create(
Dinero.options(~amount=money.amount, ~currency=money.currency->Money.currencyToJs, ()),
)
{dinero.toFormat(. "$0,0.00", #HALF_AWAY_FROM_ZERO)->React.string}
```
## Globals
Dinero has an export for it self global instance `Dinero.dineroJs` - this will be needed to use the global setters or getters.
Set Globals
```res
Dinero.setLocale(Dinero.dineroJs, "us-en")
Dinero.setLocale(Dinero.dineroJs, "us-en")
```
Access Globals:
```res
Dinero.dineroJs.globalLocale
```