TomFrost / Jexl

Javascript Expression Language: Powerful context-based expression parser and evaluator
MIT License
573 stars 94 forks source link

Support for Function Calls #25

Closed keyofdb closed 4 years ago

keyofdb commented 7 years ago

Does this library support function calls?

For example, given the following context { number1: 3, number2: 5, number3: 4 }

Can i use something like the following? min(number1, number2, number3)

johannesschobel commented 6 years ago

that would be so cool..

@TomFrost : maybe this feature can be added to v2.0? That would greatly enhance this awesome library!

TomFrost commented 4 years ago

It's been a long time coming, but functions support is working in the functions branch. No docs there yet, but it works exactly as you might expect:

jexl.addFunction('hello', (arg) => `Hello, ${arg}!`)
jexl.evalSync('hello("world")') // "Hello, world!"

Getting this documented and teed up for the next release!

austinkelleher commented 4 years ago

This is going to be fantastic! Thanks for your work @TomFrost!

shrugal commented 4 years ago

Adding functions to the context would be nice, e.g.:

jexl.eval("a.b(5).c", { a: { b: v => ({ c: v }) } })
austinkelleher commented 4 years ago

Any update on this @TomFrost? Is it safe to use the functions branch?

TomFrost commented 4 years ago

Released in 2.3.0!