One lib to rule them all (nemathode.js)
Quick links
What Is Nemathode?
Nemathode is array based mathematical expression notation (further in the text: nematode/s, expression/s).
It was created as an intermediate type of mathematical expressions, as close as possible to the language (JavaScript as first experiment), in order to get the opportunity to bring the entire diversity of the ecosystem of mathematical libraries under one denominator
What is the purpose of this?
Sometimes we have to change math core on the fly but keep all the API differences outside of our attention. Refactoring process is slow, tedious, and error prone so.
With Nemathode we can
- use whole bunch of libs and configure them them “under one roof”
- add new methods, operators, constants and choose naming for them
- calibrate computation accuracy on the fly by
- changing already declared method implementations
- replacing math constants with more suitable values
What Is Nemathode.js?
Nemathode.js is a JavaScript library for nemathodes evaluation. It lets you to combine any number of libraries while leaving the format of the expressions unchanged (aggregator of solutions under one format)
Examples of using
Configuration example (pure js)
You can view this and more other examples of configurations here
mathConstants
Literally, mathematical constants
functions
Set of records with implementations
toInputType
It seems excessive but not everyone using pure js functionality. There are set of libraries where intermediate type is not a number, for example: bignumber.js, decimal.js etc (we have on our website set of configs for most popular libs). So you can configure entry handler for them like
toOutputType
Opposite of toInputType. See at an example
binaryOperators
Let’s look at one of examples
It’s a configuration for operator that consists from two (by now) fields: precedence, implementation (the same as in functions).
Api — standart
Api — with love ❤️
Inspired by
- stackoverflow post about some task with similar syntax
- a few tasks in codewars (couldn’t find it unfortunately)
- math.js library and it’s evaluation mechanism
Future
- Full TS coverage
- Unary operands (still thinking, need your opinion)
- Function arguments evaluation
- Overcome limitations with different return types: number, boolean
A few last words
If you have any bugs, suggestions, wishes, please let me know. I’m glad to hear any feedback you have. Use main website and repo in order to get info about this solution (syntax and JS lib itself)
Have a nice coding or nemathoding)