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 {
3939 delimiter ?: string ;
4040 }
4141
42+ export interface TokensToFunctionOptions {
43+ /**
44+ * When `true` the regexp will be case sensitive. (default: `false`)
45+ */
46+ sensitive ?: boolean ;
47+ }
48+
4249 /**
4350 * Parse an Express-style path into an array of tokens.
4451 */
@@ -47,12 +54,12 @@ declare namespace pathToRegexp {
4754 /**
4855 * Transforming an Express-style path into a valid path.
4956 */
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 > ;
5158
5259 /**
5360 * Transform an array of tokens into a path generator function.
5461 */
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 > ;
5663
5764 /**
5865 * 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) {
117117 * @return {!function(Object=, Object=) }
118118 */
119119function compile ( str , options ) {
120- return tokensToFunction ( parse ( str , options ) )
120+ return tokensToFunction ( parse ( str , options ) , options )
121121}
122122
123123/**
124124 * Expose a method for transforming tokens into the path function.
125125 */
126- function tokensToFunction ( tokens ) {
126+ function tokensToFunction ( tokens , options ) {
127127 // Compile all the tokens into regexps.
128128 var matches = new Array ( tokens . length )
129129
130130 // Compile all the patterns before compilation.
131131 for ( var i = 0 ; i < tokens . length ; i ++ ) {
132132 if ( typeof tokens [ i ] === 'object' ) {
133- matches [ i ] = new RegExp ( '^(?:' + tokens [ i ] . pattern + ')$' )
133+ matches [ i ] = new RegExp ( '^(?:' + tokens [ i ] . pattern + ')$' , flags ( options ) )
134134 }
135135 }
136136
Original file line number Diff line number Diff line change @@ -2651,6 +2651,58 @@ var TESTS: Test[] = [
26512651 [ { attr2 : 'attr' } , 'name-attr' ]
26522652 ]
26532653 ] ,
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+
26542706]
26552707
26562708/**
You can’t perform that action at this time.
0 commit comments