Many templating languages support filtering individual interpolated values:
"Hello, {name | capitalize}!"
//=> with {name: "john doe"} => "Hello, John Doe!"
pupa
supports transforming all values, but not individual ones. The regex to match items could be modified to:
/{(\d+|[a-z$_][\w\-$]*?(?:\.[\w\-$]*?)*?)(?: \| [^ }]+)*}/gi
This would match an arbitrary number of filters separated by |
. (regex101)
Filters would just be an object of functions passed to pupa
and would be applied in order from left to right. Filters in the template without a match could have the same semantics as a missing value (either get ignored or throw, perhaps with a new MissingFilterError
).
Related, some further improvements to the regex could be supporting arbitrary whitespace and characters:
/{\s*([^\s}|]+)\s*(?:\|\s*[^}]+\s*)*}/gi
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too