Skip to content

Commit 6587c81

Browse files
authored
Move parameter name errors up in docs (#402)
1 parent 9df2448 commit 6587c81

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Readme.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,31 +178,31 @@ fn("/test"); //=> { path: '/test', index: 0, params: { foo: 'test' } }
178178

179179
An effort has been made to ensure ambiguous paths from previous releases throw an error. This means you might be seeing an error when things worked before.
180180

181+
### Missing parameter name
182+
183+
Parameter names must be provided after `:` or `*`, for example `/*path`. They can be valid JavaScript identifiers (e.g. `:myName`) or JSON strings (`:"my-name"`).
184+
181185
### Unexpected `?` or `+`
182186

183187
In past releases, `?`, `*`, and `+` were used to denote optional or repeating parameters. As an alternative, try these:
184188

185-
- For optional (`?`), use an empty segment in a group such as `/:file{.:ext}`.
186-
- For repeating (`+`), only wildcard matching is supported, such as `/*path`.
187-
- For optional repeating (`*`), use a group and a wildcard parameter such as `/files{/*path}`.
189+
- For optional (`?`), use braces: `/file{.:ext}`.
190+
- For one or more (`+`), use a wildcard: `/*path`.
191+
- For zero or more (`*`), use both: `/files{/*path}`.
188192

189193
### Unexpected `(`, `)`, `[`, `]`, etc.
190194

191-
Previous versions of Path-to-RegExp used these for RegExp features. This version no longer supports them so they've been reserved to avoid ambiguity. To use these characters literally, escape them with a backslash, e.g. `"\\("`.
192-
193-
### Missing parameter name
194-
195-
Parameter names must be provided after `:` or `*`, and they must be a valid JavaScript identifier. If you want an parameter name that isn't a JavaScript identifier, such as starting with a number, you can wrap the name in quotes like `:"my-name"`.
195+
Previous versions of Path-to-RegExp used these for RegExp features. This version no longer supports them so they've been reserved to avoid ambiguity. To match these characters literally, escape them with a backslash, e.g. `"\\("`.
196196

197197
### Unterminated quote
198198

199-
Parameter names can be wrapped in double quote characters, and this error means you forgot to close the quote character.
199+
Parameter names can be wrapped in double quote characters, and this error means you forgot to close the quote character. For example, `:"foo`.
200200

201201
### Express <= 4.x
202202

203203
Path-To-RegExp breaks compatibility with Express <= `4.x` in the following ways:
204204

205-
- The wildcard `*` must have a name, matching the behavior of parameters `:`.
205+
- The wildcard `*` must have a name and matches the behavior of parameters `:`.
206206
- The optional character `?` is no longer supported, use braces instead: `/:file{.:ext}`.
207207
- Regexp characters are not supported.
208208
- Some characters have been reserved to avoid confusion during upgrade (`()[]?+!`).

0 commit comments

Comments
 (0)