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
The `pathToRegexp` function returns a regular expression with `keys` as a property. It accepts the following arguments:
29
+
The `match` function returns a function for transforming paths into parameters:
31
30
32
31
-**path** A string.
33
-
-**options**_(optional)_
32
+
-**options**_(optional)_ (See [parse](#parse) for more options)
34
33
-**sensitive** Regexp will be case sensitive. (default: `false`)
35
-
-**trailing** Allows optional trailing delimiter to match. (default: `true`)
36
-
-**strict** Verify patterns are valid and safe to use. (default: `false`, recommended: `true`)
37
-
-**end** Match to the end of the string. (default: `true`)
38
-
-**start** Match from the beginning of the string. (default: `true`)
39
-
-**loose** Allow the delimiter to be arbitrarily repeated, e.g. `/` or `///`. (default: `true`)
40
-
-**delimiter** The default delimiter for segments, e.g. `[^/]` for `:named` parameters. (default: `'/'`)
41
-
-**encodePath** A function for encoding input strings. (default: `x => x`, recommended: [`encodeurl`](https://github.com/pillarjs/encodeurl) for unicode encoding)
34
+
-**end** Validate the match reaches the end of the string. (default: `true`)
35
+
-**decode** Function for decoding strings to params, or `false` to disable all processing. (default: `decodeURIComponent`)
**Please note:**The `RegExp` returned by `path-to-regexp` is intended for ordered data (e.g. pathnames, hostnames). It can not handle arbitrarily ordered data (e.g. query strings, URL fragments, JSON, etc).
41
+
**Please note:**`path-to-regexp` is intended for ordered data (e.g. pathnames, hostnames). It can not handle arbitrarily ordered data (e.g. query strings, URL fragments, JSON, etc).
50
42
51
43
### Parameters
52
44
53
-
The path argument is used to define parameters and populate keys.
45
+
Parameters match arbitrary strings in a path by matching up to the end of the segment, or up to any proceeding tokens.
54
46
55
47
#### Named parameters
56
48
57
-
Named parameters are defined by prefixing a colon to the parameter name (`:foo`). Parameter names can use any valid unicode identifier characters (similar to JavaScript).
49
+
Named parameters are defined by prefixing a colon to the parameter name (`:foo`). Parameter names can use any valid unicode identifier characters, similar to JavaScript.
**Note:** Setting `decode: false` disables the "splitting" behavior of repeated parameters, which is useful if you need the exactly matched parameter back.
214
-
215
181
### Compile ("Reverse" Path-To-RegExp)
216
182
217
183
The `compile` function will return a function for transforming parameters into a valid path:
218
184
219
185
-**path** A string.
220
-
-**options**_(optional)_ Similar to `pathToRegexp` (`delimiter`, `encodePath`, `sensitive`, and `loose`), plus:
186
+
-**options** (See [parse](#parse) for more options)
187
+
-**sensitive** Regexp will be case sensitive. (default: `false`)
221
188
-**validate** When `false` the function can produce an invalid (unmatched) path. (default: `true`)
222
189
-**encode** Function for encoding input strings for output into the path, or `false` to disable entirely. (default: `encodeURIComponent`)
- If you are rewriting paths with match and compiler, consider using `encode: false` and `decode: false` to keep raw paths passed around.
215
+
- If you are rewriting paths with match and compile, consider using `encode: false` and `decode: false` to keep raw paths passed around.
249
216
- To ensure matches work on paths containing characters usually encoded, consider using [encodeurl](https://github.com/pillarjs/encodeurl) for `encodePath`.
250
-
- If matches are intended to be exact, you need to set `loose: false`, `trailing: false`, and `sensitive: true`.
251
-
- Enable `strict: true` to detect ReDOS issues.
252
217
253
218
### Parse
254
219
255
-
A `parse` function is available and returns `TokenData`, the set of tokens and other metadata parsed from the input string. `TokenData` is can passed directly into `pathToRegexp`, `match`, and `compile`. It accepts only two options, `delimiter` and `encodePath`, which makes those options redundant in the above methods.
220
+
The `parse` function accepts a string and returns `TokenData`, the set of tokens and other metadata parsed from the input string. `TokenData` is can used with `$match` and `$compile`.
221
+
222
+
-**path** A string.
223
+
-**options**_(optional)_
224
+
-**delimiter** The default delimiter for segments, e.g. `[^/]` for `:named` parameters. (default: `'/'`)
225
+
-**encodePath** A function for encoding input strings. (default: `x => x`, recommended: [`encodeurl`](https://github.com/pillarjs/encodeurl) for unicode encoding)
256
226
257
227
### Tokens
258
228
@@ -267,14 +237,14 @@ The `tokens` returned by `TokenData` is an array of strings or keys, represented
267
237
268
238
### Custom path
269
239
270
-
In some applications, you may not be able to use the `path-to-regexp` syntax (e.g. file-based routing), but you can still use this library for `match`, `compile`, and `pathToRegexp` by building your own `TokenData` instance. For example:
240
+
In some applications, you may not be able to use the `path-to-regexp` syntax, but still want to use this library for `match`and `compile`. For example:
@@ -299,6 +269,30 @@ Used as a [custom separator](#custom-separator) for repeated parameters.
299
269
300
270
These characters have been reserved for future use.
301
271
272
+
### Missing separator
273
+
274
+
Repeated parameters must have a separator to be valid. For example, `{:foo}*` can't be used. Separators can be defined manually, such as `{:foo;/}*`, or they default to the suffix and prefix with the parameter, such as `{/:foo}*`.
275
+
276
+
### Missing parameter name
277
+
278
+
Parameter names, the part after `:`, must be a valid JavaScript identifier. For example, it cannot start with a number or dash. If you want a parameter name that uses these characters you can wrap the name in quotes, e.g. `:"my-name"`.
279
+
280
+
### Unterminated quote
281
+
282
+
Parameter names can be wrapped in double quote characters, and this error means you forgot to close the quote character.
283
+
284
+
### Pattern cannot start with "?"
285
+
286
+
Parameters in `path-to-regexp` must be basic groups. However, you can use features that require the `?` nested within the pattern. For example, `:foo((?!login)[^/]+)` is valid, but `:foo(?!login)` is not.
287
+
288
+
### Capturing groups are not allowed
289
+
290
+
A parameter pattern can not contain nested capturing groups.
291
+
292
+
### Unbalanced or missing pattern
293
+
294
+
A parameter pattern must have the expected number of parentheses. An unbalanced amount, such as `((?!login)` implies something has been written that is invalid. Check you didn't forget any parentheses.
295
+
302
296
### Express <= 4.x
303
297
304
298
Path-To-RegExp breaks compatibility with Express <= `4.x` in the following ways:
0 commit comments