Currency conversion lib that we're hoping to make usable across many languages thru bindings
use girlmath;
fn main() {
let payout_amt = girlmath::convert("3", "USD", "GHS", "12.10").unwrap();
assert_eq!("36.30", payout_amt);
}
girlmath is available on npm and can be installed by running the following command:
npm install @tbd54566975/girlmath
Once installed, girlmath
can be used like so:
import girlmath from '@tbd54566975/girlmath'
const btc = girlmath.convert('10', 'USD', 'BTC', '0.000023')
Note
girlmath only ships esm
Instructions on how to install and configure rust can be found here
This project uses just
as a command runner. Installation instructions can be found here
To generate JS bindings, it's necessary to compile the girlmath library into WebAssembly (WASM). This process involves setting up a specific Rust compilation target which can be done by running the following:
rustup target add wasm32-unknown-unknown
This project uses wasm-pack
to generate wasm which can be installed by running:
cargo install wasm-pack
We use node
to:
- bundle the js produced by
wasm-pack
into a single file that can be used in both the browser and node environments - run tests in both the browser and node environments
This project is using node v20.5.0
. You can verify your node
and npm
installation via the terminal:
$ node --version
v20.5.0
If you don't have node
installed, feel free to choose whichever approach you feel the most comfortable with. If you don't have a preferred installation method, we recommend using nvm
(aka node version manager). nvm
allows you to install and use different versions of node. It can be installed by running brew install nvm
(assuming that you have homebrew)
Once you have installed nvm
, install the desired node version with nvm install vX.Y.Z
. After installation, you can run nvm use
to automatically tell nvm
which node
version to use (this will be picked up from the target version noted in .nvmrc
):
nvm use
Found 'bindings/girlmath-js/.nvmrc' with version <v20.5.0>
Now using node v20.5.0 (npm v9.8.0)
Note
More info specific to js bindings can be found in the girlmath-js directory
command | description |
---|---|
cargo clean |
deletes rust target dirs |
make clean_js |
deletes all autogenerated js dirs |
make js |
generates js bindings |