Conditions
Conditions are functions that evaluate a message. Each condition has two components: an operator, which determines how data is evaluated, and inspectors, which evaluate data.
Operators
Operators determine how data is evaluated when applying inspectors. These include:
- any: Data passes inspection if any inspector returns true.
- all: Data passes inspection if every inspector returns true.
- none: Data passes inspection if no inspector returns true.
Inspectors
Inspectors include:
- Format: Any inspector that evaluates the format, structure, or shape of data.
- Meta: Any inspector that applies other conditions and inspectors.
- Network: Any inspector that evaluates network data.
- Number: Any inspector that evaluates number data.
- String: Any inspector that evaluates string data.
- Utility: Any inspector that provides evaluation functions for testing or debugging.
Examples
String Pattern Match and String Length
This returns true if the value of a
begins with "FOO", "FoO", "foo" (etc.) and has a length greater than 3 characters.
sub.cnd.all([
sub.cnd.string.match({object: {source_key: 'a'}, pattern: '^[Ff][Oo][Oo]'}),
sub.cnd.number.length.greater_than({object: {source_key: 'a'}, value: 3}),
])
Missing Field
This returns true if the value of b
has a length of zero (e.g., missing field).
sub.cnd.any([
sub.cnd.number.length.equal_to({object: {source_key: 'b'}, value: 0}),
])
Evaluate Multiple Fields
This returns true if the value of c
is equal to "bar" and the value of d
starts with "baz".
sub.cnd.all([
sub.cnd.string.equal_to({object: {source_key: 'c'}, value: 'bar'}),
sub.cnd.string.starts_with({object: {source_key: 'd'}, value: 'baz'}),
])
Updated 10 months ago