Skip to content

Latest commit

 

History

History
31 lines (22 loc) · 2.03 KB

File metadata and controls

31 lines (22 loc) · 2.03 KB

TypeScript Port Enhancements

Note: This document has been reorganized. See Advanced Features for the main documentation.

This is a modern TypeScript port of the expr-eval library, completely rewritten with contemporary build tools and development practices. Originally based on expr-eval 2.0.2, this version has been restructured with a modular architecture, TypeScript support, and comprehensive testing using Vitest. The library maintains backward compatibility while providing enhanced features and improved maintainability.

Summary of Enhancements

This TypeScript port adds the following features over the original library:

Expression Syntax Enhancements

  • undefined keyword - Use undefined in expressions and handle undefined values gracefully
  • Coalesce operator (??) - Null/undefined fallback: x ?? defaultValue
  • not in operator - Check if value is not in array: "x" not in arr
  • Optional chaining - Property access returns undefined instead of throwing errors
  • String concatenation with + - Concatenate strings using the + operator
  • SQL-style CASE blocks - Multi-way conditionals with case/when/then/else/end
  • Object construction - Create objects with {key: value} syntax
  • json() function - Convert values to JSON strings

Developer Integration Features

  • Promise support - Custom functions can return promises (async evaluation)
  • Custom variable resolution - parser.resolve callback for dynamic variable lookup, plus a per-call resolver argument on Expression.evaluate() / Parser.evaluate() so a single parsed expression can be evaluated against different data sources without mutating parser state
  • as operator - Type conversion with customizable implementation

For detailed documentation, see: