@@ -26,9 +26,13 @@ const { pathToRegexp, match, parse, compile } = require("path-to-regexp");
2626// compile(path)
2727```
2828
29+ ### Path to regexp
30+
31+ The ` pathToRegexp ` function will return a regular expression object based on the provided ` path ` argument. It accepts the following arguments:
32+
2933- ** path** A string, array of strings, or a regular expression.
30- - ** keys** An array to populate with keys found in the path.
31- - ** options**
34+ - ** keys** _ (optional) _ An array to populate with keys found in the path.
35+ - ** options** _ (optional) _
3236 - ** sensitive** When ` true ` the regexp will be case sensitive. (default: ` false ` )
3337 - ** strict** When ` true ` the regexp won't allow an optional trailing delimiter to match. (default: ` false ` )
3438 - ** end** When ` true ` the regexp will match to the end of the string. (default: ` true ` )
@@ -194,6 +198,21 @@ fn("/invalid"); //=> false
194198fn (" /user/caf%C3%A9" ); // => { path: '/user/caf%C3%A9', index: 0, params: { id: 'café' } }
195199```
196200
201+ The ` match ` function can be used to custom match named parameters. For example, this can be used to whitelist a small number of valid paths:
202+
203+ ``` js
204+ const urlMatch = match (" /users/:id/:tab(home|photos|bio)" , { decode: decodeURIComponent });
205+
206+ urlMatch (" /users/1234/photos" )
207+ // => { path: '/users/1234/photos', index: 0, params: { id: '1234', tab: 'photos' } }
208+
209+ urlMatch (" /users/1234/bio" )
210+ // => { path: '/users/1234/bio', index: 0, params: { id: '1234', tab: 'bio' } }
211+
212+ urlMatch (" /users/1234/otherstuff" )
213+ // => false
214+ ```
215+
197216#### Process Pathname
198217
199218You should make sure variations of the same path match the expected ` path ` . Here's one possible solution using ` encode ` :
0 commit comments