Skip to content

Commit fe645f9

Browse files
committed
Rename TokensToRegexpOptions
1 parent 9e1215a commit fe645f9

File tree

2 files changed

+37
-44
lines changed

2 files changed

+37
-44
lines changed

src/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as pathToRegexp from "./index";
33

44
type Test = [
55
pathToRegexp.Path,
6-
(pathToRegexp.RegexpOptions & pathToRegexp.ParseOptions) | undefined,
6+
(pathToRegexp.TokensToRegexpOptions & pathToRegexp.ParseOptions) | undefined,
77
pathToRegexp.Token[],
88
Array<
99
[

src/index.ts

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export type MatchFunction<P extends object = object> = (
318318
*/
319319
export function match<P extends object = object>(
320320
str: Path,
321-
options?: ParseOptions & RegexpOptions & RegexpToFunctionOptions
321+
options?: ParseOptions & TokensToRegexpOptions & RegexpToFunctionOptions
322322
) {
323323
const keys: Key[] = [];
324324
const re = pathToRegexp(str, keys, options);
@@ -423,7 +423,7 @@ function regexpToRegexp(path: RegExp, keys?: Key[]): RegExp {
423423
function arrayToRegexp(
424424
paths: Array<string | RegExp>,
425425
keys?: Key[],
426-
options?: RegexpOptions & ParseOptions
426+
options?: TokensToRegexpOptions & ParseOptions
427427
): RegExp {
428428
const parts = paths.map(path => pathToRegexp(path, keys, options).source);
429429
return new RegExp(`(?:${parts.join("|")})`, flags(options));
@@ -435,18 +435,49 @@ function arrayToRegexp(
435435
function stringToRegexp(
436436
path: string,
437437
keys?: Key[],
438-
options?: RegexpOptions & ParseOptions
438+
options?: TokensToRegexpOptions & ParseOptions
439439
) {
440440
return tokensToRegexp(parse(path, options), keys, options);
441441
}
442442

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+
443474
/**
444475
* Expose a function for taking tokens and returning a RegExp.
445476
*/
446477
export function tokensToRegexp(
447478
tokens: Token[],
448479
keys?: Key[],
449-
options: RegexpOptions = {}
480+
options: TokensToRegexpOptions = {}
450481
) {
451482
const {
452483
strict,
@@ -513,44 +544,6 @@ export function tokensToRegexp(
513544
return new RegExp(route, flags(options));
514545
}
515546

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-
554547
/**
555548
* Supported `path-to-regexp` input types.
556549
*/
@@ -566,7 +559,7 @@ export type Path = string | RegExp | Array<string | RegExp>;
566559
export function pathToRegexp(
567560
path: Path,
568561
keys?: Key[],
569-
options?: RegexpOptions & ParseOptions
562+
options?: TokensToRegexpOptions & ParseOptions
570563
) {
571564
if (path instanceof RegExp) {
572565
return regexpToRegexp(path, keys);

0 commit comments

Comments
 (0)