@@ -318,7 +318,7 @@ export type MatchFunction<P extends object = object> = (
318
318
*/
319
319
export function match < P extends object = object > (
320
320
str : Path ,
321
- options ?: ParseOptions & RegexpOptions & RegexpToFunctionOptions
321
+ options ?: ParseOptions & TokensToRegexpOptions & RegexpToFunctionOptions
322
322
) {
323
323
const keys : Key [ ] = [ ] ;
324
324
const re = pathToRegexp ( str , keys , options ) ;
@@ -423,7 +423,7 @@ function regexpToRegexp(path: RegExp, keys?: Key[]): RegExp {
423
423
function arrayToRegexp (
424
424
paths : Array < string | RegExp > ,
425
425
keys ?: Key [ ] ,
426
- options ?: RegexpOptions & ParseOptions
426
+ options ?: TokensToRegexpOptions & ParseOptions
427
427
) : RegExp {
428
428
const parts = paths . map ( path => pathToRegexp ( path , keys , options ) . source ) ;
429
429
return new RegExp ( `(?:${ parts . join ( "|" ) } )` , flags ( options ) ) ;
@@ -435,18 +435,49 @@ function arrayToRegexp(
435
435
function stringToRegexp (
436
436
path : string ,
437
437
keys ?: Key [ ] ,
438
- options ?: RegexpOptions & ParseOptions
438
+ options ?: TokensToRegexpOptions & ParseOptions
439
439
) {
440
440
return tokensToRegexp ( parse ( path , options ) , keys , options ) ;
441
441
}
442
442
443
+ export interface TokensToRegexpOptions {
444
+ /**
445
+ * When `true` the regexp will be case sensitive. (default: `false`)
446
+ */
447
+ sensitive ?: boolean ;
448
+ /**
449
+ * When `true` the regexp allows an optional trailing delimiter to match. (default: `false`)
450
+ */
451
+ strict ?: boolean ;
452
+ /**
453
+ * When `true` the regexp will match to the end of the string. (default: `true`)
454
+ */
455
+ end ?: boolean ;
456
+ /**
457
+ * When `true` the regexp will match from the beginning of the string. (default: `true`)
458
+ */
459
+ start ?: boolean ;
460
+ /**
461
+ * Sets the final character for non-ending optimistic matches. (default: `/`)
462
+ */
463
+ delimiter ?: string ;
464
+ /**
465
+ * List of characters that can also be "end" characters.
466
+ */
467
+ endsWith ?: string | string [ ] ;
468
+ /**
469
+ * Encode path tokens for use in the `RegExp`.
470
+ */
471
+ encode ?: ( value : string ) => string ;
472
+ }
473
+
443
474
/**
444
475
* Expose a function for taking tokens and returning a RegExp.
445
476
*/
446
477
export function tokensToRegexp (
447
478
tokens : Token [ ] ,
448
479
keys ?: Key [ ] ,
449
- options : RegexpOptions = { }
480
+ options : TokensToRegexpOptions = { }
450
481
) {
451
482
const {
452
483
strict,
@@ -513,44 +544,6 @@ export function tokensToRegexp(
513
544
return new RegExp ( route , flags ( options ) ) ;
514
545
}
515
546
516
- export interface RegexpOptions {
517
- /**
518
- * When `true` the regexp will be case sensitive. (default: `false`)
519
- */
520
- sensitive ?: boolean ;
521
- /**
522
- * When `true` the regexp allows an optional trailing delimiter to match. (default: `false`)
523
- */
524
- strict ?: boolean ;
525
- /**
526
- * When `true` the regexp will match to the end of the string. (default: `true`)
527
- */
528
- end ?: boolean ;
529
- /**
530
- * When `true` the regexp will match from the beginning of the string. (default: `true`)
531
- */
532
- start ?: boolean ;
533
- /**
534
- * Sets the final character for non-ending optimistic matches. (default: `/`)
535
- */
536
- delimiter ?: string ;
537
- /**
538
- * List of characters that can also be "end" characters.
539
- */
540
- endsWith ?: string | string [ ] ;
541
- /**
542
- * Encode path tokens for use in the `RegExp`.
543
- */
544
- encode ?: ( value : string ) => string ;
545
- }
546
-
547
- export interface ParseOptions {
548
- /**
549
- * Set the default delimiter for repeat parameters. (default: `'/'`)
550
- */
551
- delimiter ?: string ;
552
- }
553
-
554
547
/**
555
548
* Supported `path-to-regexp` input types.
556
549
*/
@@ -566,7 +559,7 @@ export type Path = string | RegExp | Array<string | RegExp>;
566
559
export function pathToRegexp (
567
560
path : Path ,
568
561
keys ?: Key [ ] ,
569
- options ?: RegexpOptions & ParseOptions
562
+ options ?: TokensToRegexpOptions & ParseOptions
570
563
) {
571
564
if ( path instanceof RegExp ) {
572
565
return regexpToRegexp ( path , keys ) ;
0 commit comments