|
| 1 | +// Type definitions for EventEmitter2 v0.14.4 |
| 2 | +// Project: https://github.com/asyncly/EventEmitter2 |
| 3 | +// Definitions by: ryiwamoto <https://github.com/ryiwamoto/> |
| 4 | +// Definitions: https://github.com/borisyankov/DefinitelyTyped |
| 5 | + |
| 6 | +declare module eventemitter2 { |
| 7 | + interface Configuration { |
| 8 | + /** |
| 9 | + * use wildcards |
| 10 | + */ |
| 11 | + wildcard?: boolean; |
| 12 | + |
| 13 | + /** |
| 14 | + * the delimiter used to segment namespaces, defaults to `.`. |
| 15 | + */ |
| 16 | + delimiter?: string; |
| 17 | + |
| 18 | + /** |
| 19 | + * if you want to emit the newListener event set to true. |
| 20 | + */ |
| 21 | + newListener?: boolean; |
| 22 | + |
| 23 | + /** |
| 24 | + * max listeners that can be assigned to an event, default 10. |
| 25 | + */ |
| 26 | + maxListeners?: number; |
| 27 | + } |
| 28 | + |
| 29 | + export class EventEmitter2 { |
| 30 | + /** |
| 31 | + * @param conf |
| 32 | + */ |
| 33 | + constructor(conf?: Configuration); |
| 34 | + |
| 35 | + /** |
| 36 | + * Adds a listener to the end of the listeners array for the specified event. |
| 37 | + * @param event |
| 38 | + * @param listener |
| 39 | + */ |
| 40 | + addListener(event: string, listener: Function): EventEmitter2; |
| 41 | + |
| 42 | + /** |
| 43 | + * Adds a listener to the end of the listeners array for the specified event. |
| 44 | + * @param event |
| 45 | + * @param listener |
| 46 | + */ |
| 47 | + on(event: string, listener: Function): EventEmitter2; |
| 48 | + |
| 49 | + /** |
| 50 | + * Adds a listener that will be fired when any event is emitted. |
| 51 | + * @param listener |
| 52 | + */ |
| 53 | + onAny(listener: Function): EventEmitter2; |
| 54 | + |
| 55 | + /** |
| 56 | + * Removes the listener that will be fired when any event is emitted. |
| 57 | + * @param listener |
| 58 | + */ |
| 59 | + offAny(listener: Function): EventEmitter2; |
| 60 | + |
| 61 | + /** |
| 62 | + * Adds a one time listener for the event. |
| 63 | + * The listener is invoked only the first time the event is fired, after which it is removed. |
| 64 | + * @param event |
| 65 | + * @param listener |
| 66 | + */ |
| 67 | + once(event: string, listener: Function): EventEmitter2; |
| 68 | + |
| 69 | + /** |
| 70 | + * Adds a listener that will execute n times for the event before being removed. |
| 71 | + * The listener is invoked only the first n times the event is fired, after which it is removed. |
| 72 | + * @param event |
| 73 | + * @param timesToListen |
| 74 | + * @param listener |
| 75 | + */ |
| 76 | + many(event: string, timesToListen: number, listener: Function): EventEmitter2; |
| 77 | + |
| 78 | + /** |
| 79 | + * Remove a listener from the listener array for the specified event. |
| 80 | + * Caution: changes array indices in the listener array behind the listener. |
| 81 | + * @param event |
| 82 | + * @param listener |
| 83 | + */ |
| 84 | + removeListener(event: string, listener: Function): EventEmitter2; |
| 85 | + |
| 86 | + /** |
| 87 | + * Remove a listener from the listener array for the specified event. |
| 88 | + * Caution: changes array indices in the listener array behind the listener. |
| 89 | + * @param event |
| 90 | + * @param listener |
| 91 | + */ |
| 92 | + off(event: string, listener: Function): EventEmitter2; |
| 93 | + |
| 94 | + /** |
| 95 | + * Removes all listeners, or those of the specified event. |
| 96 | + * @param event |
| 97 | + */ |
| 98 | + removeAllListeners(event?: string): EventEmitter2; |
| 99 | + |
| 100 | + /** |
| 101 | + * Removes all listeners, or those of the specified event. |
| 102 | + * @param events |
| 103 | + */ |
| 104 | + removeAllListeners(events: string[]): EventEmitter2; |
| 105 | + |
| 106 | + /** |
| 107 | + * By default EventEmitters will print a warning if more than 10 listeners are added to it. |
| 108 | + * This is a useful default which helps finding memory leaks. |
| 109 | + * Obviously not all Emitters should be limited to 10. This function allows that to be increased. |
| 110 | + * Set to zero for unlimited. |
| 111 | + * @param n |
| 112 | + */ |
| 113 | + setMaxListeners(n: number): void; |
| 114 | + |
| 115 | + /** |
| 116 | + * Returns an array of listeners for the specified event. This array can be manipulated, e.g. to remove listeners. |
| 117 | + * @param event |
| 118 | + */ |
| 119 | + listeners(event: string): Function[]; |
| 120 | + |
| 121 | + /** |
| 122 | + * Returns an array of listeners that are listening for any event that is specified. |
| 123 | + * This array can be manipulated, e.g. to remove listeners. |
| 124 | + */ |
| 125 | + listenersAny(): Function[]; |
| 126 | + |
| 127 | + /** |
| 128 | + * Execute each of the listeners that may be listening for the specified event name in order with the list of arguments. |
| 129 | + * @param event |
| 130 | + * @param args |
| 131 | + */ |
| 132 | + emit(event: string, ...args: string[]): boolean; |
| 133 | + |
| 134 | + /** |
| 135 | + * Execute each of the listeners that may be listening for the specified event name in order with the list of arguments. |
| 136 | + * @param event |
| 137 | + */ |
| 138 | + emit(event: string[]): boolean; |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +declare module "eventemitter2" { |
| 143 | + export = eventemitter2; |
| 144 | +} |
| 145 | + |
| 146 | +declare var EventEmitter2: typeof eventemitter2.EventEmitter2; |
0 commit comments