Skip to main content
Rule Engine JS Hero Light

Welcome to Rule Engine JS

Stop hardcoding business logic. Rule Engine JS lets you define complex conditional logic as data, making your applications more flexible, maintainable, and business-friendly.
if (user.age >= 18 && user.role === 'admin' && user.permissions.includes('write')) {
  return true;
}

Key Features

Zero Dependencies

Lightweight with no external dependencies for minimal bundle size

High Performance

Intelligent caching with LRU eviction for optimal speed

Security First

Built-in protection against prototype pollution and malicious access

Type Safe

Full TypeScript support with comprehensive type definitions

Stateful Engine

Track state changes with event-driven architecture

Extensible

Easy custom operator registration for business-specific logic

Dynamic Fields

Compare values across different data paths

Monitoring

Built-in performance metrics and cache statistics

Why Choose Rule Engine JS?

Define business rules as JSON data instead of hardcoding them. Update rules without deploying code changes.
Fluent helper API makes building complex rules intuitive and readable.
Battle-tested with 500+ unit tests and >90% code coverage. Zero dependencies means fewer security vulnerabilities.
Works with any JavaScript framework - React, Vue, Angular, Node.js, Express, and more.

Installation

npm install rule-engine-js

Quick Example

Here’s a simple example to get you started:
import { createRuleEngine, createRuleHelpers } from 'rule-engine-js';

// Create engine and helpers
const engine = createRuleEngine();
const rules = createRuleHelpers();

// Your data
const user = {
  name: 'John Doe',
  age: 28,
  role: 'admin',
  email: 'john@company.com',
  permissions: ['read', 'write', 'delete'],
};

// Simple rule
const isAdult = rules.gte('age', 18);
console.log(engine.evaluateExpr(isAdult, user).success); // true

// Complex rule
const canAccess = rules.and(
  rules.gte('age', 18),
  rules.eq('role', 'admin'),
  rules.validation.email('email'),
  rules.in('write', 'permissions')
);

console.log(engine.evaluateExpr(canAccess, user).success); // true

Core Principles

1

Rules are Data

Rules are simple JSON objects that describe conditions, making them easy to store, version, and manage.
2

Declarative Syntax

Express complex logic in a readable, maintainable format using helper functions or raw JSON.
3

Safe by Default

Security features protect against common vulnerabilities like prototype pollution and malicious data access.
4

Performance Optimized

Intelligent caching and optimized evaluation paths ensure fast rule execution even with complex logic.

What’s Next?

Community and Support