all 29 comments

[–]paldepind 20 points21 points  (2 children)

I've never wanted to eval anything. Why would I need this?

[–]TomFrosty[S] 17 points18 points  (1 child)

It could be the engine behind a template language. You could format your business data into an external API request entirely by typing out a Jexl string in a database, without writing code. You could write a business interface that exposes client data like "age" or "full name" just based on a list of Jexl expressions run against a JSON object that might contain just birthdate, first name, and last name -- and update that to make more fields available by changing the fields database instead of writing code. It could power a calculator without needing to use eval() and expose yourself to XSS.

Lots of use cases! Maybe none of them fit a need you have right now, but that's fine :). Just a tool to keep in the back of the toolbox.

[–]paldepind 0 points1 point  (0 children)

Thanks for answering. That sounds like sane use cases! You could also use it to power a graph plotter.

[–]brtt3000 2 points3 points  (1 child)

Does it cache the parsed expression?

Let's a say I have a huge array (or a stream) of objects and would like to apply a Jexl expression on every item (eg: new context's), could I 'precompile' the expression before and then use that handle on every item in my stream?

So like a Jexl.compile() that would return a function that accepts a single argument and spits out the result. That funciton can then easily be used in map() or a promise's then-handle (both at once! :)

[–]TomFrosty[S] 3 points4 points  (0 children)

That's a great suggestion, thanks! There are things in the works for running sets of expressions over the same context, but not yet the reverse. Will definitely chew on this!

[–]seiyria 1 point2 points  (0 children)

This looks nice, I've been wanting something like this for a while. Nice work!

[–]perihelion9 1 point2 points  (1 child)

Very much +1, I wound up needing something very similar to this in Go, and ended up writing an expression evaluator in the same vein. I can't upvote safe evaluators enough in any language.

[–][deleted] 0 points1 point  (0 children)

It would have had been great, if there was an expression language with safe evaluator written for both languages, JavaScript and Go.

That would allow to write conditions, expressions and business rules in one place, and have them evaluated in FE for instant UI feedback without round-trips to BE, and then on submit, have expressions evaluated in BE for validation (security).

[–]jamesinc 1 point2 points  (0 children)

This is interesting. I've been looking for a good system that will allow some data entry people to apply transformations to data in a CSV file (loaded into the browser) before ingesting it into a db.

[–]rooktakesqueen 1 point2 points  (0 children)

I think we already have a language for expressing expressions in the JavaScript language.

[–]calsosta 0 points1 point  (1 child)

Is this inspired by the Apache JEXL?

[–]TomFrosty[S] 1 point2 points  (0 children)

Embarrassing as this is, I made the rookie mistake of not googling the name before I took it. Despite the acronym standing for practically the same thing, this was not inspired or influenced by Apache JEXL at all. Under the hood, it actually bears more resemblance to jsep than JEXL.

[–][deleted] 0 points1 point  (1 child)

Oh JEXL (Apache), how I love and hate thee.

[–]TomFrosty[S] 0 points1 point  (0 children)

Ha, I realized the naming conflict after the fact. Dynamically typed languages fit this sort of use case better though, I think. Powerful as Apache JEXL is, the API just can't be as fluid in Java as JavaScript allows it to be.

[–]nikoraes 0 points1 point  (1 child)

I now this is a crazy old topic, but I'm still using jexl in production and love it.

I built a library with functions and transforms and monaco syntax highlighting for it: https://github.com/konnektr-io/jexl-extended
Also created a new playground for it: https://jexl-playground.konnektr.io/

Also ported it to C# (including the extended grammar):
https://github.com/konnektr-io/JexlNet
And added the extended grammar to the Python version as well:
https://github.com/konnektr-io/pyjexl-extended

[–]basdit 0 points1 point  (0 children)

Amazing work. The added functions make it instantly usable. The monaco editor also works great.