events-ex 2.0.0-alpha.13 → 2.0.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [2.0.0-alpha.15](https://github.com/snowyu/events-ex.js/compare/v2.0.0-alpha.14...v2.0.0-alpha.15) (2024-04-05)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **ts:** add typescript declaration for RegExp to listen ([ccda83d](https://github.com/snowyu/events-ex.js/commit/ccda83d9385b9dc16382fce7d0d9f9d0ebe275ed))
11
+
12
+ ## [2.0.0-alpha.14](https://github.com/snowyu/events-ex.js/compare/v2.0.0-alpha.13...v2.0.0-alpha.14) (2024-03-29)
13
+
14
+
15
+ ### Refactor
16
+
17
+ * extract the isRegExpStr and toRegExp to util-ex ([706994b](https://github.com/snowyu/events-ex.js/commit/706994b76036cbaf4650b12dde673508d8d74c5d))
18
+
5
19
  ## [2.0.0-alpha.13](https://github.com/snowyu/events-ex.js/compare/v2.0.0-alpha.12...v2.0.0-alpha.13) (2024-03-28)
6
20
 
7
21
 
@@ -49,7 +49,7 @@ Event Object that contains information about the event, such as the target eleme
49
49
 
50
50
  #### Defined in
51
51
 
52
- [src/event.js:8](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event.js#L8)
52
+ [src/event.js:8](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event.js#L8)
53
53
 
54
54
  ## Properties
55
55
 
@@ -61,7 +61,7 @@ Keep your event result here if any.
61
61
 
62
62
  #### Defined in
63
63
 
64
- [src/event.js:38](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event.js#L38)
64
+ [src/event.js:38](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event.js#L38)
65
65
 
66
66
  ___
67
67
 
@@ -73,7 +73,7 @@ Whether stop the bubbling event
73
73
 
74
74
  #### Defined in
75
75
 
76
- [src/event.js:32](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event.js#L32)
76
+ [src/event.js:32](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event.js#L32)
77
77
 
78
78
  ___
79
79
 
@@ -85,7 +85,7 @@ Who trigger the event
85
85
 
86
86
  #### Defined in
87
87
 
88
- [src/event.js:26](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event.js#L26)
88
+ [src/event.js:26](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event.js#L26)
89
89
 
90
90
  ___
91
91
 
@@ -97,7 +97,7 @@ The type of the event.
97
97
 
98
98
  #### Defined in
99
99
 
100
- [src/event.js:44](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event.js#L44)
100
+ [src/event.js:44](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event.js#L44)
101
101
 
102
102
  ## Methods
103
103
 
@@ -115,7 +115,7 @@ The result of the event.
115
115
 
116
116
  #### Defined in
117
117
 
118
- [src/event.js:51](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event.js#L51)
118
+ [src/event.js:51](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event.js#L51)
119
119
 
120
120
  ___
121
121
 
@@ -138,4 +138,4 @@ Initializes the event with the target object.
138
138
 
139
139
  #### Defined in
140
140
 
141
- [src/event.js:20](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event.js#L20)
141
+ [src/event.js:20](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event.js#L20)
@@ -26,4 +26,4 @@ Class that represents an event emitter.
26
26
 
27
27
  #### Defined in
28
28
 
29
- [src/event-emitter.js:8](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event-emitter.js#L8)
29
+ [src/event-emitter.js:8](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event-emitter.js#L8)
@@ -47,7 +47,7 @@ Class that represents an event emitter.
47
47
 
48
48
  #### Defined in
49
49
 
50
- [src/event-emitter.d.ts:7](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event-emitter.d.ts#L7)
50
+ [src/event-emitter.d.ts:7](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event-emitter.d.ts#L7)
51
51
 
52
52
  ## Methods
53
53
 
@@ -72,7 +72,7 @@ The result of the event.
72
72
 
73
73
  #### Defined in
74
74
 
75
- [src/event-emitter.d.ts:38](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event-emitter.d.ts#L38)
75
+ [src/event-emitter.d.ts:38](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event-emitter.d.ts#L38)
76
76
 
77
77
  ___
78
78
 
@@ -97,7 +97,7 @@ A promise that resolves with the result of the event.
97
97
 
98
98
  #### Defined in
99
99
 
100
- [src/event-emitter.d.ts:44](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event-emitter.d.ts#L44)
100
+ [src/event-emitter.d.ts:44](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event-emitter.d.ts#L44)
101
101
 
102
102
  ___
103
103
 
@@ -111,7 +111,7 @@ Returns the count of listeners that are registered to listen for the specified e
111
111
 
112
112
  | Name | Type | Description |
113
113
  | :------ | :------ | :------ |
114
- | `eventName` | `string` | The name of the event to get the listeners for. |
114
+ | `eventName` | `string` \| `RegExp` | The name of the event to get the listeners for. |
115
115
 
116
116
  #### Returns
117
117
 
@@ -121,7 +121,7 @@ Returns the count of listeners that are registered to listen for the specified e
121
121
 
122
122
  #### Defined in
123
123
 
124
- [src/event-emitter.d.ts:66](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event-emitter.d.ts#L66)
124
+ [src/event-emitter.d.ts:66](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event-emitter.d.ts#L66)
125
125
 
126
126
  ___
127
127
 
@@ -135,7 +135,7 @@ Returns an array of functions that are registered to listen for the specified ev
135
135
 
136
136
  | Name | Type | Description |
137
137
  | :------ | :------ | :------ |
138
- | `eventName` | `string` | The name of the event to get the listeners for. |
138
+ | `eventName` | `string` \| `RegExp` | The name of the event to get the listeners for. |
139
139
 
140
140
  #### Returns
141
141
 
@@ -145,7 +145,7 @@ Returns an array of functions that are registered to listen for the specified ev
145
145
 
146
146
  #### Defined in
147
147
 
148
- [src/event-emitter.d.ts:59](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event-emitter.d.ts#L59)
148
+ [src/event-emitter.d.ts:59](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event-emitter.d.ts#L59)
149
149
 
150
150
  ___
151
151
 
@@ -159,7 +159,7 @@ Removes a listener function from the specified event type.
159
159
 
160
160
  | Name | Type | Description |
161
161
  | :------ | :------ | :------ |
162
- | `eventName` | `string` | - |
162
+ | `eventName` | `string` \| `RegExp` | - |
163
163
  | `listener` | `Function` | The listener function to be removed. |
164
164
 
165
165
  #### Returns
@@ -174,7 +174,7 @@ If the listener is not a function.
174
174
 
175
175
  #### Defined in
176
176
 
177
- [src/event-emitter.d.ts:32](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event-emitter.d.ts#L32)
177
+ [src/event-emitter.d.ts:32](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event-emitter.d.ts#L32)
178
178
 
179
179
  ___
180
180
 
@@ -188,7 +188,7 @@ Adds a listener function to the specified event type.
188
188
 
189
189
  | Name | Type | Description |
190
190
  | :------ | :------ | :------ |
191
- | `eventName` | `string` | - |
191
+ | `eventName` | `string` \| `RegExp` | - |
192
192
  | `listener` | `Function` | The listener function to be called when the event is emitted. |
193
193
 
194
194
  #### Returns
@@ -203,7 +203,7 @@ If the listener is not a function.
203
203
 
204
204
  #### Defined in
205
205
 
206
- [src/event-emitter.d.ts:16](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event-emitter.d.ts#L16)
206
+ [src/event-emitter.d.ts:16](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event-emitter.d.ts#L16)
207
207
 
208
208
  ___
209
209
 
@@ -217,7 +217,7 @@ Adds a one-time listener function to the specified event type.
217
217
 
218
218
  | Name | Type | Description |
219
219
  | :------ | :------ | :------ |
220
- | `eventName` | `string` | - |
220
+ | `eventName` | `string` \| `RegExp` | - |
221
221
  | `listener` | `Function` | The listener function to be called once when the event is emitted. |
222
222
 
223
223
  #### Returns
@@ -232,7 +232,7 @@ If the listener is not a function.
232
232
 
233
233
  #### Defined in
234
234
 
235
- [src/event-emitter.d.ts:24](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event-emitter.d.ts#L24)
235
+ [src/event-emitter.d.ts:24](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event-emitter.d.ts#L24)
236
236
 
237
237
  ___
238
238
 
@@ -246,7 +246,7 @@ Removes all listeners for a specific event or all events from an event emitter.
246
246
 
247
247
  | Name | Type | Description |
248
248
  | :------ | :------ | :------ |
249
- | `eventName?` | `string` | The event to remove listeners for. If not provided, all listeners for all events will be removed. |
249
+ | `eventName?` | `string` \| `RegExp` | The event to remove listeners for. If not provided, all listeners for all events will be removed. |
250
250
 
251
251
  #### Returns
252
252
 
@@ -256,7 +256,7 @@ Removes all listeners for a specific event or all events from an event emitter.
256
256
 
257
257
  #### Defined in
258
258
 
259
- [src/event-emitter.d.ts:51](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event-emitter.d.ts#L51)
259
+ [src/event-emitter.d.ts:51](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event-emitter.d.ts#L51)
260
260
 
261
261
  ___
262
262
 
@@ -276,7 +276,7 @@ ___
276
276
 
277
277
  #### Defined in
278
278
 
279
- [src/event-emitter.d.ts:52](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event-emitter.d.ts#L52)
279
+ [src/event-emitter.d.ts:52](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event-emitter.d.ts#L52)
280
280
 
281
281
  ___
282
282
 
@@ -284,17 +284,23 @@ ___
284
284
 
285
285
  ▸ **listenerCount**(`emitter`, `eventName`): `number`
286
286
 
287
+ Returns the count of listeners that are registered to listen for the specified event.
288
+
287
289
  #### Parameters
288
290
 
289
291
  | Name | Type |
290
292
  | :------ | :------ |
291
293
  | `emitter` | [`EventEmitter`](event_emitter.EventEmitter.md) |
292
- | `eventName` | `string` |
294
+ | `eventName` | `string` \| `RegExp` |
293
295
 
294
296
  #### Returns
295
297
 
296
298
  `number`
297
299
 
300
+ **`Deprecated`**
301
+
302
+ use emitter.listenerCount instead
303
+
298
304
  #### Defined in
299
305
 
300
- [src/event-emitter.d.ts:67](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/event-emitter.d.ts#L67)
306
+ [src/event-emitter.d.ts:74](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/event-emitter.d.ts#L74)
@@ -41,4 +41,4 @@ Removes all listeners for a specific event or all events from an event emitter.
41
41
 
42
42
  #### Defined in
43
43
 
44
- [src/all-off.js:12](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/all-off.js#L12)
44
+ [src/all-off.js:12](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/all-off.js#L12)
@@ -17,7 +17,7 @@
17
17
 
18
18
  #### Defined in
19
19
 
20
- [src/consts.js:13](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/consts.js#L13)
20
+ [src/consts.js:13](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/consts.js#L13)
21
21
 
22
22
  ___
23
23
 
@@ -36,4 +36,4 @@ ___
36
36
 
37
37
  #### Defined in
38
38
 
39
- [src/consts.js:6](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/consts.js#L6)
39
+ [src/consts.js:6](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/consts.js#L6)
@@ -40,12 +40,12 @@ Renames and re-exports [getEventableMethods](default_methods.md#geteventablemeth
40
40
  | `emitAsync` | (...`args`: `any`) => `Promise`\<`any`\> |
41
41
  | `listenerCount` | (`emitter`: `any`, `type`: `any`) => `number` |
42
42
  | `listeners` | (`type`: `any`) => `any` |
43
- | `off` | (`type`: `string`, `listener`: `Function`) => [`EventEmitter`](../classes/event_emitter.EventEmitter.md) |
44
- | `on` | (`type`: `string`, `listener`: `Function`) => [`EventEmitter`](../classes/event_emitter.EventEmitter.md) |
45
- | `once` | (`type`: `string`, `listener`: `Function`) => [`EventEmitter`](../classes/event_emitter.EventEmitter.md) |
46
- | `removeAllListeners` | (`type`: `string`) => [`EventEmitter`](../classes/event_emitter.EventEmitter.md) |
47
- | `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; } |
43
+ | `off` | (`type`: `string` \| `RegExp`, `listener`: `Function`) => [`EventEmitter`](../classes/event_emitter.EventEmitter.md) |
44
+ | `on` | (`type`: `string` \| `RegExp`, `listener`: `Function`) => [`EventEmitter`](../classes/event_emitter.EventEmitter.md) |
45
+ | `once` | (`type`: `string` \| `RegExp`, `listener`: `Function`) => [`EventEmitter`](../classes/event_emitter.EventEmitter.md) |
46
+ | `removeAllListeners` | (`type`: `string` \| `RegExp`) => [`EventEmitter`](../classes/event_emitter.EventEmitter.md) |
47
+ | `setMaxListeners` | (`n`: `any`) => \{ on(type: string \| RegExp, listener: Function): EventEmitter; once(type: string \| RegExp, listener: Function): EventEmitter; ... 6 more ...; removeAllListeners(type: string \| RegExp): EventEmitter; } |
48
48
 
49
49
  #### Defined in
50
50
 
51
- [src/default-methods.js:28](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/default-methods.js#L28)
51
+ [src/default-methods.js:14](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/default-methods.js#L14)
@@ -37,4 +37,4 @@ Renames and re-exports [hasListeners](has_listeners.md#haslisteners)
37
37
 
38
38
  #### Defined in
39
39
 
40
- [src/has-listeners.js:10](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/has-listeners.js#L10)
40
+ [src/has-listeners.js:10](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/has-listeners.js#L10)
@@ -46,4 +46,4 @@ Creates a pipeline between two event emitters, so that any events emitted by the
46
46
 
47
47
  #### Defined in
48
48
 
49
- [src/pipe.js:21](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/pipe.js#L21)
49
+ [src/pipe.js:21](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/pipe.js#L21)
@@ -46,4 +46,4 @@ Creates a pipeline between two event emitters, so that any events emitted by the
46
46
 
47
47
  #### Defined in
48
48
 
49
- [src/pipe-async.js:21](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/pipe-async.js#L21)
49
+ [src/pipe-async.js:21](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/pipe-async.js#L21)
@@ -43,4 +43,4 @@ Unifies the event listeners of two event emitter objects so that they share the
43
43
 
44
44
  #### Defined in
45
45
 
46
- [src/unify.js:17](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/unify.js#L17)
46
+ [src/unify.js:17](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/unify.js#L17)
@@ -36,4 +36,4 @@ Renames and re-exports [remove](util_array_remove.md#remove)
36
36
 
37
37
  #### Defined in
38
38
 
39
- [src/util/array-remove.js:5](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/util/array-remove.js#L5)
39
+ [src/util/array-remove.js:5](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/util/array-remove.js#L5)
@@ -38,4 +38,4 @@ Renames and re-exports [forEach](util_object_for_each.md#foreach)
38
38
 
39
39
  #### Defined in
40
40
 
41
- [src/util/object-for-each.js:6](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/util/object-for-each.js#L6)
41
+ [src/util/object-for-each.js:6](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/util/object-for-each.js#L6)
@@ -37,4 +37,4 @@ Renames and re-exports [pad](util_string_pad.md#pad)
37
37
 
38
38
  #### Defined in
39
39
 
40
- [src/util/string-pad.js:8](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/util/string-pad.js#L8)
40
+ [src/util/string-pad.js:8](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/util/string-pad.js#L8)
@@ -36,4 +36,4 @@ Renames and re-exports [toInt](util_to_int.md#toint)
36
36
 
37
37
  #### Defined in
38
38
 
39
- [src/util/to-int.js:2](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/util/to-int.js#L2)
39
+ [src/util/to-int.js:2](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/util/to-int.js#L2)
@@ -36,4 +36,4 @@ Renames and re-exports [validCallable](util_valid_callable.md#validcallable)
36
36
 
37
37
  #### Defined in
38
38
 
39
- [src/util/valid-callable.js:1](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/util/valid-callable.js#L1)
39
+ [src/util/valid-callable.js:1](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/util/valid-callable.js#L1)
@@ -36,4 +36,4 @@ Renames and re-exports [validObject](util_valid_object.md#validobject)
36
36
 
37
37
  #### Defined in
38
38
 
39
- [src/util/valid-object.js:3](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/util/valid-object.js#L3)
39
+ [src/util/valid-object.js:3](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/util/valid-object.js#L3)
@@ -30,7 +30,7 @@ Renames and re-exports [wrapEventEmitter](wrap_event_emitter.md#wrapeventemitter
30
30
 
31
31
  #### Defined in
32
32
 
33
- [src/wrap-event-emitter.js:7](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/wrap-event-emitter.js#L7)
33
+ [src/wrap-event-emitter.js:7](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/wrap-event-emitter.js#L7)
34
34
 
35
35
  ## Functions
36
36
 
@@ -54,4 +54,4 @@ o or new Event instance
54
54
 
55
55
  #### Defined in
56
56
 
57
- [src/wrap-event-emitter.js:34](https://github.com/snowyu/events-ex.js/blob/ca80c32/src/wrap-event-emitter.js#L34)
57
+ [src/wrap-event-emitter.js:34](https://github.com/snowyu/events-ex.js/blob/ccda83d/src/wrap-event-emitter.js#L34)
@@ -1,20 +1,20 @@
1
1
  export function getEventableMethods(aClass: any): {
2
2
  /**
3
3
  * Adds a listener function to the specified event type.
4
- * @param {string} type - The event type to listen for.
4
+ * @param {string|RegExp} type - The event type to listen for.
5
5
  * @param {Function} listener - The listener function to be called when the event is emitted.
6
6
  * @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
7
7
  * @throws {TypeError} If the listener is not a function.
8
8
  */
9
- on(type: string, listener: Function): import('./event-emitter').EventEmitter;
9
+ on(type: string | RegExp, listener: Function): import('./event-emitter').EventEmitter;
10
10
  /**
11
11
  * Adds a one-time listener function to the specified event type.
12
- * @param {string} type - The event type to listen for.
12
+ * @param {string|RegExp} type - The event type to listen for.
13
13
  * @param {Function} listener - The listener function to be called once when the event is emitted.
14
14
  * @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
15
15
  * @throws {TypeError} If the listener is not a function.
16
16
  */
17
- once(type: string, listener: Function): import('./event-emitter').EventEmitter;
17
+ once(type: string | RegExp, listener: Function): import('./event-emitter').EventEmitter;
18
18
  /**
19
19
  * Emits the specified event type with the given arguments.
20
20
  * @param {...*} args - The event type followed by any number of arguments to be passed to the listener functions.
@@ -32,18 +32,18 @@ export function getEventableMethods(aClass: any): {
32
32
  listenerCount(emitter: any, type: any): number;
33
33
  /**
34
34
  * Removes a listener function from the specified event type.
35
- * @param {string} type - The event type to remove the listener from.
35
+ * @param {string|RegExp} type - The event type to remove the listener from.
36
36
  * @param {Function} listener - The listener function to be removed.
37
37
  * @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
38
38
  * @throws {TypeError} If the listener is not a function.
39
39
  */
40
- off(type: string, listener: Function): import('./event-emitter').EventEmitter;
40
+ off(type: string | RegExp, listener: Function): import('./event-emitter').EventEmitter;
41
41
  /**
42
42
  * Removes all listener functions from the specified event type.
43
- * @param {string} type - The event type to remove the listener from.
43
+ * @param {string|RegExp} type - The event type to remove the listener from.
44
44
  * @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
45
45
  * @throws {TypeError} If the listener is not a function.
46
46
  */
47
- removeAllListeners(type: string): import('./event-emitter').EventEmitter;
47
+ removeAllListeners(type: string | RegExp): import('./event-emitter').EventEmitter;
48
48
  };
49
49
  export default getEventableMethods;
@@ -11,27 +11,15 @@ var _event = require("./event");
11
11
  const create = Object.create;
12
12
  const UnCAUGHT_ERR = "Uncaught, unspecified 'error' event.";
13
13
  const slice = Array.prototype.slice;
14
- function isRegExpStr(value) {
15
- const result = typeof value === 'string' && value.length > 2 && value[0] === '/' && value.lastIndexOf('/') > 0;
16
- return result;
17
- }
18
14
  function isRegExp(value) {
19
- const result = isRegExpStr(value);
15
+ const result = (0, _utilEx.isRegExpStr)(value);
20
16
  return result || (0, _utilEx.isRegExp)(value);
21
17
  }
22
- function toRegExp(value) {
23
- if (typeof value === 'string' && value.length > 2 && value[0] === '/') {
24
- const i = value.lastIndexOf('/');
25
- const source = value.slice(1, i);
26
- const flags = value.slice(i + 1);
27
- return new RegExp(source, flags);
28
- }
29
- }
30
18
  function getEventableMethods(aClass) {
31
19
  return {
32
20
  /**
33
21
  * Adds a listener function to the specified event type.
34
- * @param {string} type - The event type to listen for.
22
+ * @param {string|RegExp} type - The event type to listen for.
35
23
  * @param {Function} listener - The listener function to be called when the event is emitted.
36
24
  * @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
37
25
  * @throws {TypeError} If the listener is not a function.
@@ -79,7 +67,7 @@ function getEventableMethods(aClass) {
79
67
  },
80
68
  /**
81
69
  * Adds a one-time listener function to the specified event type.
82
- * @param {string} type - The event type to listen for.
70
+ * @param {string|RegExp} type - The event type to listen for.
83
71
  * @param {Function} listener - The listener function to be called once when the event is emitted.
84
72
  * @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
85
73
  * @throws {TypeError} If the listener is not a function.
@@ -235,7 +223,7 @@ function getEventableMethods(aClass) {
235
223
  },
236
224
  /**
237
225
  * Removes a listener function from the specified event type.
238
- * @param {string} type - The event type to remove the listener from.
226
+ * @param {string|RegExp} type - The event type to remove the listener from.
239
227
  * @param {Function} listener - The listener function to be removed.
240
228
  * @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
241
229
  * @throws {TypeError} If the listener is not a function.
@@ -289,7 +277,7 @@ function getEventableMethods(aClass) {
289
277
  },
290
278
  /**
291
279
  * Removes all listener functions from the specified event type.
292
- * @param {string} type - The event type to remove the listener from.
280
+ * @param {string|RegExp} type - The event type to remove the listener from.
293
281
  * @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
294
282
  * @throws {TypeError} If the listener is not a function.
295
283
  */
@@ -325,7 +313,7 @@ function getEventableMethods(aClass) {
325
313
  }
326
314
  if (regExpEvents) {
327
315
  for (const key in regExpEvents) {
328
- this.removeAllListeners(toRegExp(key));
316
+ this.removeAllListeners((0, _utilEx.toRegExp)(key));
329
317
  }
330
318
  }
331
319
  this.removeAllListeners('removeListener');
@@ -380,7 +368,7 @@ function _emit(type, msg) {
380
368
  if (regExpEvents) {
381
369
  const matched = [];
382
370
  for (let key in regExpEvents) {
383
- key = toRegExp(key);
371
+ key = (0, _utilEx.toRegExp)(key);
384
372
  if (key && key.test(type)) {
385
373
  const listener = regExpEvents[key];
386
374
  if ((0, _utilEx.isArray)(listener)) {
@@ -8,28 +8,28 @@ export class EventEmitter {
8
8
 
9
9
  /**
10
10
  * Adds a listener function to the specified event type.
11
- * @param {string} type - The event type to listen for.
11
+ * @param {string|RegExp} type - The event type to listen for.
12
12
  * @param {Function} listener - The listener function to be called when the event is emitted.
13
13
  * @returns {EventEmitter} The EventEmitter instance to allow chaining.
14
14
  * @throws {TypeError} If the listener is not a function.
15
15
  */
16
- on(eventName: string, listener: ListenerCallbackFunc): EventEmitter;
16
+ on(eventName: string|RegExp, listener: ListenerCallbackFunc): EventEmitter;
17
17
  /**
18
18
  * Adds a one-time listener function to the specified event type.
19
- * @param {string} type - The event type to listen for.
19
+ * @param {string|RegExp} type - The event type to listen for.
20
20
  * @param {Function} listener - The listener function to be called once when the event is emitted.
21
21
  * @returns {EventEmitter} The EventEmitter instance to allow chaining.
22
22
  * @throws {TypeError} If the listener is not a function.
23
23
  */
24
- once(eventName: string, listener: ListenerCallbackFunc): EventEmitter;
24
+ once(eventName: string|RegExp, listener: ListenerCallbackFunc): EventEmitter;
25
25
  /**
26
26
  * Removes a listener function from the specified event type.
27
- * @param {string} type - The event type to remove the listener from.
27
+ * @param {string|RegExp} type - The event type to remove the listener from.
28
28
  * @param {Function} listener - The listener function to be removed.
29
29
  * @returns {EventEmitter} The EventEmitter instance to allow chaining.
30
30
  * @throws {TypeError} If the listener is not a function.
31
31
  */
32
- off(eventName: string, listener: ListenerCallbackFunc): EventEmitter;
32
+ off(eventName: string|RegExp, listener: ListenerCallbackFunc): EventEmitter;
33
33
  /**
34
34
  * Emits the specified event type with the given arguments.
35
35
  * @param {...*} args - The event type followed by any number of arguments to be passed to the listener functions.
@@ -45,26 +45,33 @@ export class EventEmitter {
45
45
  /**
46
46
  * Removes all listeners for a specific event or all events from an event emitter.
47
47
  *
48
- * @param {string} [eventName] - The event to remove listeners for. If not provided, all listeners for all events will be removed.
48
+ * @param {string|RegExp} [eventName] - The event to remove listeners for. If not provided, all listeners for all events will be removed.
49
49
  * @returns {EventEmitter} - The event emitter with all listeners removed.
50
50
  */
51
- removeAllListeners(eventName?: string): EventEmitter;
51
+ removeAllListeners(eventName?: string|RegExp): EventEmitter;
52
52
  setMaxListeners(n: number): EventEmitter;
53
53
  /**
54
54
  * Returns an array of functions that are registered to listen for the specified event.
55
55
  *
56
- * @param {string} eventName - The name of the event to get the listeners for.
56
+ * @param {string|RegExp} eventName - The name of the event to get the listeners for.
57
57
  * @returns {ListenerCallbackFunc[]} - An array of functions that are registered to listen for the specified event.
58
58
  */
59
- listeners(eventName: string): ListenerCallbackFunc[];
59
+ listeners(eventName: string|RegExp): ListenerCallbackFunc[];
60
60
  /**
61
61
  * Returns the count of listeners that are registered to listen for the specified event.
62
62
  *
63
- * @param {string} eventName - The name of the event to get the listeners for.
63
+ * @param {string|RegExp} eventName - The name of the event to get the listeners for.
64
64
  * @returns {number} - the listeners count
65
65
  */
66
- listenerCount(eventName: string): number;
67
- static listenerCount(emitter: EventEmitter, eventName: string): number; // Deprecated
66
+ listenerCount(eventName: string|RegExp): number;
67
+ /**
68
+ * Returns the count of listeners that are registered to listen for the specified event.
69
+ *
70
+ * @deprecated use emitter.listenerCount instead
71
+ * @param emitter
72
+ * @param eventName
73
+ */
74
+ static listenerCount(emitter: EventEmitter, eventName: string|RegExp): number; // Deprecated
68
75
  }
69
76
 
70
77
  export default EventEmitter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "events-ex",
3
- "version": "2.0.0-alpha.13",
3
+ "version": "2.0.0-alpha.15",
4
4
  "description": "Browser-friendly enhanced events most compatible with standard node.js, it's powerful eventable ability.",
5
5
  "contributors": [
6
6
  {
@@ -38,7 +38,7 @@
38
38
  "module": "./src/index.js",
39
39
  "dependencies": {
40
40
  "custom-ability": "^2.0.0-alpha.6",
41
- "util-ex": "^2.0.0-alpha.10"
41
+ "util-ex": "^2.0.0-alpha.11"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@antfu/eslint-config": "^2.6.1",
@@ -1,4 +1,4 @@
1
- import {defineProperty, isArray, isFunction, isNumber, isObject, isRegExp as _isRegExp, isUndefined} from 'util-ex'
1
+ import {defineProperty, isArray, isFunction, isNumber, isObject, isRegExp as _isRegExp, isUndefined, isRegExpStr, toRegExp } from 'util-ex'
2
2
  import {RegExpEventSymbol} from './consts'
3
3
  import {Event} from './event';
4
4
 
@@ -6,30 +6,16 @@ const create = Object.create
6
6
  const UnCAUGHT_ERR = "Uncaught, unspecified 'error' event."
7
7
  const slice = Array.prototype.slice
8
8
 
9
- function isRegExpStr(value) {
10
- const result = typeof value === 'string' && value.length > 2 && value[0] === '/' && value.lastIndexOf('/') > 0
11
- return result
12
- }
13
-
14
9
  function isRegExp(value) {
15
10
  const result = isRegExpStr(value)
16
11
  return result || _isRegExp(value)
17
12
  }
18
13
 
19
- function toRegExp(value) {
20
- if (typeof value === 'string' && value.length > 2 && value[0] === '/') {
21
- const i = value.lastIndexOf('/')
22
- const source = value.slice(1, i)
23
- const flags = value.slice(i+1)
24
- return new RegExp(source, flags)
25
- }
26
- }
27
-
28
14
  export function getEventableMethods(aClass) {
29
15
  return {
30
16
  /**
31
17
  * Adds a listener function to the specified event type.
32
- * @param {string} type - The event type to listen for.
18
+ * @param {string|RegExp} type - The event type to listen for.
33
19
  * @param {Function} listener - The listener function to be called when the event is emitted.
34
20
  * @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
35
21
  * @throws {TypeError} If the listener is not a function.
@@ -81,7 +67,7 @@ export function getEventableMethods(aClass) {
81
67
 
82
68
  /**
83
69
  * Adds a one-time listener function to the specified event type.
84
- * @param {string} type - The event type to listen for.
70
+ * @param {string|RegExp} type - The event type to listen for.
85
71
  * @param {Function} listener - The listener function to be called once when the event is emitted.
86
72
  * @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
87
73
  * @throws {TypeError} If the listener is not a function.
@@ -226,7 +212,7 @@ export function getEventableMethods(aClass) {
226
212
 
227
213
  /**
228
214
  * Removes a listener function from the specified event type.
229
- * @param {string} type - The event type to remove the listener from.
215
+ * @param {string|RegExp} type - The event type to remove the listener from.
230
216
  * @param {Function} listener - The listener function to be removed.
231
217
  * @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
232
218
  * @throws {TypeError} If the listener is not a function.
@@ -267,7 +253,7 @@ export function getEventableMethods(aClass) {
267
253
 
268
254
  /**
269
255
  * Removes all listener functions from the specified event type.
270
- * @param {string} type - The event type to remove the listener from.
256
+ * @param {string|RegExp} type - The event type to remove the listener from.
271
257
  * @returns {import('./event-emitter').EventEmitter} The EventEmitter instance to allow chaining.
272
258
  * @throws {TypeError} If the listener is not a function.
273
259
  */
@@ -8,28 +8,28 @@ export class EventEmitter {
8
8
 
9
9
  /**
10
10
  * Adds a listener function to the specified event type.
11
- * @param {string} type - The event type to listen for.
11
+ * @param {string|RegExp} type - The event type to listen for.
12
12
  * @param {Function} listener - The listener function to be called when the event is emitted.
13
13
  * @returns {EventEmitter} The EventEmitter instance to allow chaining.
14
14
  * @throws {TypeError} If the listener is not a function.
15
15
  */
16
- on(eventName: string, listener: ListenerCallbackFunc): EventEmitter;
16
+ on(eventName: string|RegExp, listener: ListenerCallbackFunc): EventEmitter;
17
17
  /**
18
18
  * Adds a one-time listener function to the specified event type.
19
- * @param {string} type - The event type to listen for.
19
+ * @param {string|RegExp} type - The event type to listen for.
20
20
  * @param {Function} listener - The listener function to be called once when the event is emitted.
21
21
  * @returns {EventEmitter} The EventEmitter instance to allow chaining.
22
22
  * @throws {TypeError} If the listener is not a function.
23
23
  */
24
- once(eventName: string, listener: ListenerCallbackFunc): EventEmitter;
24
+ once(eventName: string|RegExp, listener: ListenerCallbackFunc): EventEmitter;
25
25
  /**
26
26
  * Removes a listener function from the specified event type.
27
- * @param {string} type - The event type to remove the listener from.
27
+ * @param {string|RegExp} type - The event type to remove the listener from.
28
28
  * @param {Function} listener - The listener function to be removed.
29
29
  * @returns {EventEmitter} The EventEmitter instance to allow chaining.
30
30
  * @throws {TypeError} If the listener is not a function.
31
31
  */
32
- off(eventName: string, listener: ListenerCallbackFunc): EventEmitter;
32
+ off(eventName: string|RegExp, listener: ListenerCallbackFunc): EventEmitter;
33
33
  /**
34
34
  * Emits the specified event type with the given arguments.
35
35
  * @param {...*} args - The event type followed by any number of arguments to be passed to the listener functions.
@@ -45,26 +45,33 @@ export class EventEmitter {
45
45
  /**
46
46
  * Removes all listeners for a specific event or all events from an event emitter.
47
47
  *
48
- * @param {string} [eventName] - The event to remove listeners for. If not provided, all listeners for all events will be removed.
48
+ * @param {string|RegExp} [eventName] - The event to remove listeners for. If not provided, all listeners for all events will be removed.
49
49
  * @returns {EventEmitter} - The event emitter with all listeners removed.
50
50
  */
51
- removeAllListeners(eventName?: string): EventEmitter;
51
+ removeAllListeners(eventName?: string|RegExp): EventEmitter;
52
52
  setMaxListeners(n: number): EventEmitter;
53
53
  /**
54
54
  * Returns an array of functions that are registered to listen for the specified event.
55
55
  *
56
- * @param {string} eventName - The name of the event to get the listeners for.
56
+ * @param {string|RegExp} eventName - The name of the event to get the listeners for.
57
57
  * @returns {ListenerCallbackFunc[]} - An array of functions that are registered to listen for the specified event.
58
58
  */
59
- listeners(eventName: string): ListenerCallbackFunc[];
59
+ listeners(eventName: string|RegExp): ListenerCallbackFunc[];
60
60
  /**
61
61
  * Returns the count of listeners that are registered to listen for the specified event.
62
62
  *
63
- * @param {string} eventName - The name of the event to get the listeners for.
63
+ * @param {string|RegExp} eventName - The name of the event to get the listeners for.
64
64
  * @returns {number} - the listeners count
65
65
  */
66
- listenerCount(eventName: string): number;
67
- static listenerCount(emitter: EventEmitter, eventName: string): number; // Deprecated
66
+ listenerCount(eventName: string|RegExp): number;
67
+ /**
68
+ * Returns the count of listeners that are registered to listen for the specified event.
69
+ *
70
+ * @deprecated use emitter.listenerCount instead
71
+ * @param emitter
72
+ * @param eventName
73
+ */
74
+ static listenerCount(emitter: EventEmitter, eventName: string|RegExp): number; // Deprecated
68
75
  }
69
76
 
70
77
  export default EventEmitter;