https://github.com/kikobeats/voll
A boolean expressions evaluator.
https://github.com/kikobeats/voll
expr
Last synced: about 1 year ago
JSON representation
A boolean expressions evaluator.
- Host: GitHub
- URL: https://github.com/kikobeats/voll
- Owner: Kikobeats
- License: mit
- Created: 2016-07-17T14:37:30.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-11-15T09:11:21.000Z (over 2 years ago)
- Last Synced: 2025-05-05T23:09:10.268Z (about 1 year ago)
- Topics: expr
- Language: JavaScript
- Homepage: http://Kikobeats.github.io/voll/
- Size: 102 KB
- Stars: 18
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
Boolean expressions evaluator.
**voll** is based mayority [bool](https://www.npmjs.com/package/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
```bash
$ npm install voll --save
```
## Usage
```js
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](https://github.com/sindresorhus/mem#options).
## License
Icon made by [Darius Dan](http://www.flaticon.com/free-icon/browser_173659) from [flaticon](http://www.flaticon.com/).
MIT © [Kiko Beats](https://github.com/Kikobeats)