Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

events-ex

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

events-ex - npm Package Compare versions

Comparing version 2.0.0-alpha.1 to 2.0.0-alpha.2

docs/classes/event_emitter-1.EventEmitter.md

16

CHANGELOG.md

@@ -5,2 +5,18 @@ # Changelog

## [2.0.0-alpha.2](https://github.com/snowyu/events-ex.js/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2023-06-13)
### ⚠ BREAKING CHANGES
* rename src/event-emitter to src/wrap-event-emitter and extract EventEmitter from index to event-emitter
### Bug Fixes
* **ts:** EventEmitter not found ([9a74862](https://github.com/snowyu/events-ex.js/commit/9a748624e00417f6d7f72ea7c297650e10895d19))
### Refactor
* rename src/event-emitter to src/wrap-event-emitter and extract EventEmitter from index to event-emitter ([f06f39f](https://github.com/snowyu/events-ex.js/commit/f06f39fb809006f5e098e31bb23870fff39ec5c8))
## [2.0.0-alpha.1](https://github.com/snowyu/events-ex.js/compare/v2.0.0-alpha.0...v2.0.0-alpha.1) (2023-06-13)

@@ -7,0 +23,0 @@

16

docs/classes/event.Event.md

@@ -40,7 +40,7 @@ [events-ex](../README.md) / [Exports](../modules.md) / [event](../modules/event.md) / Event

| :------ | :------ | :------ |
| `target` | `EventEmitter` | Who trigger the event |
| `target` | [`EventEmitter`](event_emitter.EventEmitter.md) | Who trigger the event |
#### Defined in
[src/event.js:8](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event.js#L8)
[src/event.js:8](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/event.js#L8)

@@ -57,3 +57,3 @@ ## Properties

[src/event.js:38](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event.js#L38)
[src/event.js:38](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/event.js#L38)

@@ -70,3 +70,3 @@ ___

[src/event.js:32](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event.js#L32)
[src/event.js:32](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/event.js#L32)

@@ -83,3 +83,3 @@ ___

[src/event.js:26](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event.js#L26)
[src/event.js:26](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/event.js#L26)

@@ -102,3 +102,3 @@ ## Methods

[src/event.js:45](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event.js#L45)
[src/event.js:45](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/event.js#L45)

@@ -117,3 +117,3 @@ ___

| :------ | :------ | :------ |
| `target` | `EventEmitter` | The target object for the event. |
| `target` | [`EventEmitter`](event_emitter.EventEmitter.md) | The target object for the event. |

@@ -126,2 +126,2 @@ #### Returns

[src/event.js:20](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event.js#L20)
[src/event.js:20](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/event.js#L20)

@@ -14,6 +14,6 @@ [events-ex](README.md) / Exports

- [event-emitter](modules/event_emitter.md)
- [event-emitter](modules/event_emitter-1.md)
- [eventable](modules/eventable.md)
- [has-listeners](modules/has_listeners.md)
- [index](modules/index.md)
- [index](modules/index-1.md)
- [pipe](modules/pipe.md)

@@ -28,1 +28,2 @@ - [pipe-async](modules/pipe_async.md)

- [util/valid-object](modules/util_valid_object.md)
- [wrap-event-emitter](modules/wrap_event_emitter.md)

@@ -25,3 +25,3 @@ [events-ex](../README.md) / [Exports](../modules.md) / all-off

▸ **allOff**(`emitter`, `type?`): `EventEmitter`
▸ **allOff**(`emitter`, `type?`): [`EventEmitter`](../classes/event_emitter.EventEmitter.md)

@@ -34,3 +34,3 @@ Removes all listeners for a specific event or all events from an event emitter.

| :------ | :------ | :------ |
| `emitter` | `EventEmitter` | The event emitter to remove listeners from. |
| `emitter` | [`EventEmitter`](../classes/event_emitter.EventEmitter.md) | The event emitter to remove listeners from. |
| `type?` | `string` | The event to remove listeners for. If not provided, all listeners for all events will be removed. |

@@ -40,3 +40,3 @@

`EventEmitter`
[`EventEmitter`](../classes/event_emitter.EventEmitter.md)

@@ -47,2 +47,2 @@ - The event emitter with all listeners removed.

[src/all-off.js:12](https://github.com/snowyu/events-ex.js/blob/892d26d/src/all-off.js#L12)
[src/all-off.js:12](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/all-off.js#L12)

@@ -27,2 +27,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / consts

[src/consts.js:5](https://github.com/snowyu/events-ex.js/blob/892d26d/src/consts.js#L5)
[src/consts.js:5](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/consts.js#L5)

@@ -43,10 +43,10 @@ [events-ex](../README.md) / [Exports](../modules.md) / default-methods

| `listeners` | (`type`: `any`) => `any` |
| `off` | (`type`: `string`, `listener`: `Function`) => `EventEmitter` |
| `on` | (`type`: `string`, `listener`: `Function`) => `EventEmitter` |
| `once` | (`type`: `string`, `listener`: `Function`) => `EventEmitter` |
| `removeAllListeners` | (`type`: `string`) => `EventEmitter` |
| `setMaxListeners` | (`n`: `any`) => { on(type: string, listener: Function): EventEmitter; once(type: string, listener: Function): EventEmitter; emit(...args: any[]): any; emitAsync(...args: any[]): Promise<any\>; ... 4 more ...; removeAllListeners(type: string): EventEmitter; } |
| `off` | (`type`: `string`, `listener`: `Function`) => [`EventEmitter`](../classes/event_emitter.EventEmitter.md) |
| `on` | (`type`: `string`, `listener`: `Function`) => [`EventEmitter`](../classes/event_emitter.EventEmitter.md) |
| `once` | (`type`: `string`, `listener`: `Function`) => [`EventEmitter`](../classes/event_emitter.EventEmitter.md) |
| `removeAllListeners` | (`type`: `string`) => [`EventEmitter`](../classes/event_emitter.EventEmitter.md) |
| `setMaxListeners` | (`n`: `any`) => { on(type: string, listener: Function): EventEmitter; once(type: string, listener: Function): EventEmitter; emit(...args: any[]): any; ... 5 more ...; removeAllListeners(type: string): EventEmitter; } |
#### Defined in
[src/default-methods.js:8](https://github.com/snowyu/events-ex.js/blob/892d26d/src/default-methods.js#L8)
[src/default-methods.js:8](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/default-methods.js#L8)

@@ -11,10 +11,6 @@ [events-ex](../README.md) / [Exports](../modules.md) / event-emitter

### Variables
### Classes
- [methods](event_emitter.md#methods)
- [EventEmitter](../classes/event_emitter.EventEmitter.md)
### Functions
- [wrapEventEmitter](event_emitter.md#wrapeventemitter)
## References

@@ -24,36 +20,2 @@

Renames and re-exports [wrapEventEmitter](event_emitter.md#wrapeventemitter)
## Variables
### methods
• `Const` **methods**: `any`
#### Defined in
[src/event-emitter.js:6](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event-emitter.js#L6)
## Functions
### wrapEventEmitter
▸ **wrapEventEmitter**(`o?`): `any`
Create or inject the eventable instance into the object
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `o?` | `any` | the optional instance to eventable |
#### Returns
`any`
o or new Event instance
#### Defined in
[src/event-emitter.js:33](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event-emitter.js#L33)
Renames and re-exports [EventEmitter](../classes/event_emitter.EventEmitter.md)

@@ -40,2 +40,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / has-listeners

[src/has-listeners.js:10](https://github.com/snowyu/events-ex.js/blob/892d26d/src/has-listeners.js#L10)
[src/has-listeners.js:10](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/has-listeners.js#L10)

@@ -9,2 +9,4 @@ [events-ex](../README.md) / [Exports](../modules.md) / index

- [Event](index.md#event)
- [EventEmitter](index.md#eventemitter)
- [allOff](index.md#alloff)

@@ -21,8 +23,16 @@ - [default](index.md#default)

### Classes
## References
- [EventEmitter](../classes/index.EventEmitter.md)
### Event
## References
Re-exports [Event](../classes/event.Event.md)
___
### EventEmitter
Re-exports [EventEmitter](../classes/event_emitter.EventEmitter.md)
___
### allOff

@@ -36,3 +46,3 @@

Renames and re-exports [EventEmitter](../classes/index.EventEmitter.md)
Renames and re-exports [EventEmitter](../classes/event_emitter.EventEmitter.md)

@@ -55,3 +65,3 @@ ___

Re-exports [methods](event_emitter.md#methods)
Re-exports [methods](wrap_event_emitter.md#methods)

@@ -86,2 +96,2 @@ ___

Re-exports [wrapEventEmitter](event_emitter.md#wrapeventemitter)
Re-exports [wrapEventEmitter](wrap_event_emitter.md#wrapeventemitter)

@@ -37,4 +37,4 @@ [events-ex](../README.md) / [Exports](../modules.md) / pipe-async

| :------ | :------ | :------ |
| `e1` | `EventEmitter` | The first event emitter. |
| `e2` | `EventEmitter` | The second event emitter. |
| `e1` | [`EventEmitter`](../classes/event_emitter.EventEmitter.md) | The first event emitter. |
| `e2` | [`EventEmitter`](../classes/event_emitter.EventEmitter.md) | The second event emitter. |
| `...args` | `any` | - |

@@ -50,2 +50,2 @@

[src/pipe-async.js:21](https://github.com/snowyu/events-ex.js/blob/892d26d/src/pipe-async.js#L21)
[src/pipe-async.js:21](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/pipe-async.js#L21)

@@ -37,4 +37,4 @@ [events-ex](../README.md) / [Exports](../modules.md) / pipe

| :------ | :------ | :------ |
| `e1` | `EventEmitter` | The first event emitter. |
| `e2` | `EventEmitter` | The second event emitter. |
| `e1` | [`EventEmitter`](../classes/event_emitter.EventEmitter.md) | The first event emitter. |
| `e2` | [`EventEmitter`](../classes/event_emitter.EventEmitter.md) | The second event emitter. |
| `...args` | `any` | - |

@@ -50,2 +50,2 @@

[src/pipe.js:21](https://github.com/snowyu/events-ex.js/blob/892d26d/src/pipe.js#L21)
[src/pipe.js:21](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/pipe.js#L21)

@@ -37,4 +37,4 @@ [events-ex](../README.md) / [Exports](../modules.md) / unify

| :------ | :------ | :------ |
| `e1` | `EventEmitter` | The first event emitter object. |
| `e2` | `EventEmitter` | The second event emitter object. |
| `e1` | [`EventEmitter`](../classes/event_emitter.EventEmitter.md) | The first event emitter object. |
| `e2` | [`EventEmitter`](../classes/event_emitter.EventEmitter.md) | The second event emitter object. |

@@ -47,2 +47,2 @@ #### Returns

[src/unify.js:17](https://github.com/snowyu/events-ex.js/blob/892d26d/src/unify.js#L17)
[src/unify.js:17](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/unify.js#L17)

@@ -39,2 +39,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / util/array-remove

[src/util/array-remove.js:5](https://github.com/snowyu/events-ex.js/blob/892d26d/src/util/array-remove.js#L5)
[src/util/array-remove.js:5](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/util/array-remove.js#L5)

@@ -41,2 +41,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / util/object-for-each

[src/util/object-for-each.js:6](https://github.com/snowyu/events-ex.js/blob/892d26d/src/util/object-for-each.js#L6)
[src/util/object-for-each.js:6](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/util/object-for-each.js#L6)

@@ -40,2 +40,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / util/string-pad

[src/util/string-pad.js:8](https://github.com/snowyu/events-ex.js/blob/892d26d/src/util/string-pad.js#L8)
[src/util/string-pad.js:8](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/util/string-pad.js#L8)

@@ -39,2 +39,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / util/to-int

[src/util/to-int.js:2](https://github.com/snowyu/events-ex.js/blob/892d26d/src/util/to-int.js#L2)
[src/util/to-int.js:2](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/util/to-int.js#L2)

@@ -39,2 +39,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / util/valid-callable

[src/util/valid-callable.js:1](https://github.com/snowyu/events-ex.js/blob/892d26d/src/util/valid-callable.js#L1)
[src/util/valid-callable.js:1](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/util/valid-callable.js#L1)

@@ -39,2 +39,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / util/valid-object

[src/util/valid-object.js:3](https://github.com/snowyu/events-ex.js/blob/892d26d/src/util/valid-object.js#L3)
[src/util/valid-object.js:3](https://github.com/snowyu/events-ex.js/blob/25f69f3/src/util/valid-object.js#L3)
/**
* Removes all listeners for a specific event or all events from an event emitter.
*
* @param {EventEmitter} emitter - The event emitter to remove listeners from.
* @param {import('./event-emitter').EventEmitter} emitter - The event emitter to remove listeners from.
* @param {string} [type] - The event to remove listeners for. If not provided, all listeners for all events will be removed.
* @returns {EventEmitter} - The event emitter with all listeners removed.
* @returns {import('./event-emitter').EventEmitter} - The event emitter with all listeners removed.
*/
export function allOff(emitter: EventEmitter, type?: string): EventEmitter;
export function allOff(emitter: import('./event-emitter').EventEmitter, type?: string): import('./event-emitter').EventEmitter;
export default allOff;

@@ -15,5 +15,5 @@ "use strict";

*
* @param {EventEmitter} emitter - The event emitter to remove listeners from.
* @param {import('./event-emitter').EventEmitter} emitter - The event emitter to remove listeners from.
* @param {string} [type] - The event to remove listeners for. If not provided, all listeners for all events will be removed.
* @returns {EventEmitter} - The event emitter with all listeners removed.
* @returns {import('./event-emitter').EventEmitter} - The event emitter with all listeners removed.
*/

@@ -20,0 +20,0 @@ function allOff(emitter, type) {

@@ -6,6 +6,6 @@ export function getEventableMethods(aClass: any): {

* @param {Function} listener - The listener function to be called when the event is emitted.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.
*/
on(type: string, listener: Function): EventEmitter;
on(type: string, listener: Function): import('./event-emitter').EventEmitter;
/**

@@ -15,6 +15,6 @@ * Adds a one-time listener function to the specified event type.

* @param {Function} listener - The listener function to be called once when the event is emitted.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.
*/
once(type: string, listener: Function): EventEmitter;
once(type: string, listener: Function): import('./event-emitter').EventEmitter;
/**

@@ -39,14 +39,14 @@ * Emits the specified event type with the given arguments.

* @param {Function} listener - The listener function to be removed.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.
*/
off(type: string, listener: Function): EventEmitter;
off(type: string, listener: Function): import('./event-emitter').EventEmitter;
/**
* Removes all listener functions from the specified event type.
* @param {string} type - The event type to remove the listener from.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.
*/
removeAllListeners(type: string): EventEmitter;
removeAllListeners(type: string): import('./event-emitter').EventEmitter;
};
export default getEventableMethods;

@@ -19,3 +19,3 @@ "use strict";

* @param {Function} listener - The listener function to be called when the event is emitted.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.

@@ -65,3 +65,3 @@ */

* @param {Function} listener - The listener function to be called once when the event is emitted.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.

@@ -182,3 +182,3 @@ */

* @param {Function} listener - The listener function to be removed.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.

@@ -232,3 +232,3 @@ */

* @param {string} type - The event type to remove the listener from.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.

@@ -235,0 +235,0 @@ */

@@ -0,8 +1,70 @@

type ListenerCallbackFunc = Function;
/**
* Create or inject the eventable instance into the object
* @param {Object} [o] the optional instance to eventable
* @returns o or new Event instance
* Class that represents an event emitter.
*/
export function wrapEventEmitter(o?: any): any;
export const methods: any;
export default wrapEventEmitter;
export class EventEmitter {
static defaultMaxListeners: number;
/**
* Adds a listener function to the specified event type.
* @param {string} type - The event type to listen for.
* @param {Function} listener - The listener function to be called when the event is emitted.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.
*/
on(eventName: string, listener: ListenerCallbackFunc): EventEmitter;
/**
* Adds a one-time listener function to the specified event type.
* @param {string} type - The event type to listen for.
* @param {Function} listener - The listener function to be called once when the event is emitted.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.
*/
once(eventName: string, listener: ListenerCallbackFunc): EventEmitter;
/**
* Removes a listener function from the specified event type.
* @param {string} type - The event type to remove the listener from.
* @param {Function} listener - The listener function to be removed.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.
*/
off(eventName: string, listener: ListenerCallbackFunc): EventEmitter;
/**
* Emits the specified event type with the given arguments.
* @param {...*} args - The event type followed by any number of arguments to be passed to the listener functions.
* @returns {*} The result of the event.
*/
emit(eventName: string, ...args: any[]): any;
/**
* Asynchronously emits the specified event type with the given arguments.
* @param {...*} args - The event type followed by any number of arguments to be passed to the listener functions.
* @returns {Promise<*>} A promise that resolves with the result of the event.
*/
emitAsync(eventName: string, ...args: any[]): Promise<any>;
/**
* Removes all listeners for a specific event or all events from an event emitter.
*
* @param {string} [eventName] - The event to remove listeners for. If not provided, all listeners for all events will be removed.
* @returns {EventEmitter} - The event emitter with all listeners removed.
*/
removeAllListeners(eventName?: string): EventEmitter;
setMaxListeners(n: number): EventEmitter;
/**
* Returns an array of functions that are registered to listen for the specified event.
*
* @param {string} eventName - The name of the event to get the listeners for.
* @returns {ListenerCallbackFunc[]} - An array of functions that are registered to listen for the specified event.
*/
listeners(eventName: string): ListenerCallbackFunc[];
/**
* Returns the count of listeners that are registered to listen for the specified event.
*
* @param {string} eventName - The name of the event to get the listeners for.
* @returns {number} - the listeners count
*/
listenerCount(eventName: string): number;
static listenerCount(emitter: EventEmitter, eventName: string): number; // Deprecated
}
export default EventEmitter;

@@ -6,43 +6,12 @@ "use strict";

});
exports.methods = exports.default = void 0;
exports.wrapEventEmitter = wrapEventEmitter;
var _eventable = _interopRequireDefault(require("./eventable"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const create = Object.create;
const defineProperties = Object.defineProperties;
const methods = (0, _eventable.default)().methods;
exports.methods = methods;
const descriptors = {
on: {
value: methods.on
},
once: {
value: methods.once
},
off: {
value: methods.off
},
emit: {
value: methods.emit
},
emitAsync: {
value: methods.emitAsync
}
};
const base = defineProperties({}, descriptors);
exports.EventEmitter = EventEmitter;
exports.default = void 0;
var _eventable = require("./eventable");
/**
* Create or inject the eventable instance into the object
* @param {Object} [o] the optional instance to eventable
* @returns o or new Event instance
* @class
* @classdesc Class that represents an event emitter.
*/
function wrapEventEmitter(o) {
if (o == null) {
return create(base);
} else {
return defineProperties(Object(o), descriptors);
}
}
;
var _default = wrapEventEmitter;
function EventEmitter() {}
(0, _eventable.eventable)(EventEmitter);
var _default = EventEmitter;
exports.default = _default;

@@ -5,6 +5,6 @@ /**

* @classdesc Event Object that contains information about the event, such as the target element and the return value of the event.
* @param {EventEmitter} target - Who trigger the event
* @param {import('./event-emitter').EventEmitter} target - Who trigger the event
* @returns {Event} - The new Event instance.
*/
export function Event(target: EventEmitter): Event;
export function Event(target: import('./event-emitter').EventEmitter): Event;
export class Event {

@@ -15,11 +15,11 @@ /**

* @classdesc Event Object that contains information about the event, such as the target element and the return value of the event.
* @param {EventEmitter} target - Who trigger the event
* @param {import('./event-emitter').EventEmitter} target - Who trigger the event
* @returns {Event} - The new Event instance.
*/
constructor(target: EventEmitter);
constructor(target: import('./event-emitter').EventEmitter);
/**
* Initializes the event with the target object.
* @param {EventEmitter} target - The target object for the event.
* @param {import('./event-emitter').EventEmitter} target - The target object for the event.
*/
init(target: EventEmitter): void;
init(target: import('./event-emitter').EventEmitter): void;
/**

@@ -26,0 +26,0 @@ * Who trigger the event

@@ -12,3 +12,3 @@ "use strict";

* @classdesc Event Object that contains information about the event, such as the target element and the return value of the event.
* @param {EventEmitter} target - Who trigger the event
* @param {import('./event-emitter').EventEmitter} target - Who trigger the event
* @returns {Event} - The new Event instance.

@@ -26,3 +26,3 @@ */

* Initializes the event with the target object.
* @param {EventEmitter} target - The target object for the event.
* @param {import('./event-emitter').EventEmitter} target - The target object for the event.
*/

@@ -29,0 +29,0 @@ Event.prototype.init = function (target) {

@@ -1,79 +0,12 @@

export * from './consts'
export * from './all-off'
export * from './eventable'
export * from './event-emitter'
export * from './has-listeners'
export * from './pipe'
export * from './pipe-async'
export * from './unify'
type ListenerCallbackFunc = Function;
/**
* Class that represents an event emitter.
*/
export class EventEmitter {
static defaultMaxListeners: number;
/**
* Adds a listener function to the specified event type.
* @param {string} type - The event type to listen for.
* @param {Function} listener - The listener function to be called when the event is emitted.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.
*/
on(eventName: string, listener: ListenerCallbackFunc): EventEmitter;
/**
* Adds a one-time listener function to the specified event type.
* @param {string} type - The event type to listen for.
* @param {Function} listener - The listener function to be called once when the event is emitted.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.
*/
once(eventName: string, listener: ListenerCallbackFunc): EventEmitter;
/**
* Removes a listener function from the specified event type.
* @param {string} type - The event type to remove the listener from.
* @param {Function} listener - The listener function to be removed.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.
*/
off(eventName: string, listener: ListenerCallbackFunc): EventEmitter;
/**
* Emits the specified event type with the given arguments.
* @param {...*} args - The event type followed by any number of arguments to be passed to the listener functions.
* @returns {*} The result of the event.
*/
emit(eventName: string, ...args: any[]): any;
/**
* Asynchronously emits the specified event type with the given arguments.
* @param {...*} args - The event type followed by any number of arguments to be passed to the listener functions.
* @returns {Promise<*>} A promise that resolves with the result of the event.
*/
emitAsync(eventName: string, ...args: any[]): Promise<any>;
/**
* Removes all listeners for a specific event or all events from an event emitter.
*
* @param {string} [eventName] - The event to remove listeners for. If not provided, all listeners for all events will be removed.
* @returns {EventEmitter} - The event emitter with all listeners removed.
*/
removeAllListeners(eventName?: string): EventEmitter;
setMaxListeners(n: number): EventEmitter;
/**
* Returns an array of functions that are registered to listen for the specified event.
*
* @param {string} eventName - The name of the event to get the listeners for.
* @returns {ListenerCallbackFunc[]} - An array of functions that are registered to listen for the specified event.
*/
listeners(eventName: string): ListenerCallbackFunc[];
/**
* Returns the count of listeners that are registered to listen for the specified event.
*
* @param {string} eventName - The name of the event to get the listeners for.
* @returns {number} - the listeners count
*/
listenerCount(eventName: string): number;
static listenerCount(emitter: EventEmitter, eventName: string): number; // Deprecated
}
export * from "./all-off";
export * from "./consts";
export * from "./event";
export * from "./eventable";
export * from "./event-emitter";
export * from "./has-listeners";
export * from "./pipe";
export * from "./pipe-async";
export * from "./unify";
export * from "./wrap-event-emitter";
export default EventEmitter;
import { EventEmitter } from './event-emitter';

@@ -6,16 +6,13 @@ "use strict";

});
var _exportNames = {
EventEmitter: true
};
exports.EventEmitter = EventEmitter;
var _exportNames = {};
exports.default = void 0;
var _eventable = _interopRequireWildcard(require("./eventable"));
Object.keys(_eventable).forEach(function (key) {
var _eventEmitter = require("./event-emitter");
Object.keys(_eventEmitter).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _eventable[key]) return;
if (key in exports && exports[key] === _eventEmitter[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _eventable[key];
return _eventEmitter[key];
}

@@ -60,11 +57,11 @@ });

});
var _eventEmitter = require("./event-emitter");
Object.keys(_eventEmitter).forEach(function (key) {
var _eventable = require("./eventable");
Object.keys(_eventable).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _eventEmitter[key]) return;
if (key in exports && exports[key] === _eventable[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _eventEmitter[key];
return _eventable[key];
}

@@ -121,11 +118,15 @@ });

});
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
* @class
* @classdesc Class that represents an event emitter.
*/
function EventEmitter() {}
(0, _eventable.default)(EventEmitter);
var _default = EventEmitter;
var _wrapEventEmitter = require("./wrap-event-emitter");
Object.keys(_wrapEventEmitter).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _wrapEventEmitter[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _wrapEventEmitter[key];
}
});
});
var _default = _eventEmitter.EventEmitter;
exports.default = _default;
/**
* Creates a pipeline between two event emitters, so that any events emitted by the first emitter are also emitted by the second emitter.
*
* @param {EventEmitter} e1 - The first event emitter.
* @param {EventEmitter} e2 - The second event emitter.
* @param {import('./event-emitter').EventEmitter} e1 - The first event emitter.
* @param {import('./event-emitter').EventEmitter} e2 - The second event emitter.
* @param {string} [name='emitAsync'] - The name of the event to pipe (defaults to 'emitAsync').

@@ -10,3 +10,3 @@ * @returns {Object} - An object with a `close` method that removes the pipeline between the two event emitters.

*/
export function pipeAsync(e1: EventEmitter, e2: EventEmitter, ...args: any[]): any;
export function pipeAsync(e1: import('./event-emitter').EventEmitter, e2: import('./event-emitter').EventEmitter, ...args: any[]): any;
export default pipeAsync;

@@ -9,3 +9,3 @@ "use strict";

var _defineProperty = _interopRequireDefault(require("util-ex/lib/defineProperty"));
var _eventEmitter = require("./event-emitter");
var _wrapEventEmitter = require("./wrap-event-emitter");
var _arrayRemove = _interopRequireDefault(require("./util/array-remove"));

@@ -17,3 +17,3 @@ var _validObject = _interopRequireDefault(require("./util/valid-object"));

const arrFrom = Array.from;
const emit = _eventEmitter.methods.emitAsync;
const emit = _wrapEventEmitter.methods.emitAsync;

@@ -23,4 +23,4 @@ /**

*
* @param {EventEmitter} e1 - The first event emitter.
* @param {EventEmitter} e2 - The second event emitter.
* @param {import('./event-emitter').EventEmitter} e1 - The first event emitter.
* @param {import('./event-emitter').EventEmitter} e2 - The second event emitter.
* @param {string} [name='emitAsync'] - The name of the event to pipe (defaults to 'emitAsync').

@@ -27,0 +27,0 @@ * @returns {Object} - An object with a `close` method that removes the pipeline between the two event emitters.

/**
* Creates a pipeline between two event emitters, so that any events emitted by the first emitter are also emitted by the second emitter.
*
* @param {EventEmitter} e1 - The first event emitter.
* @param {EventEmitter} e2 - The second event emitter.
* @param {import('./event-emitter').EventEmitter} e1 - The first event emitter.
* @param {import('./event-emitter').EventEmitter} e2 - The second event emitter.
* @param {string} [name='emit'] - The name of the event to pipe (defaults to 'emit').

@@ -10,3 +10,3 @@ * @returns {Object} - An object with a `close` method that removes the pipeline between the two event emitters.

*/
export function pipe(e1: EventEmitter, e2: EventEmitter, ...args: any[]): any;
export function pipe(e1: import('./event-emitter').EventEmitter, e2: import('./event-emitter').EventEmitter, ...args: any[]): any;
export default pipe;

@@ -9,3 +9,3 @@ "use strict";

var _defineProperty = _interopRequireDefault(require("util-ex/lib/defineProperty"));
var _eventEmitter = require("./event-emitter");
var _wrapEventEmitter = require("./wrap-event-emitter");
var _arrayRemove = _interopRequireDefault(require("./util/array-remove"));

@@ -17,3 +17,3 @@ var _validObject = _interopRequireDefault(require("./util/valid-object"));

const arrFrom = Array.from;
const emit = _eventEmitter.methods.emit;
const emit = _wrapEventEmitter.methods.emit;

@@ -23,4 +23,4 @@ /**

*
* @param {EventEmitter} e1 - The first event emitter.
* @param {EventEmitter} e2 - The second event emitter.
* @param {import('./event-emitter').EventEmitter} e1 - The first event emitter.
* @param {import('./event-emitter').EventEmitter} e2 - The second event emitter.
* @param {string} [name='emit'] - The name of the event to pipe (defaults to 'emit').

@@ -27,0 +27,0 @@ * @returns {Object} - An object with a `close` method that removes the pipeline between the two event emitters.

/**
* Unifies the event listeners of two event emitter objects so that they share the same set of listeners for each event.
*
* @param {EventEmitter} e1 - The first event emitter object.
* @param {EventEmitter} e2 - The second event emitter object.
* @param {import('./event-emitter').EventEmitter} e1 - The first event emitter object.
* @param {import('./event-emitter').EventEmitter} e2 - The second event emitter object.
* @throws {TypeError} - If either of the arguments is not an event emitter object.
*/
export function unify(e1: EventEmitter, e2: EventEmitter): void;
export function unify(e1: import('./event-emitter').EventEmitter, e2: import('./event-emitter').EventEmitter): void;
export default unify;

@@ -24,4 +24,4 @@ "use strict";

*
* @param {EventEmitter} e1 - The first event emitter object.
* @param {EventEmitter} e2 - The second event emitter object.
* @param {import('./event-emitter').EventEmitter} e1 - The first event emitter object.
* @param {import('./event-emitter').EventEmitter} e2 - The second event emitter object.
* @throws {TypeError} - If either of the arguments is not an event emitter object.

@@ -28,0 +28,0 @@ */

{
"name": "events-ex",
"version": "2.0.0-alpha.1",
"version": "2.0.0-alpha.2",
"description": "Browser-friendly enhanced events most compatible with standard node.js, it's powerful eventable ability.",

@@ -64,3 +64,3 @@ "contributors": [

"build.cjs": "babel src --out-dir lib --config-file ./.babelrc",
"build.ts": "tsc --declaration --emitDeclarationOnly --outDir lib && cp src/index.d.ts lib/",
"build.ts": "tsc --declaration --emitDeclarationOnly --outDir lib && cp src/event-emitter.d.ts lib/",
"clean": "rm -fr web docs lib",

@@ -67,0 +67,0 @@ "clean.doc": "rm -fr web docs",

@@ -8,5 +8,5 @@ import eventable from './eventable'

*
* @param {EventEmitter} emitter - The event emitter to remove listeners from.
* @param {import('./event-emitter').EventEmitter} emitter - The event emitter to remove listeners from.
* @param {string} [type] - The event to remove listeners for. If not provided, all listeners for all events will be removed.
* @returns {EventEmitter} - The event emitter with all listeners removed.
* @returns {import('./event-emitter').EventEmitter} - The event emitter with all listeners removed.
*/

@@ -13,0 +13,0 @@ export function allOff(emitter, type) {

@@ -14,3 +14,3 @@ import {defineProperty, isArray, isFunction, isNumber, isObject, isUndefined} from 'util-ex'

* @param {Function} listener - The listener function to be called when the event is emitted.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.

@@ -64,3 +64,3 @@ */

* @param {Function} listener - The listener function to be called once when the event is emitted.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.

@@ -176,3 +176,3 @@ */

* @param {Function} listener - The listener function to be removed.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.

@@ -213,3 +213,3 @@ */

* @param {string} type - The event type to remove the listener from.
* @returns {EventEmitter} The EventEmitter instance to allow chaining.
* @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
* @throws {TypeError} If the listener is not a function.

@@ -216,0 +216,0 @@ */

@@ -1,42 +0,11 @@

import eventable from './eventable'
import {eventable} from './eventable'
const create = Object.create;
const defineProperties = Object.defineProperties;
export const methods = eventable().methods;
const descriptors = {
on: {
value: methods.on
},
once: {
value: methods.once
},
off: {
value: methods.off
},
emit: {
value: methods.emit
},
emitAsync: {
value: methods.emitAsync
},
};
const base = defineProperties({}, descriptors);
/**
* Create or inject the eventable instance into the object
* @param {Object} [o] the optional instance to eventable
* @returns o or new Event instance
* @class
* @classdesc Class that represents an event emitter.
*/
export function wrapEventEmitter(o) {
if (o == null) {
return create(base);
} else {
return defineProperties(Object(o), descriptors);
}
};
export function EventEmitter() {}
eventable(EventEmitter);
export default wrapEventEmitter
export default EventEmitter;

@@ -5,3 +5,3 @@ /**

* @classdesc Event Object that contains information about the event, such as the target element and the return value of the event.
* @param {EventEmitter} target - Who trigger the event
* @param {import('./event-emitter').EventEmitter} target - Who trigger the event
* @returns {Event} - The new Event instance.

@@ -19,3 +19,3 @@ */

* Initializes the event with the target object.
* @param {EventEmitter} target - The target object for the event.
* @param {import('./event-emitter').EventEmitter} target - The target object for the event.
*/

@@ -22,0 +22,0 @@ Event.prototype.init = function(target) {

@@ -1,2 +0,2 @@

import eventable from './eventable'
import {EventEmitter} from './event-emitter'

@@ -12,11 +12,4 @@ export * from './all-off'

export * from './unify'
export * from './wrap-event-emitter'
/**
* @class
* @classdesc Class that represents an event emitter.
*/
export function EventEmitter() {}
eventable(EventEmitter);
export default EventEmitter;
import defineProperty from 'util-ex/lib/defineProperty'
import {methods} from './event-emitter'
import {methods} from './wrap-event-emitter'
import arrRemove from './util/array-remove'

@@ -15,4 +15,4 @@ import validObject from './util/valid-object'

*
* @param {EventEmitter} e1 - The first event emitter.
* @param {EventEmitter} e2 - The second event emitter.
* @param {import('./event-emitter').EventEmitter} e1 - The first event emitter.
* @param {import('./event-emitter').EventEmitter} e2 - The second event emitter.
* @param {string} [name='emitAsync'] - The name of the event to pipe (defaults to 'emitAsync').

@@ -19,0 +19,0 @@ * @returns {Object} - An object with a `close` method that removes the pipeline between the two event emitters.

import defineProperty from 'util-ex/lib/defineProperty'
import {methods} from './event-emitter'
import {methods} from './wrap-event-emitter'
import arrRemove from './util/array-remove'

@@ -15,4 +15,4 @@ import validObject from './util/valid-object'

*
* @param {EventEmitter} e1 - The first event emitter.
* @param {EventEmitter} e2 - The second event emitter.
* @param {import('./event-emitter').EventEmitter} e1 - The first event emitter.
* @param {import('./event-emitter').EventEmitter} e2 - The second event emitter.
* @param {string} [name='emit'] - The name of the event to pipe (defaults to 'emit').

@@ -19,0 +19,0 @@ * @returns {Object} - An object with a `close` method that removes the pipeline between the two event emitters.

@@ -13,4 +13,4 @@ import validObject from './util/valid-object'

*
* @param {EventEmitter} e1 - The first event emitter object.
* @param {EventEmitter} e2 - The second event emitter object.
* @param {import('./event-emitter').EventEmitter} e1 - The first event emitter object.
* @param {import('./event-emitter').EventEmitter} e2 - The second event emitter object.
* @throws {TypeError} - If either of the arguments is not an event emitter object.

@@ -17,0 +17,0 @@ */

import {assert} from "chai";
import ee from '../src/event-emitter'
import ee from '../src/wrap-event-emitter'
import allOff from '../src/all-off'

@@ -5,0 +5,0 @@

import {assert} from "chai";
import wrapEventEmitter from '../src/event-emitter'
import wrapEventEmitter from '../src/wrap-event-emitter'

@@ -5,0 +5,0 @@ function wait(milliseconds){

import {assert} from "chai";
import eventEmitter from '../src/event-emitter'
import eventEmitter from '../src/wrap-event-emitter'

@@ -5,0 +5,0 @@ function deepEqu(act, expected, msg) {

import {assert} from "chai";
import hasListeners from '../src/has-listeners'
import ee from '../src/event-emitter';
import ee from '../src/wrap-event-emitter';

@@ -6,0 +6,0 @@ describe('hasListeners', () => {

import {assert} from "chai";
import pipeAsync from '../src/pipe-async'
import ee from '../src/event-emitter';
import ee from '../src/wrap-event-emitter';

@@ -6,0 +6,0 @@ describe('pipe-async', () => {

import {assert} from "chai";
import pipe from '../src/pipe'
import ee from '../src/event-emitter';
import ee from '../src/wrap-event-emitter';

@@ -6,0 +6,0 @@ describe('pipe', () => {

import {assert} from "chai"
import unify from '../src/unify'
import ee from '../src/event-emitter'
import ee from '../src/wrap-event-emitter'

@@ -6,0 +6,0 @@ describe('unify async', () => {

import {assert} from "chai"
import unify from '../src/unify'
import ee from '../src/event-emitter'
import ee from '../src/wrap-event-emitter'

@@ -6,0 +6,0 @@ describe('unify', () => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc