Open perotom opened 1 year ago
It's unfortunately not possible to combine filters with operations in that way. After a filter |
, the only valid syntax is name (args)
and then optionally more filters.
What a pity. Can you think of any other workaround? Or is it possible to use math functions like min max and then do some arithmetic? Thank you
@perotom sure. The trick is to use multiple filters chained together, eg.
{{it.num_array | min | subtract(5) | format}}
or {{it.fruits | join(" + ") | append("test")}}
@nebrelbug Sounds like a nice idea but let's just flip the subtraction in your example:
{{5 | subtract(it.num_array | min) | format}}
Sadly this simple example doesn't work. Overall it is an excellent library but this "simple" flaw really is a deal breaker. Any ideas for workarounds?
@perotom yeah, Squirrelly unfortunately only supports top-level filters. Your best bet would be to use JS expressions inside of your filter. As an example:
{{ 5 | subtract(it.num_array.min()) | format }}
@nebrelbug Thanks for the idea, sadly we have a lot of subtractions with different variables so this approach won't work out in the long run. Do you think it is easy to add support for braces? Or does it break everything? Would be glad to add the support.
It's unfortunately probably not feasible for this project :(.
Describe the bug I would like to use braces in my expressions to do some calculations. When using pipes this creates some issues.
To Reproduce Try to use braces mixed with pipes like:
One can reproduce it in the playground for the display array examples like:
https://squirrelly.js.org/playground/
Expected behavior Braces should work as "usual" which normally are used to change evaluation order.
Package & Environment Details