Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/marcbachmann/boolean-expression

⋀⋁ Create a boolean expression that's safe (you can still harm your app if you don't validate) to eval.
https://github.com/marcbachmann/boolean-expression

boolean-expression code-generation parser

Last synced: 27 days ago
JSON representation

⋀⋁ Create a boolean expression that's safe (you can still harm your app if you don't validate) to eval.

Awesome Lists containing this project

README

        

# boolean-expression

Create a boolean expression that's safe to eval

## expression = booleanExpression(exp)

Returns a `BooleanExpression` instance with `toString` and `toTokens` methods.

### expression.toString(map)

```
var expression = booleanExpression('foo AND bar')
var str = expression.toString(function (token) {
return 'val.indexOf(' + JSON.stringify(token) + ')'
})

// str == 'val.indexOf("foo") && val.indexOf("bar")'

```

### expression.toTokens()

```
var expression = booleanExpression('foo && bar && !qux')
expression.toTokens()
// returns ['foo', 'bar', 'qux']
```