One lib to rule them all (nemathode.js)

Kas Elvirov
2 min readMay 26, 2021


Short description

Quick links

  1. Demo
  2. Docs

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

example (nemathode === math expression as we used to)

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

  1. use whole bunch of libs and configure them them “under one roof”
  2. add new methods, operators, constants and choose naming for them
  3. calibrate computation accuracy on the fly by
  • changing already declared method implementations
  • replacing math constants with more suitable values
Combine any libs you like and evaluate expressions with single syntax

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

Binary operations
Functions (number and boolean)
Math constants
Nemathode with nested expressions

Configuration example (pure js)

You can view this and more other examples of configurations here

Nemathode PureJS configuration


Literally, mathematical constants


Set of records with implementations


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

toInputType configuration example


Opposite of toInputType. See at an example

toOutputType configuration example


Let’s look at one of examples

operator configuration example

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 ❤️

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


  1. Full TS coverage
  2. Unary operands (still thinking, need your opinion)
  3. Function arguments evaluation
  4. 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)