Skip to content

Latest commit

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

expression-eval

JavaScript expression parsing and evaluation, safely.

Powered by jsep.

Installation

npm install --save expression-eval

Parsing

constexpr=require('expression-eval');constast=expr.parse('1 + foo');

The result of the parse is an AST (abstract syntax tree), like:

{
"type": "BinaryExpression",
"operator": "+",
"left": {
"type": "Literal",
"value": 1,
"raw": "1"
},
"right": {
"type": "Identifier",
"name": "foo"
}
}

Evaluation

constexpr=require('expression-eval');constast=expr.parse('a + b / c');// abstract syntax tree (AST)constvalue=expr.eval(ast,{a: 2,b: 2,c: 5});// 2.4

Compilation

constexpr=require('expression-eval');constfn=expr.compile('foo.bar + 10');fn({foo: {bar: 'baz'}});// 'baz10'

License

MIT License.

About

JavaScript expression parsing and evaluation, safely.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages