3 ms·
Filtrex: A simple JavaScript filter expression compiler
- couchand 12y agoThis is really slick. I wonder if it would be useful to build an object model for the filters rather than directly concatenating the code. That would allow for interesting inspection on the parsed expressions or transformation of them. For instance, combining two filters should be just as easy as combining two expressions. var expression = compileExpression('transactions <= 5 and abs(profit) > 20.5'); ...should also be possible to write as this, to help DRY everything... var fewTransactions = compileExpression('transactions <= 5'); var lotsOfProfit = compileExpression('abs(profit) > 20.5'); var expression = fewTransactions.and(lotsOfProfit); You might look into the Specification pattern [0] to handle the heavy lifting in a simple way. [0]: http://www.martinfowler.com/apsupp/spec.pdf http://www.martinfowler.com/apsupp/spec.pdf
- afternooner 12y agoI love this, but I think I'll wait until a few more people play around with hacking it.
- mappu 12y agoIncluding all of jison? I've implemented something similar several times in different ways now, and I strongly recommend looking into the Precedence Climbing algorithm - you can build something like this without the jison dependency in almost as few lines as `filtrex.js` already is.
- mappum 12y agoYour username...
- michaelsbradley 12y agoIt's less general purpose, but the polymer-expressions library is also worth a look: https://github.com/Polymer/polymer-expressions https://github.com/Polymer/polymer-expressions
- SchizoDuckie 12y agoIt looks brilliant, but the 128kb dependency kills it. You'd have to do a lot of these expressions to be able to validate the usage of yet another 128k lib imo.