|
| 1 | +interface ParseOptions { |
| 2 | + /** |
| 3 | + * Set the default delimiter for repeat parameters. (default: `'/'`) |
| 4 | + */ |
| 5 | + delimiter?: string; |
| 6 | + /** |
| 7 | + * List of characters to automatically consider prefixes when parsing. |
| 8 | + */ |
| 9 | + prefixes?: string; |
| 10 | +} |
| 11 | +interface RegexpToFunctionOptions { |
| 12 | + /** |
| 13 | + * Function for decoding strings for params. |
| 14 | + */ |
| 15 | + decode?: (value: string, token: Key) => string; |
| 16 | +} |
| 17 | +/** |
| 18 | + * A match result contains data about the path match. |
| 19 | + */ |
| 20 | +interface MatchResult<P extends object = object> { |
| 21 | + path: string; |
| 22 | + index: number; |
| 23 | + params: P; |
| 24 | +} |
| 25 | +/** |
| 26 | + * A match is either `false` (no match) or a match result. |
| 27 | + */ |
| 28 | +type Match<P extends object = object> = false | MatchResult<P>; |
| 29 | +/** |
| 30 | + * The match function takes a string and returns whether it matched the path. |
| 31 | + */ |
| 32 | +type MatchFunction<P extends object = object> = (path: string) => Match<P>; |
| 33 | +/** |
| 34 | + * Create path match function from `path-to-regexp` spec. |
| 35 | + */ |
| 36 | +declare function match<P extends object = object>( |
| 37 | + str: Path, |
| 38 | + options?: ParseOptions & TokensToRegexpOptions & RegexpToFunctionOptions, |
| 39 | +): MatchFunction<P>; |
| 40 | +/** |
| 41 | + * Metadata about a key. |
| 42 | + */ |
| 43 | +interface Key { |
| 44 | + name: string | number; |
| 45 | + prefix: string; |
| 46 | + suffix: string; |
| 47 | + pattern: string; |
| 48 | + modifier: string; |
| 49 | +} |
| 50 | +interface TokensToRegexpOptions { |
| 51 | + /** |
| 52 | + * When `true` the regexp will be case sensitive. (default: `false`) |
| 53 | + */ |
| 54 | + sensitive?: boolean; |
| 55 | + /** |
| 56 | + * When `true` the regexp won't allow an optional trailing delimiter to match. (default: `false`) |
| 57 | + */ |
| 58 | + strict?: boolean; |
| 59 | + /** |
| 60 | + * When `true` the regexp will match to the end of the string. (default: `true`) |
| 61 | + */ |
| 62 | + end?: boolean; |
| 63 | + /** |
| 64 | + * When `true` the regexp will match from the beginning of the string. (default: `true`) |
| 65 | + */ |
| 66 | + start?: boolean; |
| 67 | + /** |
| 68 | + * Sets the final character for non-ending optimistic matches. (default: `/`) |
| 69 | + */ |
| 70 | + delimiter?: string; |
| 71 | + /** |
| 72 | + * List of characters that can also be "end" characters. |
| 73 | + */ |
| 74 | + endsWith?: string; |
| 75 | + /** |
| 76 | + * Encode path tokens for use in the `RegExp`. |
| 77 | + */ |
| 78 | + encode?: (value: string) => string; |
| 79 | +} |
| 80 | +/** |
| 81 | + * Supported `path-to-regexp` input types. |
| 82 | + */ |
| 83 | +type Path = string | RegExp | Array<string | RegExp>; |
| 84 | +/** |
| 85 | + * Normalize the given path string, returning a regular expression. |
| 86 | + * |
| 87 | + * An empty array can be passed in for the keys, which will hold the |
| 88 | + * placeholder key descriptions. For example, using `/user/:id`, `keys` will |
| 89 | + * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`. |
| 90 | + */ |
| 91 | +declare function pathToRegexp(path: Path, keys?: Key[], options?: TokensToRegexpOptions & ParseOptions): RegExp; |
| 92 | + |
| 93 | +export { |
| 94 | + type Match, |
| 95 | + type MatchFunction, |
| 96 | + type ParseOptions, |
| 97 | + type Path, |
| 98 | + type RegexpToFunctionOptions, |
| 99 | + type TokensToRegexpOptions, |
| 100 | + match, |
| 101 | + pathToRegexp, |
| 102 | +}; |
0 commit comments