Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
Add TypeScript declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Danford committed Jun 23, 2017
1 parent eda19e8 commit dec38a0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions EventEmitter.d.ts
@@ -0,0 +1,41 @@
type EventKey = string|RegExp;

interface EventMap {
[evt: string]: EventKey;
}

type Events = EventKey|EventMap;

interface Listener {
listener: Function;
once: boolean;
}

interface ListenerMap {
[evt: string]: Listener[];
}

type Listeners = Listener[]|ListenerMap;

declare class EventEmitter {
getListeners(evt: EventKey): Listeners;
flattenListeners(listeners: Listener[]): void;
getListenersAsObject(evt: EventKey): ListenerMap;
addListener(evt: EventKey, listener: Listener|Function): this;
on(evt: EventKey, listener: Listener|Function): this;
addOnceListener(evt: EventKey, listener: Function): this;
once(evt: EventKey, listener: Function): this;
defineEvent(evt: EventKey): this;
defineEvents(evts: EventKey[]): this;
removeListener(evt: EventKey, listener: Function): this;
off(evt: EventKey, listener: Function): this;
addListeners(evt: Events, listeners: Function[]): this;
removeListeners(evt: Events, listeners: Function[]): this;
manipulateListeners(remove: boolean, evt: Events, listeners: Function[]): this;
removeEvent(evt: EventKey): this;
removeAllListeners(evt: EventKey): this;
emitEvent(evt: EventKey, args?: any[]): this;
trigger(evt: EventKey, args?: any[]): this;
emit(evt: EventKey): this;
setOnceReturnValue(value: any): this;
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -3,6 +3,7 @@
"version": "5.1.0",
"description": "Event based JavaScript for the browser",
"main": "EventEmitter.js",
"types": "EventEmitter.d.ts",
"directories": {
"doc": "docs",
"test": "tests"
Expand Down

0 comments on commit dec38a0

Please sign in to comment.