TomFrost / Jexl

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

Transform Confusion #136

Open mfreeman-xtivia opened 9 months ago

mfreeman-xtivia commented 9 months ago

So can JEXL be used as a tranform language or just an expression evaluator only?

For example, if I wanted to use JEXL against the following:

{ "name": { "first": "Sterling", "last": "Archer" }, "assoc": [ { "first": "Lana", "last": "Kane" }, { "first": "Cyril", "last": "Figgis" }, { "first": "Pam", "last": "Poovey" } ], "age": 36 }

and simply return the array contents of "assoc" but with last names upper-cased, is that possible with JEXL? (i.e i would like to output something like this:

[ { "first": "Lana", "last": "KANE" }, { "first": "Cyril", "last": "FIGGIS" }, { "first": "Pam", "last": "POOVEY" } ]

nikoraes commented 7 months ago

JexlPlayground)%2C%0A%7D)

You can add the following transform (for example) mapToUpper: (arr) => arr.map(o => ({first: o.first, last: o.last.toUpperCase()}))

And you can call it like this assoc|mapToUpper