Overview
Logical operators let you combine multiple conditions together. Think of them like building blocks for complex rules.and
All conditions must be true
or
At least one condition must be true
not
Reverses a condition
Architecture
Logical operators are implemented in theLogicalOperators class:
Source Files:
- Logical operators:
src/operators/logical.js - Base operator:
src/operators/base/BaseOperator.js - Unit tests:
tests/unit/operators/logical.test.js
Key Features
- Short-circuit evaluation - Stops checking as soon as result is known
- Unlimited nesting - Combine operators inside each other
- Works with any operator - Combine comparison, string, array operators, etc.
- Clear error messages - Helpful feedback when something goes wrong
and - All Must Be True
All conditions must pass for the rule to pass. Like saying “I need this AND that AND those.”
Syntax
Parameters
array
required
Array of rule conditions (minimum 1 condition)
Returns
boolean - true only if all conditions are true
How It Works
Examples
- Basic AND
- Access Control
- Nested AND
- With Rule Helpers
Common Use Cases
User Permissions
User Permissions
Form Validation
Form Validation
Price Range
Price Range
Short-circuit: AND stops checking as soon as it finds a false condition, making it faster.
or - At Least One Must Be True
At least one condition must pass. Like saying “I need this OR that OR those.”
Syntax
Parameters
array
required
Array of rule conditions (minimum 1 condition)
Returns
boolean - true if any condition is true
How It Works
Examples
- Basic OR
- Multiple Payment Methods
- Nested OR
- With Rule Helpers
Common Use Cases
Role-Based Access
Role-Based Access
Discount Eligibility
Discount Eligibility
Search Filters
Search Filters
Short-circuit: OR stops checking as soon as it finds a true condition, making it faster.
not - Reverse a Condition
Flips a condition - true becomes false, false becomes true. Like saying “NOT this.”
Syntax
Parameters
object
required
Single rule condition (exactly 1, no more, no less)
Returns
boolean - true if condition is false, false if condition is true
How It Works
Examples
- Basic NOT
- Exclude Conditions
- Combined with AND/OR
- With Rule Helpers
Common Use Cases
Exclude Banned Users
Exclude Banned Users
Age Restrictions
Age Restrictions
Exclude Categories
Exclude Categories
Combining Operators
Mix AND, OR, and NOT to create complex logic:Complex Examples
- Shipping Eligibility
- Content Moderation
Error Handling
Common Errors
Empty AND/OR Array
Empty AND/OR Array
NOT with Wrong Number of Arguments
NOT with Wrong Number of Arguments
Invalid Condition
Invalid Condition
Tips for Debugging
Quick Reference
Operator Comparison
Common Patterns
Related Operators
Equality Operators
eq, neq
Numeric Operators
GT, GTE, LT, LTE
Array Operators
in, notIn
String Operators
contains, startsWith, endsWith
Special Operators
isNull, isNotNull, between
All Operators
Complete reference
