forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crossroads.d.ts
159 lines (127 loc) · 5.75 KB
/
crossroads.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Type definitions for Crossroads.js
// Project: http://millermedeiros.github.io/crossroads.js/
// Definitions by: Diullei Gomes <https://github.com/diullei>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../js-signals/js-signals.d.ts" />
declare module CrossroadsJs {
export interface Route {
matched: Signal;
/**
* Signal dispatched every time a request "leaves" the route.
*/
switched: Signal;
/**
* Object used to configure parameters/segments validation rules.
*/
rules: any;
/**
* If crossroads should try to match this Route even after matching another Route.
*/
greedy: boolean;
/**
* Remove route from crossroads and destroy it, releasing memory.
*/
dispose(): void;
/**
* Test if Route matches against request. Return true if request validate against route rules and pattern.
*/
match(request: any): boolean;
/**
* Return a string that matches the route replacing the capturing groups with the values provided in the replacements object.
*/
interpolate(replacements: any): string;
/**
* Add a listener to the signal.
*
* @param listener Signal handler function.
* @param listenercontext Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @param priority The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
*/
add(listener: Function, listenerContext?: any, priority?: Number): SignalBinding;
}
export interface CrossRoadsStatic {
NORM_AS_ARRAY: Function;
NORM_AS_OBJECT: Function;
/**
* Creates a new route pattern listener and add it to crossroads routes collection.
*
* @param pattern String pattern or Regular Expression that should be used to match against requests.
* @param handler Function that should be executed when a request matches the Route pattern.
* @param priority Route execution priority.
*/
addRoute(pattern: any, handler?: Function, priority?: number): Route;
/**
* Remove a single route from crossroads collection.
*
* @param route Reference to the Route object returned by crossroads.addRoute().
*/
removeRoute(route: Route): void;
/**
* Remove all routes from crossroads collection.
*/
removeAllRoutes(): void;
/**
* Parse a string input and dispatch matched Signal of the first Route that matches the request.
*
* @param request String that should be evaluated and matched against Routes to define which Route handlers should be executed and which parameters should be passed to the handlers.
* @param defaultargs Array containing values passed to matched/routed/bypassed signals as first arguments. Useful for node.js in case you need to access the request and response objects.
*/
parse(request: string, ...defaultArgs: any[]): void;
/**
* Get number of Routes contained on the crossroads collection.
*/
getNumRoutes(): number;
/**
* Signal dispatched every time that crossroads.parse can't find a Route that matches the request. Useful for debuging and error handling.
*/
bypassed: Signal;
/**
* Signal dispatched every time that crossroads.parse find a Route that matches the request. Useful for debuging and for executing tasks that should happen at each routing.
*/
routed: Signal;
/**
* Create a new independent Router instance.
*/
create(): CrossRoadsStatic;
/**
* Sets a default function that should be used to normalize parameters before passing them to the Route.matched, works similarly to Route.rules.normalize_.
*/
normalizeFn: Function;
/**
* Set if crossroads should typecast route paths. Default value is false (IMPORTANT: on v0.5.0 it was true by default).
*/
shouldTypecast: boolean;
/**
* String representation of the crossroads version number (e.g. "0.6.0").
*/
VERSION: string;
/**
* Sets global route matching behavior to greedy so crossroads will try to match every single route with the supplied request (if true it won't stop at first match).
*/
greedy: boolean;
/**
* Sets if the greedy routes feature is enabled. If false it won't try to match multiple routes (faster).
*/
greedyEnabled: boolean;
/**
* Resets the Router internal state. Will clear reference to previously matched routes (so they won't dispatch switched signal when matching a new route) and reset last request.
*/
resetState(): void;
/**
* Sets if Router should care about previous state, so multiple crossroads.parse() calls passing same argument would not trigger the routed, matched and bypassed signals.
*/
ignoreState: boolean;
/**
* Pipe routers, so all crossroads.parse() calls will be forwarded to the other router as well.
*/
pipe(router: CrossRoadsStatic): void;
/**
* "Ceci n'est pas une pipe"
*/
unpipe(router: CrossRoadsStatic): void;
}
}
declare var crossroads: CrossroadsJs.CrossRoadsStatic;
declare module 'crossroads'{
export = crossroads;
}