ts-expression-evaluator
Context-based expression evaluator.
install
- npm
npm install ts-expression-evaluator
- yarn
yarn add ts-expression-evaluator
Quick start
const context = id: 10 name: 'FED' count: 10 staffs: id: 1 name: 'Tina' id: 2 name: 'James' // math // 3 // eval from context // 'FED' // 'Tina' // 20 // === // false // register custom function ') // It's FED // array filter // [{id: 1, name: 'Tina'}]
Details
Unary Operators
Operation | Symbol |
---|---|
Negate | ! |
Binary Operators
Operation | Symbol |
---|---|
Add, Concat | + |
Subtract | - |
Multiply | * |
Divide | / |
Logical Operators
Operation | Symbol |
---|---|
Logical AND | && |
Logical OR | || |
Comparisons
Comparison | Symbol |
---|---|
Equal | == |
Not equal | != |
Greater than | > |
Greater than or equal | >= |
Less than | < |
Less than or equal | <= |
Native Types
Type | Examples |
---|---|
Booleans | true , false |
Strings | "Hello "user"", 'Hey there!' |
Numerics | 6, -7.2, 5, -3.14159 |
Arrays | ['hello', 'world!'] |
API
evaluate(exp: string, context: object): any
registerFunction(name: string, func: Function): void
registerFunctions(funcs: {[key: string]: Function}): void
License
MIT