Added find-first and find-last formatters with corresponding tests#58
Conversation
|
Wondering if having two explicit formatters is preferred over one that takes a first/last prop |
My 2cents is it makes sense to keep them split as it is analogous to |
|
I think my point still stands about the 95% overlap in the code. You could generalize this and create a function that takes 3 args, then implement 3 formatters that wrap that function CSS supports |
|
This change is publishing to Maven Central (and should be there in a few minutes) in version |
This PR adds two new formatters to the compiler, find-first and find-last that allow you to find the first/last element that returns a truthy given a path and lookup. See this ticket for the reason we need these new formatters.
Syntax
Arguments
PATH(optional)LOOKUP(optional, used with PATH)PATHis returned.Examples
Return the last element unconditionally:
JSON
{ "items": ["a", "b", "c"] }Json-t
Output
Return the last element where a nested field is truthy:
JSON
{ "items": [ { "id": "a", "enabled": true }, { "id": "b", "enabled": true }, { "id": "c", "enabled": false } ] }Json-t
Output
Look up each key in a separate object and return the last key with a truthy value at a path:
JSON
{ "keys": ["a", "b", "c"], "map": { "a": { "enabled": false }, "b": { "enabled": true }, "c": { "enabled": true } } }Json-t
Output