Skip to main content

What are Operators?

Operators are the building blocks of rules in Rule Engine JS. Each operator implements specific logic for comparing, transforming, or validating data.
Rule Engine JS includes 20+ built-in operators organized into 7 categories, plus support for custom operators.

Operator Categories

Quick Reference

OperatorSyntaxDescription
eq{ eq: ['age', 18] }Equals comparison
gt{ gt: ['score', 90] }Greater than
and{ and: [rule1, rule2] }Logical AND
or{ or: [rule1, rule2] }Logical OR
contains{ contains: ['name', 'John'] }String contains
in{ in: ['admin', 'roles'] }Array membership
between{ between: ['age', [18, 65]] }Range check
changed{ changed: ['status'] }Value changed (stateful)
See the Complete Operators Reference for detailed documentation on all operators.

Using Operators

  • Direct JSON
  • Rule Helpers
const rule = {
  and: [
    { gte: ['age', 18] },
    { eq: ['role', 'admin'] }
  ]
};

const result = engine.evaluateExpr(rule, userData);

Custom Operators

Create custom operators for business-specific logic:
// Register a custom operator
engine.registerOperator('isWorkingAge', (args, context) => {
  const [agePath, country = 'US'] = args;
  const age = context[agePath];

  const minAge = {
    'US': 16,
    'UK': 16,
    'EU': 18
  };

  return age >= (minAge[country] || 18);
});

// Use the custom operator
const rule = { isWorkingAge: ['applicant.age', 'US'] };
const result = engine.evaluateExpr(rule, { applicant: { age: 17 } });
Custom operators integrate seamlessly with built-in operators and rule helpers.

Next Steps