evalis
v0.2.1
Published
A polyglot, secure, user-friendly expression evaluator
Maintainers
Readme
Evalis
A secure, user-friendly expression evaluator for TypeScript and JavaScript.
Early Release: This is an early release with core functionality. More features are in active development. Check the main project for roadmap and updates.
Installation
npm install evalisQuick Start
import { evaluateExpression } from 'evalis';
const context = { a: { b: 5 } };
const value = evaluateExpression('a.b + 2', context);
console.log(value); // 7Features
- Safe evaluation - No
eval(). No access to global namespace. - Simple syntax - Familiar expressions with property access, operators, and comprehensions.
- Type-safe - Full TypeScript support with type definitions included.
Supported Operations
- Arithmetic:
+,-,*,/ - Comparison:
==,!=,<,<=,>,>= - Logical:
and,or,not - Property access:
obj.property,obj['key'] - Array access:
arr[0] - List comprehensions:
[x * 2 for x in numbers] - Membership:
x in collection - String literals: Both
'single'and"double"quotes supported
Note on + operator:
- Numbers:
5 + 3→8 - Strings:
"hello" + "world"→"helloworld"(coerces primitives to string) - Arrays:
[1, 2] + [3, 4]→[1, 2, 3, 4] - Mixed types (array + string) will throw
EvalisError
More Information
This is the TypeScript/JavaScript implementation of Evalis. For more details about the project:
License
MIT
