Skip to content

Latest commit

History

48 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

bool-expr-generator

A simple generator of boolean expressions.

Installation

NPM

npm install --save bool-expr-generator

Usage

importBoolExprfrom'bool-expr-generator';constboolGenerator=newBoolExpr();constexpr=boolGenerator.generate();// 'true && false'// You may pass an option object to the constructorconstboolGenerator=newBoolExpr({complexity: 3,operators: ["||","&&","^"],operatorsDisplayed: {"^": "XOR","&&": "AND","||": "OR"},logicalValues: [true,false,0,1],invertedValue: true,});constexpr=boolGenerator.generate();// 'false XOR 1 OR true'// If cou customised the operatorsDisplayed option you can use the convert method to convert the expression into an evaluable oneconsole.log(boolGenerator.convert(expr));// 'false ^ 1 || true'// Update options:boolGenerator.options({complexity: 4});console.log(boolGenerator.generate());// true XOR 1 AND !0 OR !0// You can also use a nested expression with or without its own optionsconstboolGenerator=newBoolExpr({logicalValues: [true,false,BoolExpr.nestedExpr({complexity: 2,logicalValues: [0,1]})],// Note that it is advised to specify the logicalValues});constexpr=boolGenerator.generate();// 'false && (0 || 1)'

Option object

KeyTypeDefaultExampleDescription
complexityinteger | Array<integer>23 | [2, 4]Length of the expression, if an array is supplied the complexity will be a random value of it
operatorsArray<string>['||', '&&']['||', '&&', '^']The logical operators to be used
operatorsDisplayedObject{}{'^': 'XOR'}How the operators will be displayed in the expresssion
logicalValuesArray[true, false][0, 1, true, false]The logical values that can be included into the expression
invertedValueboolean | floatfalsetrue | .3Whether to add the inverted logical values or probability to have an inverted value for each logical values

About

A simple generator of boolean expressions

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages