IfStatementParser
The if tag returns a message based on the passed expression to the parameter.
An expression is represented by two values compared with an operator.
The payload is a required message that must be split by pipe (|
).
If the expression evaluates true, then the message before the pipe (|
) is returned, else the message after is returned.
Usage
import { Interpreter, IfStatementParser } from 'tagscript';
const ts = new Interpreter(new IfStatementParser());
API
Check IfStatementParser for the API documentation.
For End Users
Syntax
{if(expression):message}
Examples
{if({args}==63):You guessed it! The number I was thinking of was 63!|Too {if({args}<63):low|high}, try again.}
# if args is 63
You guessed it! The number I was thinking of was 63!
# if args is 73
Too high, try again.
# if args is 14
Too low, try again.
Operators
Operator | Check | Example | Description |
---|---|---|---|
== | equality | a==a | value 1 is equal to value 2 |
!= | inequality | a!=b | value 1 is not equal to value 2 |
> | greater than | 5>3 | value 1 is greater than value 2 |
< | less than | 4<8 | value 1 is less than value 2 |
>= | greater than or equality | 10>=10 | value 1 is greater than or equal to value 2 |
<= | less than or equality | 5<=6 | value 1 is less than or equal to value 2 |
Last updated on December 11, 2022