These are ReasonML/Bucklescript bindings for Numeral.js.
Run this command in your project's directory:
npm i @johnridesabike/bs-numeral
And then add the project to the bs-dependencies
array in your bsconfig.json
file, like so:
"bs-dependencies": [
"@johnridesabike/bs-numeral"
]
There are a few other Numeral.js bindings, and it's easy to write an simple binding yourself if you only use a few of its functions. This project aims to be a complete implementation. To help ensure accuracy, it uses (mostly) the same tests as vanilla Numeral.js. The goal is to provide a hassle-free replacement for people used to using Numeral.js in their JavaScript.
As with most ReasonML bindings, the interface files are mostly self-documenting. You can view this project's interface here.
Numeral.js uses several JS paradigms that don't directly translate to ReasonML, but this tries to make the transition as smooth as possible.
Notable differences between this binding and vanilla Numeral.js:
Numeral.make
.Numeral
module only accepts floats. This is because once a number gets passed to the JavaScript side, it essentially becomes a float anyway. Numeral
always returns values as floats.Numeral.String
. The bindings for that module are almost the same as the base module, except that it accepts strings and returns option
s. By keeping the two modules separate, we don't have to deal with option
cases every time we use the module.Null
as input.isNumeral
.numeral.format
has been turned into Numeral.defaultFormat
, Numeral.format
, and Numeral.formatRound
.add
, subtract
, etc., can only take floats (or strings, for the String
module).numeral._
) are available in Numeral.Helpers
. They are not documented or tested by vanilla Numeral.js, so their bindings here are not well tested either. Some of them are irrelevant in ReasonML anyway.makeConfig
, and the format configuration object is created with makeFormat
. The exact bindings are at the top of the rei file.You'll notice that this binding is very strict about what types are accepted as input. Numeral.js can throw a runtime error with malformed inputs, or simply return null
. Strictness helps ensure that corrupt data doesn't escape into the rest of your code. If you find the strictness too limiting, open an issue with your situation.
npm run build
npm run watch
If you use vscode
, Press Windows + Shift + B
it will build automatically