Open posva opened 3 years ago
Interesting idea, but I must admit I don't understand what this would be used for. Can you describe the use case? Thanks.
I would consider this useful for error reporting and inspecting purposes. For example, if a user tries to build a path by passing an object of groups to the pattern (which I believe must be another issue somewhere but doing pattern.buildURL({ id: 2 })
-> /2/static
), we can check any missing params and give the user better debugging information.
It can also be used to build UI around URL builders or checkers. For instance, I rely on this on the Vue Devtools.
Overall, this information would be very useful to extend the URLPattern API and would avoid hacks with Regexps to parse existing groups (which would partially defeat the purpose of URLPattern)
When creating a pattern like
new URLPattern('/:id/static/:tags*')
, there is no way of knowing what groups the pattern has (id and tags) nor their nature (optional, repeatable).I propose a way of getting these groups:
It's also worth noting this can be typed in TS too with string literals.