Open chetbox opened 2 years ago
Some context for this is I'm trying to write an expression that give me a random string from a static list.
["One","Two","Three"][(random() * 3) | floor]
Am I going about this the wrong way?
Oh wow -- I see why that's happening. Definitely a bug!
Until this is fixed, you could throw this into a transform function:
jexl.addTransform('random', (ary) => {
const idx = Math.floor(Math.random() * ary.length)
return ary[idx]
})
Now your expression becomes ['one', 'two', 'three']|random
Until this is fixed, you could throw this into a transform function:
jexl.addTransform('random', (ary) => { const idx = Math.floor(Math.random() * ary.length) return ary[idx] })
This will do for now. Thanks!
To avoid raising duplicate issues it looks as if what chetbox has raised means static JSON as parameters to functions isn't currently possible with jexl right now.
The following expression
"aFunction(aVariable, { \"aProperty\": 1 })"
raises the error
Error: Token "aProperty" (literal) unexpected in expression: aFunction(aVariable, { "aProperty"
By changing the expression to the following and parsing the string in aFunction as JSON does work
"aFunction(aVariable, \"{ \\\"aProperty\\\": 1 }\")"
I wondered if transforms might help but parsing bombs out just the same.
Hi! Thanks for this great library!
I just came across something I had assumed would work but it doesn't seem to.
(Playground link)
Gives this error:
Similarly,
(Playground link)
Gives this error:
It's possible to index into and array or an object if it's part of the Jexl context but seemingly not statically like this.