TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Filtrex: A simple JavaScript filter expression compiler

64 点作者 joewalnes大约 11 年前

5 条评论

couchand大约 11 年前
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.<p><pre><code> var expression = compileExpression(&#x27;transactions &lt;= 5 and abs(profit) &gt; 20.5&#x27;); </code></pre> ...should also be possible to write as this, to help DRY everything...<p><pre><code> var fewTransactions = compileExpression(&#x27;transactions &lt;= 5&#x27;); var lotsOfProfit = compileExpression(&#x27;abs(profit) &gt; 20.5&#x27;); var expression = fewTransactions.and(lotsOfProfit); </code></pre> You might look into the Specification pattern [0] to handle the heavy lifting in a simple way.<p>[0]: <a href="http://www.martinfowler.com/apsupp/spec.pdf" rel="nofollow">http:&#x2F;&#x2F;www.martinfowler.com&#x2F;apsupp&#x2F;spec.pdf</a>
michaelsbradley大约 11 年前
It&#x27;s less general purpose, but the polymer-expressions library is also worth a look:<p><a href="https://github.com/Polymer/polymer-expressions" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Polymer&#x2F;polymer-expressions</a>
mappu大约 11 年前
Including all of jison?<p>I&#x27;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.
评论 #7748122 未加载
SchizoDuckie大约 11 年前
It looks brilliant, but the 128kb dependency kills it. You&#x27;d have to do <i>a lot</i> of these expressions to be able to validate the usage of yet another 128k lib imo.
afternooner大约 11 年前
I love this, but I think I&#x27;ll wait until a few more people play around with hacking it.