Skip to content

Repository files navigation

pipeMath: Tinymath fork spooning with pipeLion

Apache Licensenpm

Tinymath is a tiny arithmetic and function evaluator for simple numbers and arrays. Named properties can be accessed from an optional scope parameter and new functions can be added without rebuilding. Enjoy.

NOTE: Tinymath requires an ES6 or newer environment. You can use it with your build system of choice to run in older environments.

See Function Documentation for details on built-in functions available in Tinymath.

import{evaluate}fromtinymath// Simple mathevaluate('10 + 20');// 30evaluate('round(3.141592)')// 3// Named propertiesevaluate('foo + 20',{foo: 5});// 25// Arraysevaluate('bar + 20',{bar: [1,2,3]});// [21, 22, 23]evaluate('bar + baz',{bar: [1,2,3],baz: [4,5,6]});// [5, 7, 9]evaluate('multiply(bar, baz) / 10',{bar: [1,2,3],baz: [4,5,6]});// [0.4, 1, 1.8]

Adding Functions

Functions can be injected, and built in function overwritten, via the 3rd argument to evaluate:

import{evaluate}fromtinymathevaluate('plustwo(foo)',{foo: 5},{plustwo: function(a){returna+2;}});// 7

Parsing

You can get to the parsed AST by importing parse

import{parse}fromtinymathparse('1 + random()')/*{ "name": "add", "args": [ 1, { "name": "random", "args": [] } ]}*/

Notes

  • Floating point operations have the normal Javascript limitations

About

TinyMath fork spooning with pipeLion

Resources

Stars

0 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages