@bxr1ng-os/boolean-evaluator
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Boolean evaluator

Known Vulnerabilities NPM Downloads NPM License npm Codecov

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!

License

ISC

Author

Danya Voshchuk (vochshukdaniil@gmail.com)

Package Sidebar

Install

npm i @bxr1ng-os/boolean-evaluator

Weekly Downloads

0

Version

0.1.1

License

ISC

Unpacked Size

29.3 kB

Total Files

57

Last publish

Collaborators

  • bxr1ng