[#470] add map helper to the templating system#471
Conversation
klappradla
left a comment
There was a problem hiding this comment.
Hey @ilyabayel 👋
welcome and thanks for your contribution 🙏
I think it's a viable use case and a feature that others could also benefit from. So yes, let's do this.
I have some thought on the implementation details though. May be personal preference, but I find the "array"-style format for something that's supposed to be a key-value-mapping a bit irritating and hard to read. How about we encode key and value as a string instead, like so:
{type | map("story:feat", "bug:fix", "task:chore")}
I would prefer to only have one syntax. This ☝️ is a bit the middle of what you proposed. What do you think?
| export const lowercase = (): StringMappingFn => (s) => s.toLowerCase(); | ||
|
|
||
| // This is a mapping function, it can be used in two ways: | ||
| // 1. With an object: map({ a: "b" }) will return a function that maps "a" to "b" and returns the original value for any other input. |
There was a problem hiding this comment.
Did you try this out in the settings? It does not work for me and I think™ that's because the { and } are reserved characters in our DIY templating language.
There was a problem hiding this comment.
only in unit tests, but not in chorme itself. Probably it's broken there
Hey @klappradla, thanks for welcoming me! I initially chose the
I like your proposed syntax too, but there's an important edge case to consider: The second variant is more readable when values contain colons. So there is a trade-off:
I'm open to either approach - what do you think? |
remove object as parameter add docs
Oh, very good point! Well while I would have preferred the |
klappradla
left a comment
There was a problem hiding this comment.
Thanks for the updates!
I'd suggest a small simplification on the function itself and align the doc string still. For whether mapping should be plural or not, that's probably personal preference. I'm undecided myself 🙈
klappradla
left a comment
There was a problem hiding this comment.
Thanks for the updates 🙏
Looking good ✨
I'm not sure when I'll come around to release this. But hopefully this week. I'll keep you posted @ilyabayel 💌
Hey, folks! How is it going?
Could you please review this MR and check if it useful to have this feature?
Add
maphelper function to templating system for conditional mapping stringsCloses: #470