Description
Creating a meta proposal to bring together the discussion around #20, #19, #14, and #13. Feel free to correct me or close if I haven't thought about some edge cases in the individual locations that the pattern intends to be used, I'm less familiar with things like service worker scopes and CSP.
I'm making a couple of assumptions:
- Using a single string is the simplest API for developers
- Being incompatible with
path-to-regexp
is acceptable (on this point, it already is - just in a different way) - You don't use
*
(wildcards) as the default behavior - You enforce the scheme/hostname to be defined (e.g.
http://
,https?://
or*://
)
With these assumptions, I think you could create a simpler API that mirrors the URL
API. For example, new URLPattern('*', window.location)
would be supported. You could always enforce a full URL instead of partial URLs, similar to the current URL
API too.
In the service worker use-case, you can have it throw if the "origin" doesn't match the static prefix of the URLPattern
. There was already some need for this sort of behavior due to the scope matching ordering: https://github.com/WICG/urlpattern/blob/master/explainer.md#scope-match-ordering.
Finally, on the path matching "magic", if you remove the magic prefix/suffix and make it explicit you can just do new URLPattern('/:foo{/bar}?', 'http://{:subdomain.}*.example.com')
.