File tree 3 files changed +59
-0
lines changed 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -204,6 +204,10 @@ Path-To-RegExp breaks compatibility with Express <= `4.x`:
204
204
* Other RegExp features are not support - no nested matching groups, non-capturing groups or look aheads
205
205
* Parameters have suffixes that augment meaning - ` * ` , ` + ` and ` ? ` . E.g. ` /:user* `
206
206
207
+ ## TypeScript
208
+
209
+ Includes a [ ` .d.ts ` ] ( index.d.ts ) file for TypeScript users.
210
+
207
211
## Live Demo
208
212
209
213
You can see a live demo of this library in use at [ express-route-tester] ( http://forbeslindesay.github.com/express-route-tester/ ) .
Original file line number Diff line number Diff line change
1
+ declare function pathToRegexp ( path : pathToRegexp . Path , options ?: pathToRegexp . Options ) : pathToRegexp . PathRegExp ;
2
+ declare function pathToRegexp ( path : pathToRegexp . Path , keys : pathToRegexp . Token [ ] , options ?: pathToRegexp . Options ) : pathToRegexp . PathRegExp ;
3
+
4
+ declare namespace pathToRegexp {
5
+ export interface PathRegExp extends RegExp {
6
+ // An array to be populated with the keys found in the path.
7
+ keys : Key [ ] ;
8
+ }
9
+
10
+ export interface Options {
11
+ // When `true` the route will be case sensitive. (default: `false`)
12
+ sensitive : boolean ;
13
+ // When `false` the trailing slash is optional. (default: `false`)
14
+ strict : boolean ;
15
+ // When `false` the path will match at the beginning. (default: `true`)
16
+ end : boolean ;
17
+ }
18
+
19
+ /**
20
+ * Parse an Express-style path into an array of tokens.
21
+ */
22
+ export function parse ( path : string ) : Token [ ] ;
23
+
24
+ /**
25
+ * Transforming an Express-style path into a valid path.
26
+ */
27
+ export function compile ( path : string ) : PathFunction ;
28
+
29
+ /**
30
+ * Transform an array of tokens into a path generator function.
31
+ */
32
+ export function tokensToFunction ( tokens : Token [ ] ) : PathFunction ;
33
+
34
+ /**
35
+ * Transform an array of tokens into a matching regular expression.
36
+ */
37
+ export function tokensToRegExp ( tokens : Token [ ] , options ?: Options ) : PathRegExp ;
38
+
39
+ export interface Key {
40
+ name : string | number ;
41
+ prefix : string ;
42
+ delimiter : string ;
43
+ optional : boolean ;
44
+ repeat : boolean ;
45
+ pattern : string ;
46
+ }
47
+
48
+ export type Token = string | Key ;
49
+ export type Path = string | RegExp | Array < string | RegExp > ;
50
+ export type PathFunction = ( data ?: Object ) => string ;
51
+ }
52
+
53
+ export = pathToRegexp ;
Original file line number Diff line number Diff line change 2
2
"name" : " path-to-regexp" ,
3
3
"description" : " Express style path to RegExp utility" ,
4
4
"version" : " 1.2.1" ,
5
+ "main" : " index.js" ,
6
+ "typings" : " index.d.ts" ,
5
7
"files" : [
6
8
" index.js" ,
7
9
" LICENSE"
You can’t perform that action at this time.
0 commit comments