Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Braces not working with pipes #256

Open
perotom opened this issue Jul 5, 2023 · 7 comments
Open

Braces not working with pipes #256

perotom opened this issue Jul 5, 2023 · 7 comments

Comments

@perotom
Copy link

perotom commented Jul 5, 2023

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:

{{((it.num_array | min) - 5) | format}}

One can reproduce it in the playground for the display array examples like:

{{(it.fruits | join(" + ")) + "test"}}

https://squirrelly.js.org/playground/

Expected behavior
Braces should work as "usual" which normally are used to change evaluation order.

Package & Environment Details

  • Environment: Chrome Version 114.0.5735.198 (Official Build) (x86_64)
  • Version: 9.0.0
@nebrelbug
Copy link
Collaborator

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.

@perotom
Copy link
Author

perotom commented Jul 5, 2023

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

@nebrelbug
Copy link
Collaborator

@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")}}

@perotom
Copy link
Author

perotom commented Oct 3, 2023

@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?

@nebrelbug
Copy link
Collaborator

nebrelbug commented Oct 3, 2023

@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 }}

@perotom
Copy link
Author

perotom commented Oct 4, 2023

@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.

@nebrelbug
Copy link
Collaborator

It's unfortunately probably not feasible for this project :(.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants