Overview
Equality operators compare values for equality or inequality. Rule Engine JS provides two equality comparison operators:eq
Tests if two values are equal
neq
Tests if two values are not equal
Architecture
Equality operators are implemented in theComparisonOperators class which extends BaseOperator:
Source Files:
- Equality operators:
src/operators/comparison.js - Base operator:
src/operators/base/BaseOperator.js - Type utilities:
src/utils/TypeUtils.js - Unit tests:
tests/unit/operators/comparison.test.js
Key Features
- Dynamic field comparison - Compare two fields or a field to a literal value
- Strict/loose modes - Control type coercion behavior (
==vs===) - Type-safe equality - Handles primitives, objects, arrays, null, undefined
- Comprehensive validation - Validates argument count and types
eq - Equals
Tests if two values are equal.
Syntax
Parameters
string | any
required
Left operand - field path or literal value
string | any
required
Right operand - field path or literal value
object
Configuration options
Returns
boolean - true if values are equal, false otherwise
Examples
- Basic Equality
- Dynamic Field Comparison
- Strict vs Loose Mode
- With Rule Helpers
Common Use Cases
Form Field Validation
Form Field Validation
Role-Based Access Control
Role-Based Access Control
Configuration Validation
Configuration Validation
Null/Undefined Handling
Null/Undefined Handling
Type Coercion: By default,
eq uses loose equality (==). Use { strict: true } or create a strict engine for type-safe comparisons.neq - Not Equal
Tests if two values are not equal (inverse of eq).
Syntax
Parameters
string | any
required
Left operand - field path or literal value
string | any
required
Right operand - field path or literal value
object
Configuration options
Returns
boolean - true if values are not equal, false otherwise
Examples
- Status Checks
- Password Change Validation
- Reserved Name Check
- Change Detection
Common Use Cases
Access Control
Access Control
Duplicate Prevention
Duplicate Prevention
State Transition Guards
State Transition Guards
Error Handling
Common Errors
Invalid Argument Count
Invalid Argument Count
Non-Array Arguments
Non-Array Arguments
Undefined Field Access
Undefined Field Access
Error Recovery
Type Coercion
Equality operators support both strict and loose comparison modes:Setting Strict Mode
Related Operators
Numeric Operators
GT, GTE, LT, LTE
Special Operators
isNull, isNotNull, between
Array Operators
in, notIn
Logical Operators
and, or, not
State Operators
changed, changedTo, changedFrom
All Operators
Complete operator reference
