Skip to content

JavaScript (TypeScript) math expression evaluator library

Notifications You must be signed in to change notification settings

tsv2013/expression-evaluator

Repository files navigation

expression-evaluator

JavaScript (TypeScript) math expression evaluator library

Build Status

How to compile this repo

Sample usage

Basic functions

  var ee = new ExpressionEvaluator();
  var res1 = ee.evaluate("6 / 2 + 1 + 2*2 - 5");
  var res2 = ee.evaluate("false or false");

Custom functions

  ExpressionEvaluator.operations["myFunc"] = {
    priority: 100,
    function: (a, b) => (a+b)/2
  }
  ExpressionEvaluator.operations["mySq"] = {
    priority: 100,
    function: a => a*a
  }
  ExpressionEvaluator.operations["mySecond"] = {
    priority: 100,
    function: (a, b, c) => b
  }
  var ee = new ExpressionEvaluator();
  var result = ee.evaluate("mySecond(5, myFunc(2,4), mySq(2))");

Evaluation context

  var ee = new ExpressionEvaluator();
  var evaluationContext = { propertyName: 1 };
  var result = ee.evaluate("{propertyName} + 1", evaluationContext);

About

JavaScript (TypeScript) math expression evaluator library

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published