A boolean expressions evaluator.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
src
test
.bumpedrc Update release process Jul 17, 2016
.editorconfig
.gitattributes
.gitignore
.npmignore
.npmrc
.travis.yml Update .travis.yml Aug 28, 2018
CHANGELOG.md
LICENSE.md
README.md
compositor.json
index.js
logo.png
package.json

README.md

voll
Boolean expressions evaluator.

Last version Build Status Coverage Status Donate
Dependency status Dev Dependencies Status NPM Status

voll is based mayority bool but improved in some aspects:

  • Exact word matching.
  • Insensitive comparison support.
  • Detect words based on unicode ranges.
  • Caching level for speed up AST evaluation.
  • Detect quotes words using scape quotes (' or ") for exact matches.
  • Operators alias (example: red+yellow means the same than red OR yellow).

Install

$ npm install voll --save

Usage

var voll = require('voll')
var test = voll('(red OR blue) AND (orange OR yellow)')

test('red') //=> false
test('yellow') //=> false
test('red yellow') //=> true

You can build complex expressions as you need. Use parentheses to specify the preference:

((red OR blue) AND NOT (orange OR yellow)) OR orange

In other case the preference is left to right. Also it handles malformed expressions. For example:

((red OR blue) AND NOT (orange yellow)) OR orange

Produces the follow error:

SyntaxError: Parse error on line 1:
...ue) AND NOT (orange yellow)) OR orange
-----------------------^

Operators

Operator Alias
AND
OR +
NOT -

API

voll(expr, [options])

expr

Required
Type: string

Boolean expression to be evaluated.

options

Type: object

Provide specific parser options

insensitive

Type: boolean
Default: false

Enable/Disable insensitive comparison.

cache

Type: boolean
Default: true

Enable/Disable caching.

cacheOpts

Type: object

Provide specific cache options. See mem#options.

License

Icon made by Darius Dan from flaticon.

MIT © Kiko Beats