Update typings.
- Add a new options,
allowStringMembersthat can be used to allow strings to be used for member access. This can be useful when needing to evaluate expressions against objects that have properties that do not follow traditional C style variable naming conventions.
- Fix a bug in the coalesce (??) operator which was preventing it from working on anything except numbers and Booleans.
- Add 'not in' operator, "c" not in ["a", "b"].
- Fork of https://github.com/silentmatt/expr-eval which appears to be abandoned
- Add undefined as an expression keyword.
- Add support for setting variables to undefined.
- Operators/functions return undefined if they operate on undefined.
- Array/structure references act like JavaScript ?.
- Add coalesce operator ??; operator returns the right side if the left side is undefined, null, Infinity, or a Nan, the left side otherwise.
- String concatenation using the + operator on two strings.
- Support for custom functions returning promises; expression evaluation will stop until the promise resolves. Note that this means that the return value of evaluate will be a promise.
- Support for invoking a callback for custom variable name resolution if an expression references an unknown variable. This allows things like environment variables to be exposed in expressions.
- Support for SQL style case/when blocks, both for switch style cases and for if/else/if style cases.
- Construction of objects in expressions using JavaScript style syntax.
- Value conversion using the AS operator; note that this is disabled by default.
- Added non-default exports when using the ES module format. This allows
import { Parser } from 'expr-eval'to work in TypeScript. The default export is still available for backward compatibility.
- Added the
if(condition, trueValue, falseValue)function back. The ternary operator is still recommended if you need to only evaluate one branch, but we're keep this as an option at least for now.
- Better support for arrays, including literals:
[ 1, 2, 3 ]and indexing:array[0] - New functions for arrays:
join,indexOf,map,filter, andfold - Variable assignment:
x = 4 - Custom function definitions:
myfunction(x, y) = x * y - Evaluate multiple expressions by separating them with
; - New operators:
log2(base-2 logarithm),cbrt(cube root),expm1(e^x - 1),log1p(log(1 + x)),sign(essentiallyx == 0 ? 0 : x / abs x)
minandmaxfunctions accept either a parameter list or a single array argumentinoperator is enabled by default. It can be disabled by passing { operators:{ 'in': false } }to theParserconstructor.||(concatenation operator) now supports strings and arrays
- Removed the
if(condition, trueValue, falseValue)function. Use the ternary conditional operator instead:condition ? trueValue : falseValue, or you can add it back easily with a custom function.