if function
Description:
This process involves compiling an expression into an ‘if’ function, which is then returned for future use. It’s particularly beneficial when iterating over a collection and evaluating each item against a specific expression. Use the action module to call the function passing the object you want to evaluate in.
{
"type": "compile",
"action": "if_value",
"args": {
"exp": "value == 10",
"target": "$data.ifFn"
}
}
The function that is created will be a sanitized version of the expression assuming that it is working with a parameter called “context”. Thus the expression above will be sanitized to be "return context.value == 10"
A typical use case scenario is to apply conditional formatting such as style colors based on the expression passing or defining the color result in the expression using ternery values.
case function
Description:
This operates similarly to the ‘if’ function, but it incorporates a ‘case’ type syntax. This enables the use of multiple expressions, each yielding its own result. Additionally, it allows for the specification of a default value if none of the cases are satisfied.
{
"type": "compile",
"action": "case_value",
"args": {
"exp": "value < 10: 'yes', value < 20: 'ok', default: 'no'",
"target": "result"
}
}