Quickstart with Filtrex
masterFiltrex allows you to compile string expressions into high-performance JavaScript functions. You can use these functions to filter or evaluate data objects at runtime.
- Define an expression string (e.g., from a user input field).
- Compile the expression using
compileExpression(expression). - Execute the resulting function by passing a data object to it.
// Input from user (e.g. search filter)
var expression = 'transactions <= 5 and abs(profit) > 20.5';
// Compile expression to executable function
var myfilter = compileExpression(expression);
// Execute function
myfilter({transactions: 3, profit:-40.5}); // returns 1
myfilter({transactions: 3, profit:-14.5}); // returns 0