Boolean evaluator
Package for transforming a string with logical operators into the result of an expression.
Installation
$ npm install @bxr1ng-os/boolean-evaluator
Usage
import Evaluate from "@bxr1ng-os/boolean-evaluator";
const string = "!(true || false) && true";
const result = Evaluate(string);
console.log(result); // false
You can also pass your variables to the function. Simply write your variables in a string, and pass in the second parameter an object with the values.
import Evaluate from "@bxr1ng-os/boolean-evaluator";
const newValues = { "some-true-value": true, "some-false-value": false};
const string = "some-true-value || some-false-value";
const result = Evaluate(string, newValues);
console.log(result); // true
Available operators and values
&&
, ||
, !
, (
, )
, true
, false
NOTE: Default values cannot be reassigned!