boolean-expression

Create a boolean expression that's safe to eval

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
boolean-expression
2.0.07 years ago7 years agoMinified + gzip package size for boolean-expression in KB

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