0.1.1 • Published 3 years ago
@bxr1ng-os/boolean-evaluator v0.1.1
Boolean evaluator
Package for transforming a string with logical operators into the result of an expression.
Installation
$ npm install @bxr1ng-os/boolean-evaluatorUsage
import Evaluate from "@bxr1ng-os/boolean-evaluator";
const string = "!(true || false) && true";
const result = Evaluate(string);
console.log(result); // falseYou 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); // trueAvailable operators and values
&&, ||, !, (, ), true, false
NOTE: Default values cannot be reassigned!