@@ -20,7 +20,7 @@ npm install path-to-regexp --save
20
20
``` javascript
21
21
const pathToRegexp = require (' path-to-regexp' )
22
22
23
- // pathToRegexp(path, keys?, options?)
23
+ // pathToRegexp.pathToRegexp (path, keys?, options?)
24
24
// pathToRegexp.match(path)
25
25
// pathToRegexp.parse(path)
26
26
// pathToRegexp.compile(path)
@@ -39,7 +39,7 @@ const pathToRegexp = require('path-to-regexp')
39
39
40
40
``` javascript
41
41
const keys = []
42
- const regexp = pathToRegexp (' /foo/:bar' , keys)
42
+ const regexp = pathToRegexp . pathToRegexp (' /foo/:bar' , keys)
43
43
// regexp = /^\/foo\/([^\/]+?)\/?$/i
44
44
// keys = [{ name: 'bar', prefix: '/', delimiter: '/', optional: false, repeat: false, pattern: '[^\\/]+?' }]
45
45
```
@@ -55,7 +55,7 @@ The path argument is used to define parameters and populate the list of keys.
55
55
Named parameters are defined by prefixing a colon to the parameter name (` :foo ` ). By default, the parameter will match until the next prefix (e.g. ` [^/]+ ` ).
56
56
57
57
``` js
58
- const regexp = pathToRegexp (' /:foo/:bar' )
58
+ const regexp = pathToRegexp . pathToRegexp (' /:foo/:bar' )
59
59
// keys = [{ name: 'foo', prefix: '/', ... }, { name: 'bar', prefix: '/', ... }]
60
60
61
61
regexp .exec (' /test/route' )
@@ -71,7 +71,7 @@ regexp.exec('/test/route')
71
71
Parameters can be suffixed with a question mark (` ? ` ) to make the parameter optional.
72
72
73
73
``` js
74
- const regexp = pathToRegexp (' /:foo/:bar?' )
74
+ const regexp = pathToRegexp . pathToRegexp (' /:foo/:bar?' )
75
75
// keys = [{ name: 'foo', ... }, { name: 'bar', delimiter: '/', optional: true, repeat: false }]
76
76
77
77
regexp .exec (' /test' )
@@ -88,7 +88,7 @@ regexp.exec('/test/route')
88
88
Parameters can be suffixed with an asterisk (` * ` ) to denote a zero or more parameter matches. The prefix is used for each match.
89
89
90
90
``` js
91
- const regexp = pathToRegexp (' /:foo*' )
91
+ const regexp = pathToRegexp . pathToRegexp (' /:foo*' )
92
92
// keys = [{ name: 'foo', delimiter: '/', optional: true, repeat: true }]
93
93
94
94
regexp .exec (' /' )
@@ -103,7 +103,7 @@ regexp.exec('/bar/baz')
103
103
Parameters can be suffixed with a plus sign (` + ` ) to denote a one or more parameter matches. The prefix is used for each match.
104
104
105
105
``` js
106
- const regexp = pathToRegexp (' /:foo+' )
106
+ const regexp = pathToRegexp . pathToRegexp (' /:foo+' )
107
107
// keys = [{ name: 'foo', delimiter: '/', optional: false, repeat: true }]
108
108
109
109
regexp .exec (' /' )
@@ -118,7 +118,7 @@ regexp.exec('/bar/baz')
118
118
It is possible to write an unnamed parameter that only consists of a matching group. It works the same as a named parameter, except it will be numerically indexed.
119
119
120
120
``` js
121
- const regexp = pathToRegexp (' /:foo/(.*)' )
121
+ const regexp = pathToRegexp . pathToRegexp (' /:foo/(.*)' )
122
122
// keys = [{ name: 'foo', ... }, { name: 0, ... }]
123
123
124
124
regexp .exec (' /test/route' )
@@ -130,7 +130,7 @@ regexp.exec('/test/route')
130
130
All parameters can have a custom regexp, which overrides the default match (` [^/]+ ` ). For example, you can match digits or names in a path:
131
131
132
132
``` js
133
- const regexpNumbers = pathToRegexp (' /icon-:foo(\\ d+).png' )
133
+ const regexpNumbers = pathToRegexp . pathToRegexp (' /icon-:foo(\\ d+).png' )
134
134
// keys = [{ name: 'foo', ... }]
135
135
136
136
regexpNumbers .exec (' /icon-123.png' )
@@ -139,7 +139,7 @@ regexpNumbers.exec('/icon-123.png')
139
139
regexpNumbers .exec (' /icon-abc.png' )
140
140
// => null
141
141
142
- const regexpWord = pathToRegexp (' /(user|u)' )
142
+ const regexpWord = pathToRegexp . pathToRegexp (' /(user|u)' )
143
143
// keys = [{ name: 0, ... }]
144
144
145
145
regexpWord .exec (' /u' )
0 commit comments