Operators
All 10 targeting rule operators available in the Switchflag evaluation engine.
The evaluation engine supports 10 operators for targeting rules. Each operator compares a context attribute against a rule value.
String operators
These operators convert both the context value and rule value to strings before comparing.
| Operator | Description | Example |
|---|---|---|
equals | Exact string match | userId equals "user-123" |
notEquals | Not an exact match | email notEquals "admin@acme.com" |
contains | Substring match | email contains "@acme.com" |
startsWith | Starts with prefix | email startsWith "admin" |
endsWith | Ends with suffix | email endsWith ".edu" |
equals / notEquals
// Rule: email equals "jane@acme.com"
{ email: "jane@acme.com" } // ✓ matches
{ email: "bob@acme.com" } // ✗ no matchcontains
// Rule: email contains "@acme.com"
{ email: "jane@acme.com" } // ✓ matches
{ email: "admin@acme.com" } // ✓ matches
{ email: "jane@example.com" } // ✗ no matchstartsWith / endsWith
// Rule: country startsWith "U"
{ country: "US" } // ✓ matches
{ country: "UK" } // ✓ matches
{ country: "CA" } // ✗ no matchList operators
These check whether the context value is present in (or absent from) an array of allowed values.
| Operator | Description | Example |
|---|---|---|
in | Value is in the list | country in ["US", "CA", "GB"] |
notIn | Value is not in the list | country notIn ["CN", "RU"] |
// Rule: country in ["US", "CA"]
{ country: "US" } // ✓ matches
{ country: "CA" } // ✓ matches
{ country: "GB" } // ✗ no matchNumeric operators
These convert both values to numbers before comparing. Non-numeric values will produce NaN, which never matches.
| Operator | Description | Example |
|---|---|---|
greaterThan | Numeric greater than | age greaterThan 18 |
lessThan | Numeric less than | requestCount lessThan 1000 |
// Rule: age greaterThan 18
{ age: 25 } // ✓ matches
{ age: 18 } // ✗ no match (not greater than)
{ age: 12 } // ✗ no matchPercentage operator
The percent operator enables percentage-based rollouts. See Percentage Rollouts for details.
| Operator | Description | Example |
|---|---|---|
percent | Percentage rollout | percent at 50 (50% of users) |
The percent operator requires userId in the context. It's deterministic — the same user always gets the same result for the same rule.
Missing attributes
If the context attribute referenced by a rule is undefined, the rule does not match. This applies to all operators except percent (which uses userId directly).
// Rule: country equals "US"
{ email: "jane@acme.com" } // ✗ no match (country is undefined)