path-to-regexp 1.6.0 → 1.7.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,10 @@
1
+ 1.6.0 / 2016-10-03
2
+ ==================
3
+
4
+ * Populate `RegExp.keys` when using the `tokensToRegExp` method (making it consistent with the main export)
5
+ * Allow a `delimiter` option to be passed in with `parse`
6
+ * Updated TypeScript definition with `Keys` and `Options` updated
7
+
1
8
  1.5.3 / 2016-06-15
2
9
  ==================
3
10
 
package/index.d.ts CHANGED
@@ -20,6 +20,10 @@ declare namespace pathToRegexp {
20
20
  * When `false` the path will match at the beginning. (default: `true`)
21
21
  */
22
22
  end?: boolean;
23
+ /**
24
+ * Sets the final character for non-ending optimistic matches. (default: `/`)
25
+ */
26
+ delimiter?: string;
23
27
  }
24
28
 
25
29
  export interface ParseOptions {
package/index.js CHANGED
@@ -341,8 +341,6 @@ function tokensToRegExp (tokens, keys, options) {
341
341
  var strict = options.strict
342
342
  var end = options.end !== false
343
343
  var route = ''
344
- var lastToken = tokens[tokens.length - 1]
345
- var endsWithSlash = typeof lastToken === 'string' && /\/$/.test(lastToken)
346
344
 
347
345
  // Iterate over the tokens and create our regexp string.
348
346
  for (var i = 0; i < tokens.length; i++) {
@@ -374,12 +372,15 @@ function tokensToRegExp (tokens, keys, options) {
374
372
  }
375
373
  }
376
374
 
375
+ var delimiter = escapeString(options.delimiter || '/')
376
+ var endsWithDelimiter = route.slice(-delimiter.length) === delimiter
377
+
377
378
  // In non-strict mode we allow a slash at the end of match. If the path to
378
379
  // match already ends with a slash, we remove it for consistency. The slash
379
380
  // is valid at the end of a path match, not in the middle. This is important
380
381
  // in non-ending mode, where "/test/" shouldn't match "/test//route".
381
382
  if (!strict) {
382
- route = (endsWithSlash ? route.slice(0, -2) : route) + '(?:\\/(?=$))?'
383
+ route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?'
383
384
  }
384
385
 
385
386
  if (end) {
@@ -387,7 +388,7 @@ function tokensToRegExp (tokens, keys, options) {
387
388
  } else {
388
389
  // In non-ending mode, we need the capturing groups to match as much as
389
390
  // possible by using a positive lookahead to the end or next path segment.
390
- route += strict && endsWithSlash ? '' : '(?=\\/|$)'
391
+ route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)'
391
392
  }
392
393
 
393
394
  return attachKeys(new RegExp('^' + route, flags(options)), keys)
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": "1.6.0",
4
+ "version": "1.7.0",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
7
7
  "files": [