Skip to content

Artifact-io/boolean-expressions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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']);

About

Boolean expression parser and evaluator

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 99.1%
  • JavaScript 0.9%