Flagship 为定向规则条件提供 13 种比较运算符。每种运算符都会将评估上下文中的属性与指定值进行比较。
| 运算符 | 描述 | 示例 | 规则值类型 |
|---|---|---|---|
equals |
如果属性与指定标量值匹配,则返回 true。 | country equals "US" |
标量 |
not_equals |
如果属性与指定标量值不同,则返回 true。 | plan not_equals "free" |
标量 |
greater_than |
如果属性值大于指定值,则返回 true。 | age greater_than 18 |
数字、ISO 8601 日期时间 |
less_than |
如果属性值小于指定值,则返回 true。 | loginCount less_than 5 |
数字、ISO 8601 日期时间 |
greater_than_or_equals |
如果属性值大于或等于指定值,则返回 true。 | score greater_than_or_equals 90 |
数字、ISO 8601 日期时间 |
less_than_or_equals |
如果属性值小于或等于指定值,则返回 true。 | createdAt less_than_or_equals <DATETIME> |
数字、ISO 8601 日期时间 |
contains |
如果属性值包含指定的子字符串,则返回 true。 | email contains "@cloudflare.com" |
字符串 |
starts_with |
如果属性值以指定前缀开头,则返回 true。 | path starts_with "/api/v2" |
字符串 |
ends_with |
如果属性值以指定后缀结尾,则返回 true。 | domain ends_with ".dev" |
字符串 |
in |
如果标量属性包含在指定数组中,则返回 true。 | country in ["US", "CA", "UK"] |
数组 |
not_in |
如果标量属性未包含在指定数组中,则返回 true。 | userId not_in ["blocked-1", "blocked-2"] |
数组 |
has |
如果数组属性包含指定标量值,则返回 true。 | tags has "beta" |
标量 |
not_has |
如果数组属性不包含指定标量值,则返回 true。 | roles not_has "contractor" |
标量 |
equals, not_equals
使用这些运算符进行精确的标量匹配。字符串比较区分大小写。
greater_than, less_than, greater_than_or_equals, less_than_or_equals
这些运算符适用于数值和 ISO 8601 日期时间字符串。日期时间值应使用 ISO 8601 格式。
contains, starts_with, ends_with
这些运算符针对属性值执行子字符串匹配。所有字符串比较均区分大小写。
in, not_in, has, not_has
对于 in 和 not_in,规则值必须是数组。Flagship 会检查标量属性是否属于该数组。
对于 has 和 not_has,上下文属性必须是数组。Flagship 会检查该数组是否包含规则的标量值。
缺失的属性永远不会匹配,包括使用否定运算符时。null 属性只匹配 not_equals 和 not_in 条件。
数组支持 has 和 not_has。对象和数组属性不会作为其他运算符的标量操作数。
以点分隔的属性最多可遍历五个对象片段。顶层字面键优先于嵌套遍历。