These are ReasonML/Bucklescript bindings for Numeral.js.
🏁 Use in your project
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:
🧐 Why use this bs-numeral?
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:
- You create a numeral object with
Numeralalways returns values as floats.
- To use a string as input, use
Numeral.String. The bindings for that module are almost the same as the base module, except that it accepts strings and returns
options. By keeping the two modules separate, we don't have to deal with
optioncases every time we use the module.
- bs-numeral cannot recieve
- Some functions are not bound because they're irrelevant in ReasonML, such as
- Some functions that can take several optional inputs are split into multiple functions. For example:
numeral.formathas been turned into
- The math functions,
subtract, etc., can only take floats (or strings, for the
- The helper functions (
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.
- Numeral.js uses has several functions that accept or return JS objects for configuration. This binding uses BuckleScript abstract types as a replacement, which are rely on helper functions. For example, the confguration object is created with
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
Windows + Shift + B it will build automatically
- @johnridesabike - Idea and initial work