dynamic-forms / Class

ExpressionParser

Secure expression parser that uses AST-based evaluation instead of eval() or new Function()

This parser provides:

  • Security: No arbitrary code execution, only whitelisted operations
  • Performance: AST caching for repeated expressions
  • Better errors: Clear error messages with position information
  • Type safety: Strongly typed AST and evaluation

Static Methods

static

clearCache()

Clear the AST cache

Presentation
static clearCache(): void;
Returns
void
static

evaluate()

Evaluate an expression with a given scope

Presentation
static evaluate(expression: string, scope: EvaluationScope): unknown;
Parameters
NameTypeDescription
expression
string
scope
EvaluationScope
Returns
unknown
static

getCacheStats()

Get cache statistics

Presentation
static getCacheStats(): { size: number; maxSize: number; };
Returns
{ size: number; maxSize: number; }
static

parse()

Parse an expression string into an AST Results are cached for performance using LRU eviction

Presentation
static parse(expression: string): ASTNode;
Parameters
NameTypeDescription
expression
string
Returns