export type ESMitterEventName = string | symbol; export interface ESMitterEvent { arguments: EventArguments; fn: (this: EventContext, ...args: EventArguments) => void; context: EventContext; } export interface ESMitterEvents { [key: ESMitterEventName]: ESMitterEvent; } export declare class ESMitter { private events; private eventsCount; constructor(); /** * Add a listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} context The context to invoke the listener with. * @param {Boolean} once Specify if the listener is a one-time listener. * @returns {EventEmitter} */ addListener(event: EventName, fn: Events[EventName]["fn"], context?: ESMitterEvents[EventName]["context"], once?: boolean): this; /** * Clear event by name. * * @param {(String|Symbol)} event The Event name. */ private clearEvent; /** * Return an array listing the events for which the emitter has registered * listeners. * * @returns {Array} */ eventNames(): ESMitterEventName[]; /** * Return the listeners registered for a given event. * * @param {(String|Symbol)} event The event name. * @returns {Array} The registered listeners. */ listeners(event: EventName): (() => unknown)[]; /** * Return the number of listeners listening to a given event. * * @param {(String|Symbol)} event The event name. * @returns {Number} The number of listeners. */ listenerCount(event: EventName): number; /** * Calls each of the listeners registered for a given event. * * @param {(String|Symbol)} event The event name. * @returns {Boolean} `true` if the event had listeners, else `false`. */ emit(event: EventName, ...args: Events[EventName]["arguments"]): boolean; /** * Add a listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} [context=this] The context to invoke the listener with. * @returns {EventEmitter} `this`. */ on(event: EventName, fn: Events[EventName]["fn"], context?: Events[EventName]["context"]): this; /** * Add a one-time listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} [context=this] The context to invoke the listener with. * @returns {EventEmitter} `this`. */ once(event: EventName, fn: Events[EventName]["fn"], context?: Events[EventName]["context"]): this; /** * Remove the listeners of a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn Only remove the listeners that match this function. * @param {*} context Only remove the listeners that have this context. * @param {Boolean} once Only remove one-time listeners. * @returns {EventEmitter} `this`. */ removeListener(event: EventName, fn?: Events[EventName]["fn"], context?: Events[EventName]["context"], once?: boolean): this; /** * Remove the listeners of a given event. Alias of removeListener(). * * @param {(String|Symbol)} event The event name. * @param {Function} fn Only remove the listeners that match this function. * @param {*} context Only remove the listeners that have this context. * @param {Boolean} once Only remove one-time listeners. * @returns {EventEmitter} `this`. */ off: (event: EventName, fn?: Events[EventName]["fn"], context?: Events[EventName]["context"], once?: boolean) => this; /** * Remove all listeners, or those of the specified event. * * @param {(String|Symbol)} [event] The event name. * @returns {EventEmitter} `this`. */ removeAllListeners(event?: EventName): this; }