Closed ozmuir closed 9 years ago
good idea ! i'll implement it.
what do you think about the following edge case behaviour ?
if there are more groups in the regex than there are names in the array that is the second argument: ignore captured values for the remaining superfluous groups.
if there are less groups in the regex than there are names in the array that is the second argument: ignored the remaining superfluous names.
shouldn't break backwards compatibility - which is nice.
:thumbsup: however don't you think it'll be more expressive to not just ignore but:
undefined
?
:wink:i now think we should consider it a user error if the number of groups and names in the array don't match up.
i would like to throw an error in such cases to notify the user of bad usage. better to blow up on that set of user bugs that to let them go unnoticed.
i might use http://stackoverflow.com/a/16046903 to detect the number of groups and be able to check for such errors as soon as possible i.e. on pattern creation and not on match (callsites of .match
tend to be far away from pattern creation).
what do you think ?
sure, sounds good.
this is now published in 0.10.0. click here for the relevant readme section. there are some breaking changes. click to see the changelog entry.
It'll be a nice little addition to have named regex segments, for ex.
new UrlPattern(/^\/user\/(\d+)\//i, ["user_id"])