Skip to main content

Overview

Rule Engine JS provides a simple, powerful API for evaluating business rules. This section documents all public APIs.

Core APIs

RuleEngine

Core evaluation engine with caching and performance optimization

StatefulRuleEngine

Event-driven engine with state tracking and history

PathResolver

Safe path resolution with security features

Rule Helpers

Fluent API for building rules programmatically

Quick Start

Import Paths

ES Modules

CommonJS

TypeScript

API Categories

Engine Management

  • createRuleEngine(config?) - Create rule engine instance
  • engine.evaluateExpr(rule, context) - Evaluate rule
  • engine.registerOperator(name, fn) - Add custom operator
  • engine.getMetrics() - Get performance metrics

State Management

  • new StatefulRuleEngine(engine, options?) - Create stateful engine
  • statefulEngine.evaluate(id, rule, context) - Evaluate with state
  • statefulEngine.evaluateBatch(rules, context) - Batch evaluation
  • statefulEngine.on(event, handler) - Event listeners

Rule Building

  • createRuleHelpers() - Create helper factory
  • rules.eq(field, value) - Equality check
  • rules.and(...conditions) - Combine conditions
  • rules.validation.email(field) - Built-in validators

Utilities

  • pathResolver.resolve(context, path) - Resolve path
  • pathResolver.resolveValueOrLiteral(context, value) - Resolve or use literal

Type Definitions

All APIs have TypeScript definitions:

Error Handling

All APIs throw or return structured errors:

Next Steps

RuleEngine

Learn the core engine API

Rule Helpers

Build rules with fluent API

Operators

See all available operators

Examples

View practical examples