forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventemitter2.d.ts
253 lines (216 loc) · 7.96 KB
/
eventemitter2.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// Type definitions for EventEmitter2 v0.14.4
// Project: https://github.com/asyncly/EventEmitter2
// Definitions by: ryiwamoto <https://github.com/ryiwamoto/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface EventEmitter2Configuration {
/**
* use wildcards
*/
wildcard?: boolean;
/**
* the delimiter used to segment namespaces, defaults to `.`.
*/
delimiter?: string;
/**
* if you want to emit the newListener event set to true.
*/
newListener?: boolean;
/**
* max listeners that can be assigned to an event, default 10.
*/
maxListeners?: number;
}
declare class EventEmitter2 {
/**
* @param conf
*/
constructor(conf?: EventEmitter2Configuration);
/**
* Adds a listener to the end of the listeners array for the specified event.
* @param event
* @param listener
*/
addListener(event: string, listener: Function): EventEmitter2;
/**
* Adds a listener to the end of the listeners array for the specified event.
* @param event
* @param listener
*/
on(event: string, listener: Function): EventEmitter2;
/**
* Adds a listener that will be fired when any event is emitted.
* @param listener
*/
onAny(listener: Function): EventEmitter2;
/**
* Removes the listener that will be fired when any event is emitted.
* @param listener
*/
offAny(listener?: Function): EventEmitter2;
/**
* Adds a one time listener for the event.
* The listener is invoked only the first time the event is fired, after which it is removed.
* @param event
* @param listener
*/
once(event: string, listener: Function): EventEmitter2;
/**
* Adds a listener that will execute n times for the event before being removed.
* The listener is invoked only the first n times the event is fired, after which it is removed.
* @param event
* @param timesToListen
* @param listener
*/
many(event: string, timesToListen: number, listener: Function): EventEmitter2;
/**
* Remove a listener from the listener array for the specified event.
* Caution: changes array indices in the listener array behind the listener.
* @param event
* @param listener
*/
removeListener(event: string, listener: Function): EventEmitter2;
/**
* Remove a listener from the listener array for the specified event.
* Caution: changes array indices in the listener array behind the listener.
* @param event
* @param listener
*/
off(event: string, listener: Function): EventEmitter2;
/**
* Removes all listeners, or those of the specified event.
* @param event
*/
removeAllListeners(event?: string): EventEmitter2;
/**
* Removes all listeners, or those of the specified event.
* @param events
*/
removeAllListeners(events: string[]): EventEmitter2;
/**
* By default EventEmitters will print a warning if more than 10 listeners are added to it.
* This is a useful default which helps finding memory leaks.
* Obviously not all Emitters should be limited to 10. This function allows that to be increased.
* Set to zero for unlimited.
* @param n
*/
setMaxListeners(n: number): void;
/**
* Returns an array of listeners for the specified event. This array can be manipulated, e.g. to remove listeners.
* @param event
*/
listeners(event: string): Function[];
/**
* Returns an array of listeners that are listening for any event that is specified.
* This array can be manipulated, e.g. to remove listeners.
*/
listenersAny(): Function[];
/**
* Execute each of the listeners that may be listening for the specified event name in order with the list of arguments.
* @param event
* @param args
*/
emit(event: string, ...args: any[]): boolean;
/**
* Execute each of the listeners that may be listening for the specified event name in order with the list of arguments.
* @param event
*/
emit(event: string[]): boolean;
}
declare module "eventemitter2" {
export class EventEmitter2 {
/**
* @param conf
*/
constructor(conf?: EventEmitter2Configuration);
/**
* Adds a listener to the end of the listeners array for the specified event.
* @param event
* @param listener
*/
addListener(event: string, listener: Function): EventEmitter2;
/**
* Adds a listener to the end of the listeners array for the specified event.
* @param event
* @param listener
*/
on(event: string, listener: Function): EventEmitter2;
/**
* Adds a listener that will be fired when any event is emitted.
* @param listener
*/
onAny(listener: Function): EventEmitter2;
/**
* Removes the listener that will be fired when any event is emitted.
* @param listener
*/
offAny(listener: Function): EventEmitter2;
/**
* Adds a one time listener for the event.
* The listener is invoked only the first time the event is fired, after which it is removed.
* @param event
* @param listener
*/
once(event: string, listener: Function): EventEmitter2;
/**
* Adds a listener that will execute n times for the event before being removed.
* The listener is invoked only the first n times the event is fired, after which it is removed.
* @param event
* @param timesToListen
* @param listener
*/
many(event: string, timesToListen: number, listener: Function): EventEmitter2;
/**
* Remove a listener from the listener array for the specified event.
* Caution: changes array indices in the listener array behind the listener.
* @param event
* @param listener
*/
removeListener(event: string, listener: Function): EventEmitter2;
/**
* Remove a listener from the listener array for the specified event.
* Caution: changes array indices in the listener array behind the listener.
* @param event
* @param listener
*/
off(event: string, listener: Function): EventEmitter2;
/**
* Removes all listeners, or those of the specified event.
* @param event
*/
removeAllListeners(event?: string): EventEmitter2;
/**
* Removes all listeners, or those of the specified event.
* @param events
*/
removeAllListeners(events: string[]): EventEmitter2;
/**
* By default EventEmitters will print a warning if more than 10 listeners are added to it.
* This is a useful default which helps finding memory leaks.
* Obviously not all Emitters should be limited to 10. This function allows that to be increased.
* Set to zero for unlimited.
* @param n
*/
setMaxListeners(n: number): void;
/**
* Returns an array of listeners for the specified event. This array can be manipulated, e.g. to remove listeners.
* @param event
*/
listeners(event: string): Function[];
/**
* Returns an array of listeners that are listening for any event that is specified.
* This array can be manipulated, e.g. to remove listeners.
*/
listenersAny(): Function[];
/**
* Execute each of the listeners that may be listening for the specified event name in order with the list of arguments.
* @param event
* @param args
*/
emit(event: string, ...args: any[]): boolean;
/**
* Execute each of the listeners that may be listening for the specified event name in order with the list of arguments.
* @param event
*/
emit(event: string[]): boolean;
}
}