Skip to content

Commit dbd79fc

Browse files
ryanwaltersblakeembrey
authored andcommitted
Add "start" config option (#165)
1 parent 73efd2d commit dbd79fc

File tree

4 files changed

+590
-363
lines changed

4 files changed

+590
-363
lines changed

index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ declare namespace pathToRegexp {
1010
* When `true` the regexp allows an optional trailing delimiter to match. (default: `false`)
1111
*/
1212
strict?: boolean;
13+
/**
14+
* When `false` the regexp will match the end instead of the entire string. (default: `true`)
15+
*/
16+
start?: boolean;
1317
/**
1418
* When `false` the regexp will match the beginning instead of the entire string. (default: `true`)
1519
*/

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,12 @@ function tokensToRegExp (tokens, keys, options) {
300300
options = options || {}
301301

302302
var strict = options.strict
303+
var start = options.start !== false
303304
var end = options.end !== false
304305
var delimiter = escapeString(options.delimiter || DEFAULT_DELIMITER)
305306
var delimiters = options.delimiters || DEFAULT_DELIMITERS
306307
var endsWith = [].concat(options.endsWith || []).map(escapeString).concat('$').join('|')
307-
var route = ''
308+
var route = start ? '^' : ''
308309
var isEndDelimited = tokens.length === 0
309310

310311
// Iterate over the tokens and create our regexp string.
@@ -342,7 +343,7 @@ function tokensToRegExp (tokens, keys, options) {
342343
if (!isEndDelimited) route += '(?=' + delimiter + '|' + endsWith + ')'
343344
}
344345

345-
return new RegExp('^' + route, flags(options))
346+
return new RegExp(route, flags(options))
346347
}
347348

348349
/**

0 commit comments

Comments
 (0)