-
Notifications
You must be signed in to change notification settings - Fork 25
Closed
Description
I made a small polyfill on top of path-to-regex to play around with this and found a few differences.
First of all, something like
pathname: '/*.:imagetype(jpg|gif|png)'
doesn't work, the wildcard has to be (.*) instead. I do like the /* wildcard so maybe we can just document this as an improvement.
You expose named groups as result.pathname.groups - but JS regexp actually supports named groups now (path-to-regex doesn't use that feature) and that it exposed to result.groups.
Basically this
const imagePattern = new URLPattern({
pathname: '/(.*).:imagetype(jpg|gif|png)'
});
let result = imagePattern.exec("/photo.jpg");
console.log(result)
console.log(result.pathname.groups['imagetype']);could be done with regexps like:
const imageRegex = new RegExp("/(.*)\.(?<imagetype>jpg|gif|png)");
let res = imageRegex.exec("/photo.jpg");
console.log(res);
console.log(res.groups['imagetype']);Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels