diff --git a/public/scripts/variables.js b/public/scripts/variables.js index abe69799e..9edc0940b 100644 --- a/public/scripts/variables.js +++ b/public/scripts/variables.js @@ -529,7 +529,7 @@ export function evalBoolean(rule, a, b) { if (isFalseBoolean(String(a))) return !resultOnTruthy; return !!a ? resultOnTruthy : !resultOnTruthy; default: - throw new Error(`Unknown boolean comparison rule for truthy check. If right-hand side is not provided, the rule must not provided or be "not". Provided: ${rule}`); + throw new Error(`Unknown boolean comparison rule for truthy check. If right operand is not provided, the rule must not provided or be 'not'. Provided: ${rule}`); } } @@ -554,6 +554,11 @@ export function evalBoolean(rule, a, b) { return aNumber === bNumber; case 'neq': return aNumber !== bNumber; + case 'in': + case 'nin': + // Fall through to string comparison. Otherwise you could not check if 12345 contains 45 for example. + console.debug(`Boolean comparison rule '${rule}' is not supported for type number. Falling back to string comparison.`); + break; default: throw new Error(`Unknown boolean comparison rule for type number. Accepted: gt, gte, lt, lte, eq, neq. Provided: ${rule}`); } @@ -1265,15 +1270,15 @@ export function registerVariableCommands() { typeList: [ARGUMENT_TYPE.STRING], defaultValue: 'eq', enumList: [ - new SlashCommandEnumValue('gt', 'a > b'), - new SlashCommandEnumValue('gte', 'a >= b'), - new SlashCommandEnumValue('lt', 'a < b'), - new SlashCommandEnumValue('lte', 'a <= b'), - new SlashCommandEnumValue('eq', 'a == b'), - new SlashCommandEnumValue('neq', 'a !== b'), - new SlashCommandEnumValue('not', '!a'), - new SlashCommandEnumValue('in', 'a includes b'), - new SlashCommandEnumValue('nin', 'a not includes b'), + new SlashCommandEnumValue('eq', 'a == b (strings & numbers)'), + new SlashCommandEnumValue('neq', 'a !== b (strings & numbers)'), + new SlashCommandEnumValue('in', 'a includes b (strings & numbers as strings)'), + new SlashCommandEnumValue('nin', 'a not includes b (strings & numbers as strings)'), + new SlashCommandEnumValue('gt', 'a > b (numbers)'), + new SlashCommandEnumValue('gte', 'a >= b (numbers)'), + new SlashCommandEnumValue('lt', 'a < b (numbers)'), + new SlashCommandEnumValue('lte', 'a <= b (numbers)'), + new SlashCommandEnumValue('not', '!a (truthy)'), ], forceEnum: true, }), @@ -1299,22 +1304,25 @@ export function registerVariableCommands() { Numeric values and string literals for left and right operands supported.
eq
.eq
.
+ left
value to be truthy.
- A non-empty string or non-zero number is considered truthy, as is the value true
.
+ A non-empty string or non-zero number is considered truthy, as is the value true
or on
.not
, and no provided rule - which default to returning whether it is not or is truthy.
eq
=> a == b (strings & numbers)neq
=> a !== b (strings & numbers)in
=> a includes b (strings & numbers as strings)nin
=> a not includes b (strings & numbers as strings)gt
=> a > b (numbers)gte
=> a >= b (numbers)lt
=> a < b (numbers)lte
=> a <= b (numbers)not
=> !a (truthy)/if left={{lastMessage}} rule=in right=surprise {: /echo SURPISE! :}
executes a subcommand defined as a closure if the given value contains a specified word.
/if left=myContent {: /echo "My content had some content." :}
+ /if left=myContent {: /echo My content had some content. :}
executes the defined subcommand, if the provided value of left is truthy (contains some kind of contant that is not empty or false)
/if left=tree right={{getvar::object}} {: /echo The object is a tree! :}
+ executes the defined subcommand, if the left and right values are equals.
+ eq
=> a == b (strings & numbers)neq
=> a !== b (strings & numbers)in
=> a includes b (strings & numbers as strings)nin
=> a not includes b (strings & numbers as strings)gt
=> a > b (numbers)gte
=> a >= b (numbers)lt
=> a < b (numbers)lte
=> a <= b (numbers)not
=> !a (truthy)