Available Operators
Rule Engine JS includes 20+ built-in operators organized into 7 categories:Comparison
6 operators
eq, neq, gt, gte, lt, lteLogical
3 operators
and, or, notString
4 operators
contains, startsWith, endsWith, regexArray
2 operators
in, notInNumeric
1 operator
betweenSpecial
2 operators
isNull, isNotNullState
6 operators
changed, changedBy, changedFrom, changedTo, increased, decreasedQuick Reference
Comparison Operators
Comparison Operators
| Operator | Description | Example |
|---|---|---|
eq | Equals | { eq: ['age', 18] } |
neq | Not equals | { neq: ['status', 'inactive'] } |
gt | Greater than | { gt: ['score', 90] } |
gte | Greater than or equal | { gte: ['age', 18] } |
lt | Less than | { lt: ['temperature', 100] } |
lte | Less than or equal | { lte: ['price', 50] } |
Logical Operators
Logical Operators
| Operator | Description | Example |
|---|---|---|
and | All conditions must be true | { and: [rule1, rule2] } |
or | At least one condition must be true | { or: [rule1, rule2] } |
not | Negates a condition | { not: [rule] } |
String Operators
String Operators
| Operator | Description | Example |
|---|---|---|
contains | String contains substring | { contains: ['name', 'John'] } |
startsWith | String starts with prefix | { startsWith: ['email', 'admin'] } |
endsWith | String ends with suffix | { endsWith: ['file', '.pdf'] } |
regex | Matches regular expression | { regex: ['email', '^[a-z]+@'] } |
Array Operators
Array Operators
| Operator | Description | Example |
|---|---|---|
in | Value exists in array | { in: ['admin', 'roles'] } |
notIn | Value does not exist in array | { notIn: ['banned', 'users'] } |
Numeric Operators
Numeric Operators
| Operator | Description | Example |
|---|---|---|
between | Value is within range (inclusive) | { between: ['age', [18, 65]] } |
Special Operators
Special Operators
| Operator | Description | Example |
|---|---|---|
isNull | Value is null or undefined | { isNull: ['optionalField'] } |
isNotNull | Value is not null/undefined | { isNotNull: ['requiredField'] } |
State Change Operators (Stateful Engine Only)
State Change Operators (Stateful Engine Only)
| Operator | Description | Example |
|---|---|---|
changed | Value changed from previous evaluation | { changed: ['status'] } |
changedBy | Numeric value changed by amount | { changedBy: ['price', 10] } |
changedFrom | Changed from specific value | { changedFrom: ['status', 'pending'] } |
changedTo | Changed to specific value | { changedTo: ['status', 'active'] } |
increased | Numeric value increased | { increased: ['temperature'] } |
decreased | Numeric value decreased | { decreased: ['stock'] } |
Operator Syntax
All operators follow a consistent syntax pattern:Single-Argument Operators
Two-Argument Operators
Multi-Argument Operators
Using Rule Helpers
The Rule Helpers API provides a more readable way to build rules:- Direct JSON
- Rule Helpers
Type Coercion
By default, operators perform type coercion for flexibility:Operator Composition
Operators can be nested and combined for complex logic:Custom Operators
Extend the engine with custom business logic:Performance Considerations
Operator Order
Place faster operators first in
and conditions to fail earlyAvoid Deep Nesting
Deeply nested rules are harder to cache and slower to evaluate
Cache-Friendly Paths
Use consistent path names to maximize cache hits
Batch Similar Rules
Group related rules for better cache utilization
Next Steps
Comparison
Detailed comparison operators
Logical
Detailed logical operators
String
Detailed string operators
Array
Detailed array operators
State
Detailed state operators
Custom Operators
Create custom operators
