File tree Expand file tree Collapse file tree 3 files changed +64
-5
lines changed Expand file tree Collapse file tree 3 files changed +64
-5
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,13 @@ declare namespace pathToRegexp {
39
39
delimiter ?: string ;
40
40
}
41
41
42
+ export interface TokensToFunctionOptions {
43
+ /**
44
+ * When `true` the regexp will be case sensitive. (default: `false`)
45
+ */
46
+ sensitive ?: boolean ;
47
+ }
48
+
42
49
/**
43
50
* Parse an Express-style path into an array of tokens.
44
51
*/
@@ -47,12 +54,12 @@ declare namespace pathToRegexp {
47
54
/**
48
55
* Transforming an Express-style path into a valid path.
49
56
*/
50
- export function compile < P extends object = object > ( path : string , options ?: ParseOptions ) : PathFunction < P > ;
57
+ export function compile < P extends object = object > ( path : string , options ?: ParseOptions & TokensToFunctionOptions ) : PathFunction < P > ;
51
58
52
59
/**
53
60
* Transform an array of tokens into a path generator function.
54
61
*/
55
- export function tokensToFunction < P extends object = object > ( tokens : Token [ ] ) : PathFunction < P > ;
62
+ export function tokensToFunction < P extends object = object > ( tokens : Token [ ] , options ?: TokensToFunctionOptions ) : PathFunction < P > ;
56
63
57
64
/**
58
65
* Transform an array of tokens into a matching regular expression.
Original file line number Diff line number Diff line change @@ -117,20 +117,20 @@ function parse (str, options) {
117
117
* @return {!function(Object=, Object=) }
118
118
*/
119
119
function compile ( str , options ) {
120
- return tokensToFunction ( parse ( str , options ) )
120
+ return tokensToFunction ( parse ( str , options ) , options )
121
121
}
122
122
123
123
/**
124
124
* Expose a method for transforming tokens into the path function.
125
125
*/
126
- function tokensToFunction ( tokens ) {
126
+ function tokensToFunction ( tokens , options ) {
127
127
// Compile all the tokens into regexps.
128
128
var matches = new Array ( tokens . length )
129
129
130
130
// Compile all the patterns before compilation.
131
131
for ( var i = 0 ; i < tokens . length ; i ++ ) {
132
132
if ( typeof tokens [ i ] === 'object' ) {
133
- matches [ i ] = new RegExp ( '^(?:' + tokens [ i ] . pattern + ')$' )
133
+ matches [ i ] = new RegExp ( '^(?:' + tokens [ i ] . pattern + ')$' , flags ( options ) )
134
134
}
135
135
}
136
136
Original file line number Diff line number Diff line change @@ -2651,6 +2651,58 @@ var TESTS: Test[] = [
2651
2651
[ { attr2 : 'attr' } , 'name-attr' ]
2652
2652
]
2653
2653
] ,
2654
+
2655
+ /**
2656
+ * Case-sensitive compile tokensToFunction params.
2657
+ */
2658
+ [
2659
+ '/:test(abc)' ,
2660
+ {
2661
+ sensitive : true
2662
+ } ,
2663
+ [
2664
+ {
2665
+ name : 'test' ,
2666
+ prefix : '/' ,
2667
+ delimiter : '/' ,
2668
+ optional : false ,
2669
+ repeat : false ,
2670
+ pattern : 'abc'
2671
+ }
2672
+ ] ,
2673
+ [
2674
+ [ '/abc' , [ '/abc' , 'abc' ] ] ,
2675
+ [ '/ABC' , null ]
2676
+ ] ,
2677
+ [
2678
+ [ { test : 'abc' } , '/abc' ] ,
2679
+ [ { test : 'ABC' } , null ]
2680
+ ]
2681
+ ] ,
2682
+ [
2683
+ '/:test(abc)' ,
2684
+ {
2685
+ } ,
2686
+ [
2687
+ {
2688
+ name : 'test' ,
2689
+ prefix : '/' ,
2690
+ delimiter : '/' ,
2691
+ optional : false ,
2692
+ repeat : false ,
2693
+ pattern : 'abc'
2694
+ }
2695
+ ] ,
2696
+ [
2697
+ [ '/abc' , [ '/abc' , 'abc' ] ] ,
2698
+ [ '/ABC' , [ '/ABC' , 'ABC' ] ]
2699
+ ] ,
2700
+ [
2701
+ [ { test : 'abc' } , '/abc' ] ,
2702
+ [ { test : 'ABC' } , '/ABC' ]
2703
+ ]
2704
+ ] ,
2705
+
2654
2706
]
2655
2707
2656
2708
/**
You can’t perform that action at this time.
0 commit comments