path-to-regexp 2.0.0 → 2.1.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.
Files changed (3) hide show
  1. package/History.md +12 -0
  2. package/index.js +24 -23
  3. package/package.json +1 -1
package/History.md CHANGED
@@ -1,3 +1,15 @@
1
+ 2.0.0 / 2017-08-23
2
+ ==================
3
+
4
+ * New option! Ability to set `endsWith` to match paths like `/test?query=string` up to the query string
5
+ * New option! Set `delimiters` for specific characters to be treated as parameter prefixes (e.g. `/:test`)
6
+ * Remove `isarray` dependency
7
+ * Explicitly handle trailing delimiters instead of trimming them (e.g. `/test/` is now treated as `/test/` instead of `/test` when matching)
8
+ * Remove overloaded `keys` argument that accepted `options`
9
+ * Remove `keys` list attached to the `RegExp` output
10
+ * Remove asterisk functionality (it's a real pain to properly encode)
11
+ * Change `tokensToFunction` (e.g. `compile`) to accept an `encode` function for pretty encoding (e.g. pass your own implementation)
12
+
1
13
  1.7.0 / 2016-11-08
2
14
  ==================
3
15
 
package/index.js CHANGED
@@ -7,6 +7,12 @@ module.exports.compile = compile
7
7
  module.exports.tokensToFunction = tokensToFunction
8
8
  module.exports.tokensToRegExp = tokensToRegExp
9
9
 
10
+ /**
11
+ * Default configs.
12
+ */
13
+ var DEFAULT_DELIMITER = '/'
14
+ var DEFAULT_DELIMITERS = './'
15
+
10
16
  /**
11
17
  * The main path matching regexp utility.
12
18
  *
@@ -36,8 +42,8 @@ function parse (str, options) {
36
42
  var key = 0
37
43
  var index = 0
38
44
  var path = ''
39
- var defaultDelimiter = (options && options.delimiter) || '/'
40
- var delimiters = (options && options.delimiters) || './'
45
+ var defaultDelimiter = (options && options.delimiter) || DEFAULT_DELIMITER
46
+ var delimiters = (options && options.delimiters) || DEFAULT_DELIMITERS
41
47
  var pathEscaped = false
42
48
  var res
43
49
 
@@ -295,9 +301,11 @@ function tokensToRegExp (tokens, keys, options) {
295
301
 
296
302
  var strict = options.strict
297
303
  var end = options.end !== false
298
- var delimiter = escapeString(options.delimiter || '/')
304
+ var delimiter = escapeString(options.delimiter || DEFAULT_DELIMITER)
305
+ var delimiters = options.delimiters || DEFAULT_DELIMITERS
299
306
  var endsWith = [].concat(options.endsWith || []).map(escapeString).concat('$').join('|')
300
307
  var route = ''
308
+ var isEndDelimited = false
301
309
 
302
310
  // Iterate over the tokens and create our regexp string.
303
311
  for (var i = 0; i < tokens.length; i++) {
@@ -305,41 +313,34 @@ function tokensToRegExp (tokens, keys, options) {
305
313
 
306
314
  if (typeof token === 'string') {
307
315
  route += escapeString(token)
316
+ isEndDelimited = i === tokens.length - 1 && delimiters.indexOf(token[token.length - 1]) > -1
308
317
  } else {
309
318
  var prefix = escapeString(token.prefix)
310
- var capture = '(?:' + token.pattern + ')'
319
+ var capture = token.repeat
320
+ ? '(?:' + token.pattern + ')(?:' + prefix + '(?:' + token.pattern + '))*'
321
+ : token.pattern
311
322
 
312
323
  if (keys) keys.push(token)
313
324
 
314
- if (token.repeat) {
315
- capture += '(?:' + prefix + capture + ')*'
316
- }
317
-
318
325
  if (token.optional) {
319
- if (!token.partial) {
320
- capture = '(?:' + prefix + '(' + capture + '))?'
326
+ if (token.partial) {
327
+ route += prefix + '(' + capture + ')?'
321
328
  } else {
322
- capture = prefix + '(' + capture + ')?'
329
+ route += '(?:' + prefix + '(' + capture + '))?'
323
330
  }
324
331
  } else {
325
- capture = prefix + '(' + capture + ')'
332
+ route += prefix + '(' + capture + ')'
326
333
  }
327
-
328
- route += capture
329
334
  }
330
335
  }
331
336
 
332
- // In non-strict mode we allow a delimiter at the end of a match.
333
- if (!strict) {
334
- route += '(?:' + delimiter + '(?=' + endsWith + '))?'
335
- }
336
-
337
337
  if (end) {
338
- route += endsWith === '$' ? endsWith : '(?=' + endsWith + ')'
338
+ if (!strict) route += '(?:' + delimiter + ')?'
339
+
340
+ route += endsWith === '$' ? '$' : '(?=' + endsWith + ')'
339
341
  } else {
340
- // In non-ending mode, we need the capturing groups to match as much as
341
- // possible by using a positive lookahead to the end or next path segment.
342
- route += '(?=' + delimiter + '|' + endsWith + ')'
342
+ if (!strict) route += '(?:' + delimiter + '(?=' + endsWith + '))?'
343
+ if (!isEndDelimited) route += '(?=' + delimiter + '|' + endsWith + ')'
343
344
  }
344
345
 
345
346
  return new RegExp('^' + route, flags(options))
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.0.0",
4
+ "version": "2.1.0",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
7
7
  "files": [