async-nmbr
Very useful JavaScript Number operator overloading for asynchronous http math operations
Getting Started
npm install --save async-nmbr
npm install --save-dev @babel/core @babel/cli babel-plugin-overload babel-template
- Create a file called
.babelrc
in your projects root directory - Place the following content inside:
{ "plugins": ["overload"] }
- Find out how you can build/compile your project, e.g.:
npx babel src -d lib
Usage
Once the initial setup is completed you'll need to actually overload the operators for the Number
type.
You can do this by simply requiring this package and passing the Number
object in every file that you want to use it in, like this:
require('async-nmbr')(Number);
Now that the operators are overloaded, you can do awesome calculations like:
await (1 + 1);
await (100 - 1);
await (2 * 2);
await (Math.PI / 3);
(Math.PI * 3).then(res => res / 3).then(pi => console.log(pi));
Please note: when using this package you'll always have to await your math calculations (isn't that awesome?)