Skip to content

Commit

Permalink
feat: add modulo (%) to extended logic operators
Browse files Browse the repository at this point in the history
  • Loading branch information
seleb committed Aug 30, 2020
1 parent 0709e07 commit 1fa9d61
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/logic-operators-extended.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Adds conditional logic operators:
- || (or)
- &&! (and not)
- ||! (or not)
- % (modulo)
Examples: candlecount > 5 && haslighter == 1
candlecount > 5 && papercount > 1 && isIndoors
Expand Down Expand Up @@ -72,16 +73,25 @@ function orNotExp(environment, left, right, onReturn) {
});
}

function modExp(environment, left, right, onReturn) {
right.Eval(environment, function (rVal) {
left.Eval(environment, function (lVal) {
onReturn(lVal % rVal);
});
});
}

inject(/(operatorMap\.set\("-", subExp\);)/, `
$1
operatorMap.set("&&", ${andExp.toString()});
operatorMap.set("||", ${orExp.toString()});
operatorMap.set("&&!", ${andNotExp.toString()});
operatorMap.set("||!", ${orNotExp.toString()});
operatorMap.set("!==", ${notEqExp.toString()});
operatorMap.set("%", ${modExp.toString()});
`);
inject(
/(var operatorSymbols = \[.+\];)/,
'$1operatorSymbols.unshift("!==", "&&", "||", "&&!", "||!");',
'$1operatorSymbols.unshift("!==", "&&", "||", "&&!", "||!", "%");',
);
// End of logic operators mod

0 comments on commit 1fa9d61

Please sign in to comment.