rcs / route-parser

An isomorphic, bullet-proof, ninja-ready route parsing, matching, and reversing library for Javascript in Node and the browser.
MIT License
352 stars 34 forks source link

Add `.asRegExp()` method to return regexp for route #27

Open simonflk opened 7 years ago

simonflk commented 7 years ago

I'm using route-parser in my react app, and it's working great, thank you! And my local dev server is serving 2 single-page apps using connect-history-api-fallback to determine which one to serve based on the URL.

Thus far I've manually crafted a regexp, then moved on to writing my own route-parser route -> regexp parser, and quickly decided that was a bit silly since route-parser can give me the regular expressions.

So here I am with a PR to expose the regexp on the route. I'm interested to know what your thoughts on this are. Personally I'm happy to continue using the regexp visitor in my code, but I'd feel better knowing that was stable/documented. I'm happy to submit a PR for docs instead.

Another solution would be to modify connect-history-api-fallback to accept a function in place of a regexp. But I'm not a direct consumer of that module. Rather I'm using webpack-dev-server, which uses that under the hood.

rcs commented 7 years ago

I'm glad you find this useful!

I like this. It makes sense, it makes it easier to use in more environments, and it hadn't occured to me how useful hat might be.

I am a little bit apprehensive, however, because I'm not entirely sure that this is an API that continues to make sense if a candidate for specifying query parameters ever works for this library, since I'm not sure that a regex will still be the solution. (Extracting query parameters, and specifying them, is a common request.)

That said: If it comes down to that, it would also be a reason to bump a major version if it couldn't be supported, and that's not the end of the world.

Thoughts?