Let in/nin fall through to string + docs update

dadfc4db988018d256e3d92ed9e1cfb999ad9f6a

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +52 -40Ignore whitespace
public/scripts/variables.js+52 -40
@@ -529,7 +529,7 @@ export function evalBoolean(rule, a, b) {
529529 if (isFalseBoolean(String(a))) return !resultOnTruthy;
530530 return !!a ? resultOnTruthy : !resultOnTruthy;
531531 default:
532532 throw new Error(`Unknown boolean comparison rule for truthy check. If right-hand sideoperand is not provided, the rule must not provided or be "'not"'. Provided: ${rule}`);
533533 }
534534 }
535535
@@ -554,6 +554,11 @@ export function evalBoolean(rule, a, b) {
554554 return aNumber === bNumber;
555555 case 'neq':
556556 return aNumber !== bNumber;
557+ case 'in':
558+ case 'nin':
559+ // Fall through to string comparison. Otherwise you could not check if 12345 contains 45 for example.
560+ console.debug(`Boolean comparison rule '${rule}' is not supported for type number. Falling back to string comparison.`);
561+ break;
557562 default:
558563 throw new Error(`Unknown boolean comparison rule for type number. Accepted: gt, gte, lt, lte, eq, neq. Provided: ${rule}`);
559564 }
@@ -1265,15 +1270,15 @@ export function registerVariableCommands() {
12651270 typeList: [ARGUMENT_TYPE.STRING],
12661271 defaultValue: 'eq',
12671272 enumList: [
12681273 new SlashCommandEnumValue('gteq', 'a >== b (strings & numbers)'),
12691274 new SlashCommandEnumValue('gteneq', 'a >!== b (strings & numbers)'),
12701275 new SlashCommandEnumValue('ltin', 'a <includes b (strings & numbers as strings)'),
12711276 new SlashCommandEnumValue('ltenin', 'a <=not includes b (strings & numbers as strings)'),
12721277 new SlashCommandEnumValue('eqgt', 'a ==> b (numbers)'),
12731278 new SlashCommandEnumValue('neqgte', 'a !=>= b (numbers)'),
12741279 new SlashCommandEnumValue('notlt', '!a < b (numbers)'),
12751280 new SlashCommandEnumValue('inlte', 'a includes<= b (numbers)'),
12761281 new SlashCommandEnumValue('ninnot', '!a not includes b(truthy)'),
12771282 ],
12781283 forceEnum: true,
12791284 }),
@@ -1299,22 +1304,25 @@ export function registerVariableCommands() {
12991304 Numeric values and string literals for left and right operands supported.
13001305 </div>
13011306 <div>
13021307 If the rule is not provided, it defaults to <code>eq</code>.<br />
1308+ </div>
1309+ <div>
13031310 If no right operand is provided, it defaults to checking the <code>left</code> value to be truthy.
13041311 A non-empty string or non-zero number is considered truthy, as is the value <code>true</code> or <code>on</code>.<br />
1312+ Only acceptable rules for no provided right operand are <code>not</code>, and no provided rule - which default to returning whether it is not or is truthy.
13051313 </div>
13061314 <div>
13071315 <strong>Available rules:</strong>
13081316 <ul>
13091317 <li>gt<code>eq</code> => a >== b <small>(strings & numbers)</small></li>
13101318 <li>gte<code>neq</code> => a >!== b <small>(strings & numbers)</small></li>
13111319 <li>lt<code>in</code> => a <includes b <small>(strings & numbers as strings)</small></li>
1312- <li>lte => a <= b</li>
1320+ <li><code>nin</code> => a not includes b <small>(strings & numbers as strings)</small></li>
13131321 <li>eq<code>gt</code> => a ==> b <small>(numbers)</small></li>
13141322 <li>neq<code>gte</code> => a !>= b <small>(numbers)</small></li>
13151323 <li>not<code>lt</code> => !a < b <small>(numbers)</small></li>
13161324 <li>in (strings)<code>lte</code> => a includes<= b <small>(numbers)</small></li>
1317- <li>nin (strings) => a not includes b</li>
1325+ <li><code>not</code> => !a <small>(truthy)</small></li>
13181326 </ul>
13191327 </div>
13201328 <div>
@@ -1328,9 +1336,13 @@ export function registerVariableCommands() {
13281336 <pre><code class="language-stscript">/if left={{lastMessage}} rule=in right=surprise {: /echo SURPISE! :}</code></pre>
13291337 executes a subcommand defined as a closure if the given value contains a specified word.
13301338 <li>
13311339 <pre><code class="language-stscript">/if left=myContent {: /echo "My content had some content." :}</code></pre>
13321340 executes the defined subcommand, if the provided value of left is truthy (contains some kind of contant that is not empty or false)
13331341 </li>
1342+ <li>
1343+ <pre><code class="language-stscript">/if left=tree right={{getvar::object}} {: /echo The object is a tree! :}</code></pre>
1344+ executes the defined subcommand, if the left and right values are equals.
1345+ </li>
13341346 </ul>
13351347 </div>
13361348 `,
@@ -1359,15 +1371,15 @@ export function registerVariableCommands() {
13591371 typeList: [ARGUMENT_TYPE.STRING],
13601372 defaultValue: 'eq',
13611373 enumList: [
13621374 new SlashCommandEnumValue('gteq', 'a >== b (strings & numbers)'),
13631375 new SlashCommandEnumValue('gteneq', 'a >!== b (strings & numbers)'),
13641376 new SlashCommandEnumValue('ltin', 'a <includes b (strings & numbers as strings)'),
13651377 new SlashCommandEnumValue('ltenin', 'a <=not includes b (strings & numbers as strings)'),
13661378 new SlashCommandEnumValue('eqgt', 'a ==> b (numbers)'),
13671379 new SlashCommandEnumValue('neqgte', 'a !=>= b (numbers)'),
13681380 new SlashCommandEnumValue('notlt', '!a < b (numbers)'),
13691381 new SlashCommandEnumValue('inlte', 'a includes<= b (numbers)'),
13701382 new SlashCommandEnumValue('ninnot', '!a not includes b(truthy)'),
13711383 ],
13721384 forceEnum: true,
13731385 }),
@@ -1396,15 +1408,15 @@ export function registerVariableCommands() {
13961408 <div>
13971409 <strong>Available rules:</strong>
13981410 <ul>
13991411 <li>gt<code>eq</code> => a >== b <small>(strings & numbers)</small></li>
14001412 <li>gte<code>neq</code> => a >!== b <small>(strings & numbers)</small></li>
14011413 <li>lt<code>in</code> => a <includes b <small>(strings & numbers as strings)</small></li>
1402- <li>lte => a <= b</li>
1414+ <li><code>nin</code> => a not includes b <small>(strings & numbers as strings)</small></li>
14031415 <li>eq<code>gt</code> => a ==> b <small>(numbers)</small></li>
14041416 <li>neq<code>gte</code> => a !>= b <small>(numbers)</small></li>
14051417 <li>not<code>lt</code> => !a < b <small>(numbers)</small></li>
14061418 <li>in (strings)<code>lte</code> => a includes<= b <small>(numbers)</small></li>
1407- <li>nin (strings) => a not includes b</li>
1419+ <li><code>not</code> => !a <small>(truthy)</small></li>
14081420 </ul>
14091421 </div>
14101422 <div>