Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Filtrex: A simple JavaScript filter expression compiler (github.com/joewalnes)
64 points by joewalnes on May 14, 2014 | hide | past | favorite | 6 comments


This 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


It's less general purpose, but the polymer-expressions library is also worth a look:

https://github.com/Polymer/polymer-expressions


Including 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.


Your username...


It 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.


I love this, but I think I'll wait until a few more people play around with hacking it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: