Why is pathToRegexp mutating keys parameter?
The examples are unclear on why it works that way. Mutating params feels wrong, because in the code it is not very easy to understand how my empty keys array gets populated. So it's always necessary to add a comment about how it works (if I want the next developer to understand it as well).
Wouldn't it make better sense to return the keys from pathToRegexp? For example, like so:
type pathToRegexp = (path, opts) => { matcher: Regexp, keys: Keys };
This is just the API that was originally designed, and I’ve avoided changing it so far. I’m not sure there’s a good reason to change it. I’ve instead moved some functionality away from raw regexes to make it a bit more user friendly. We could probably start returning keys as a property of the RegExp to continue maintaining backward compatibility.
Immutability and clarity in code would be pretty good reasons in my opinion :)
I believe keys was a property of the RegExp sometime in the past. I had to figure out what happened to the keys in frctl/fractal#714 when I updated path-to-regexp from 1.7.0 to latest, hence the confusion and this issue. So reintroducing that solution would make sense to me, although I would prefer having a "clean" Regexp and a separate keys value since types get complicated when putting additional properties to native types.
Hi! I'm new to the project but I wanted to contribute to it since I really like it. I was wondering if there is any interest in this issue since I wanted to try to pick it up.