You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,8 +25,8 @@ var pathToRegexp = require('path-to-regexp')
25
25
// pathToRegexp.compile(path)
26
26
```
27
27
28
-
-**path**A string in the express format, an array of strings, or a regular expression.
29
-
-**keys** An array to be populated with the keys present in the url.
28
+
-**path**An Express-style string, an array of strings, or a regular expression.
29
+
-**keys** An array to be populated with the keys found in the path.
30
30
-**options**
31
31
-**sensitive** When `true` the route will be case sensitive. (default: `false`)
32
32
-**strict** When `false` the trailing slash is optional. (default: `false`)
@@ -41,11 +41,11 @@ var re = pathToRegexp('/foo/:bar', keys)
41
41
42
42
### Parameters
43
43
44
-
The path has the ability to define parameters and automatically populate the keys array.
44
+
The path string can be used to define parameters and populate the keys.
45
45
46
46
#### Named Parameters
47
47
48
-
Named parameters are defined by prefixing a colon to the parameter name (`:foo`). By default, this parameter will match up to the next path segment.
48
+
Named parameters are defined by prefixing a colon to the parameter name (`:foo`). By default, this parameter will match the following path segment.
49
49
50
50
```js
51
51
var re =pathToRegexp('/:foo/:bar', keys)
@@ -59,7 +59,7 @@ re.exec('/test/route')
59
59
60
60
##### Optional
61
61
62
-
Parameters can be suffixed with a question mark (`?`) to make the entire parameter optional. This will also make any prefixed path delimiter optional (`/` or `.`).
62
+
Parameters can be suffixed with a question mark (`?`) to make the parameter optional. This will also make any the prefixed path delimiter optional (`/` or `.`).
63
63
64
64
```js
65
65
var re =pathToRegexp('/:foo/:bar?', keys)
@@ -74,7 +74,7 @@ re.exec('/test/route')
74
74
75
75
##### Zero or more
76
76
77
-
Parameters can be suffixed with an asterisk (`*`) to denote a zero or more parameter match. The prefixed path delimiter is also taken into account for the match.
77
+
Parameters can be suffixed with an asterisk (`*`) to denote a zero or more parameter matches. The prefixed path delimiter is taken into account for each match.
78
78
79
79
```js
80
80
var re =pathToRegexp('/:foo*', keys)
@@ -89,7 +89,7 @@ re.exec('/bar/baz')
89
89
90
90
##### One or more
91
91
92
-
Parameters can be suffixed with a plus sign (`+`) to denote a one or more parameters match. The prefixed path delimiter is included in the match.
92
+
Parameters can be suffixed with a plus sign (`+`) to denote a one or more parameter matches. The prefixed path delimiter is taken into account for each match.
93
93
94
94
```js
95
95
var re =pathToRegexp('/:foo+', keys)
@@ -104,7 +104,7 @@ re.exec('/bar/baz')
104
104
105
105
#### Custom Match Parameters
106
106
107
-
All parameters can be provided a custom matching regexp and override the default. Please note: Backslashes need to be escaped in strings.
107
+
All parameters can be provided a custom regexp, which overrides the default (`[^\/]+`). Please note: Backslashes need to be escaped with another backslash in strings.
108
108
109
109
```js
110
110
var re =pathToRegexp('/:foo(\\d+)', keys)
@@ -119,11 +119,11 @@ re.exec('/abc')
119
119
120
120
#### Unnamed Parameters
121
121
122
-
It is possible to write an unnamed parameter that is only a matching group. It works the same as a named parameter, except it will be numerically indexed.
122
+
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.
**Note:** This method only works with Express-style strings.
162
162
163
163
### Compile ("Reverse" Path-To-RegExp)
164
164
165
-
Path-To-RegExp exposes a compile function for transforming an express path into valid path. Confusing enough? This example will straighten everything out for you.
165
+
Path-To-RegExp exposes a compile function for transforming an Express-style path into a valid path.
**Note:** The generated function will throw on any invalid input. It will execute all necessary checks to ensure the generated path is valid. This method only works with strings.
186
+
**Note:** The generated function will throw on invalid input. It will do all necessary checks to ensure the generated path is valid. This method only works with strings.
0 commit comments