boolean-expressions
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

boolean-expressions

Boolean expression parser and evaluator. Makes use of the Ohm grammar package with grammar rules found here.

NPM version NPM license

Installation

The package is hosted on npm here. Simply install with npm install boolean-expressions.

Usage

This package provides a BooleanExpressions class which parses an expression once and allows an unlimited number of evaluations on that expression.

To parse an expression, instantiate a new instance of the BooleanExpressions class with the given expression. For example,

const b = new BooleanExpressions('p and q or t');

To get the unique variables from that query, call:

// Would return ['p', 'q', 't']
const variables = b.getVariableNames();

To evaluate the expression with the given variables set to true, use:

// Evaluates the expression with p=true, q=true, and t=false
const result = b.evaluate(['p', 'q']);

Package Sidebar

Install

npm i boolean-expressions

Weekly Downloads

3

Version

1.1.1

License

ISC

Unpacked Size

70.4 kB

Total Files

46

Last publish

Collaborators

  • dpgil