index.d.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. declare function pathToRegexp (path: pathToRegexp.Path, keys?: pathToRegexp.Key[], options?: pathToRegexp.RegExpOptions & pathToRegexp.ParseOptions): RegExp;
  2. declare namespace pathToRegexp {
  3. export interface RegExpOptions {
  4. /**
  5. * When `true` the regexp will be case sensitive. (default: `false`)
  6. */
  7. sensitive?: boolean;
  8. /**
  9. * When `true` the regexp allows an optional trailing delimiter to match. (default: `false`)
  10. */
  11. strict?: boolean;
  12. /**
  13. * When `true` the regexp will match to the end of the string. (default: `true`)
  14. */
  15. end?: boolean;
  16. /**
  17. * When `true` the regexp will match from the beginning of the string. (default: `true`)
  18. */
  19. start?: boolean;
  20. /**
  21. * Sets the final character for non-ending optimistic matches. (default: `/`)
  22. */
  23. delimiter?: string;
  24. /**
  25. * List of characters that can also be "end" characters.
  26. */
  27. endsWith?: string | string[];
  28. }
  29. export interface ParseOptions {
  30. /**
  31. * Set the default delimiter for repeat parameters. (default: `'/'`)
  32. */
  33. delimiter?: string;
  34. /**
  35. * List of valid delimiter characters. (default: `'./'`)
  36. */
  37. delimiters?: string | string[];
  38. }
  39. /**
  40. * Parse an Express-style path into an array of tokens.
  41. */
  42. export function parse (path: string, options?: ParseOptions): Token[];
  43. /**
  44. * Transforming an Express-style path into a valid path.
  45. */
  46. export function compile (path: string, options?: ParseOptions): PathFunction;
  47. /**
  48. * Transform an array of tokens into a path generator function.
  49. */
  50. export function tokensToFunction (tokens: Token[]): PathFunction;
  51. /**
  52. * Transform an array of tokens into a matching regular expression.
  53. */
  54. export function tokensToRegExp (tokens: Token[], keys?: Key[], options?: RegExpOptions): RegExp;
  55. export interface Key {
  56. name: string | number;
  57. prefix: string;
  58. delimiter: string;
  59. optional: boolean;
  60. repeat: boolean;
  61. pattern: string;
  62. partial: boolean;
  63. }
  64. interface PathFunctionOptions {
  65. /**
  66. * Function for encoding input strings for output.
  67. */
  68. encode?: (value: string, token: Key) => string;
  69. }
  70. export type Token = string | Key;
  71. export type Path = string | RegExp | Array<string | RegExp>;
  72. export type PathFunction = (data?: Object, options?: PathFunctionOptions) => string;
  73. }
  74. export = pathToRegexp;