morph-expressions
An extremely efficient and flexible parser for Math or Logical expression using Javascript. It has all the basic functions supported with extensive support for new functions, variable etc.
##Install
$ npm install morph-expressions
Usage
import Parser from 'morph-expressions';
const parser = new Parser();
const compiled = parser.parse('1 + 1');
compiled.eval();
You can also specify scope
:
const compiled = parser.parse('x + 1 - y == 0');
compiled.identifiers;
compiled.eval({ x: 2, y: 3 });
parser.parseAndEval('x + 1 - y == 0', { x: 2, y: 3 });
parser.parseAndEval('foo.bar[1] == 5', { foo: { bar: [4, 5, 6] } });
For register the custom function or computed properties
parser.registerFunction('sqr', value => value * value);
parser.registerProperty('foo', scope => 'bar');
parser.parseAndEval('sqr(sqr(x))', { x: 2 });
parser.parseAndEval('foo', { x: 2 });
Test
To execute tests for the library, install the project dependencies once:
npm install
Then, the tests can be executed:
npm test