path-to-regexp 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/History.md CHANGED
@@ -1,3 +1,14 @@
1
+ 2.1.0 / 2018-03-06
2
+ ==================
3
+
4
+ * Pass `token` as second argument to `encode` option (e.g. `encode(value, token)`)
5
+
6
+ 2.1.0 / 2017-10-20
7
+ ==================
8
+
9
+ * Handle non-ending paths where the final character is a delimiter
10
+ * E.g. `/foo/` before required either `/foo/` or `/foo//` to match in non-ending mode
11
+
1
12
  2.0.0 / 2017-08-23
2
13
  ==================
3
14
 
package/Readme.md CHANGED
@@ -61,15 +61,7 @@ re.exec('/test/route')
61
61
  //=> ['/test/route', 'test', 'route']
62
62
  ```
63
63
 
64
- **Please note:** Named parameters must be made up of "word characters" (`[A-Za-z0-9_]`).
65
-
66
- ```js
67
- var re = pathToRegexp('/(apple-)?icon-:res(\\d+).png')
68
- // keys = [{ name: 0, prefix: '/', ... }, { name: 'res', prefix: '', ... }]
69
-
70
- re.exec('/icon-76.png')
71
- //=> ['/icon-76.png', undefined, '76']
72
- ```
64
+ **Please note:** Parameter names must be made up of "word characters" (`[A-Za-z0-9_]`).
73
65
 
74
66
  #### Parameter Modifiers
75
67
 
@@ -120,18 +112,18 @@ re.exec('/bar/baz')
120
112
  //=> ['/bar/baz', 'bar/baz']
121
113
  ```
122
114
 
123
- #### Custom Match Parameters
115
+ #### Custom Matching Parameters
124
116
 
125
- All parameters can be provided a custom regexp, which overrides the default (`[^\/]+`).
117
+ All parameters can be provided a custom regexp, which overrides the default match (`[^\/]+`). For example, you can match digits in the path:
126
118
 
127
119
  ```js
128
- var re = pathToRegexp('/:foo(\\d+)')
120
+ var re = pathToRegexp('/icon-:foo(\\d+).png')
129
121
  // keys = [{ name: 'foo', ... }]
130
122
 
131
- re.exec('/123')
132
- //=> ['/123', '123']
123
+ re.exec('/icon-123.png')
124
+ //=> ['/icon-123.png', '123']
133
125
 
134
- re.exec('/abc')
126
+ re.exec('/icon-abc.png')
135
127
  //=> null
136
128
  ```
137
129
 
@@ -180,7 +172,7 @@ toPath({ id: 'café' }) //=> "/user/caf%C3%A9"
180
172
  toPath({ id: '/' }) //=> "/user/%2F"
181
173
 
182
174
  toPath({ id: ':/' }) //=> "/user/%3A%2F"
183
- toPath({ id: ':/' }, { encode: (x) => x }) //=> "/user/:/"
175
+ toPath({ id: ':/' }, { encode: (value, token) => value }) //=> "/user/:/"
184
176
 
185
177
  var toPathRepeated = pathToRegexp.compile('/:segment+')
186
178
 
package/index.d.ts CHANGED
@@ -69,7 +69,7 @@ declare namespace pathToRegexp {
69
69
  /**
70
70
  * Function for encoding input strings for output.
71
71
  */
72
- encode?: (value: string) => string;
72
+ encode?: (value: string, token: Key) => string;
73
73
  }
74
74
 
75
75
  export type Token = string | Key;
package/index.js CHANGED
@@ -161,7 +161,7 @@ function tokensToFunction (tokens) {
161
161
  }
162
162
 
163
163
  for (var j = 0; j < value.length; j++) {
164
- segment = encode(value[j])
164
+ segment = encode(value[j], token)
165
165
 
166
166
  if (!matches[i].test(segment)) {
167
167
  throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"')
@@ -174,7 +174,7 @@ function tokensToFunction (tokens) {
174
174
  }
175
175
 
176
176
  if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
177
- segment = encode(String(value))
177
+ segment = encode(String(value), token)
178
178
 
179
179
  if (!matches[i].test(segment)) {
180
180
  throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"')
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "path-to-regexp",
3
3
  "description": "Express style path to RegExp utility",
4
- "version": "2.1.0",
4
+ "version": "2.2.0",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
7
7
  "files": [