smh / rescript-dinero

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rescript-dinero

dinero.js bindings for ReScript

Installation

Using NPM:

npm install --save @bettercart/rescript-dinero

Using Yarn:

yarn add @bettercart/rescript-dinero

Then add @bettercart/rescript-dinero to bs-dependencies in your bsconfig.json:

{
  ...
  "bs-dependencies": ["@bettercart/rescript-dinero"]
}

Usage

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, ()),
)

<div> {dinero.toFormat(. "$0,0.00", #HALF_AWAY_FROM_ZERO)->React.string} </div>

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

  Dinero.setLocale(Dinero.dineroJs, "us-en")
  
  Dinero.setLocale(Dinero.dineroJs, "us-en")

Access Globals:

  Dinero.dineroJs.globalLocale

About


Languages

Language:ReScript 100.0%