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.
- If the rule is not provided, it defaults to eq.
+ If the rule is not provided, it defaults to eq. +
+
If no right operand is provided, it defaults to checking the 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.
+ Only acceptable rules for no provided right operand are not, and no provided rule - which default to returning whether it is not or is truthy.
Available rules:
@@ -1328,9 +1336,13 @@ export function registerVariableCommands() {
/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. +
  • `, @@ -1359,15 +1371,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, }), @@ -1396,15 +1408,15 @@ export function registerVariableCommands() {
    Available rules: