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

Add TypeScript declarations #130

Merged
merged 1 commit into from
Jun 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions EventEmitter.d.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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