dualsense-ts 2.1.39 → 2.2.1

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.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/dist/elements/analog.d.ts +46 -3
  3. package/dist/elements/analog.d.ts.map +1 -1
  4. package/dist/elements/analog.js +41 -14
  5. package/dist/elements/analog.js.map +1 -1
  6. package/dist/elements/axis.js +3 -3
  7. package/dist/elements/axis.js.map +1 -1
  8. package/dist/elements/unisense.js +1 -1
  9. package/dist/elements/unisense.js.map +1 -1
  10. package/dist/input.d.ts +27 -0
  11. package/dist/input.d.ts.map +1 -1
  12. package/dist/input.js +9 -3
  13. package/dist/input.js.map +1 -1
  14. package/docs/Analog.md +81 -90
  15. package/docs/AnalogParams.md +7 -7
  16. package/docs/Axis.md +72 -79
  17. package/docs/Brightness.md +8 -8
  18. package/docs/CommandScopeA.md +16 -16
  19. package/docs/CommandScopeB.md +14 -14
  20. package/docs/Dpad.md +74 -81
  21. package/docs/DpadParams.md +8 -8
  22. package/docs/DualSenseCommand.md +45 -45
  23. package/docs/Dualsense.md +83 -90
  24. package/docs/DualsenseHID.md +47 -42
  25. package/docs/DualsenseHIDState.md +41 -41
  26. package/docs/DualsenseParams.md +17 -17
  27. package/docs/Exports.md +18 -21
  28. package/docs/Haptic.md +1 -1
  29. package/docs/Home.md +29 -31
  30. package/docs/Indicator.md +2 -2
  31. package/docs/Input.md +70 -79
  32. package/docs/InputId.md +84 -84
  33. package/docs/InputParams.md +4 -4
  34. package/docs/LedOptions.md +10 -10
  35. package/docs/Momentary.md +70 -77
  36. package/docs/Motion.md +2 -2
  37. package/docs/Mute.md +71 -89
  38. package/docs/PlayerID.md +12 -12
  39. package/docs/PulseOptions.md +8 -8
  40. package/docs/Touchpad.md +120 -94
  41. package/docs/Trigger.md +75 -82
  42. package/docs/TriggerMode.md +22 -22
  43. package/docs/Unisense.md +74 -81
  44. package/docs/UnisenseParams.md +7 -7
  45. package/package.json +2 -2
  46. package/src/elements/analog.spec.ts +17 -0
  47. package/src/elements/analog.ts +56 -18
  48. package/src/elements/axis.spec.ts +31 -0
  49. package/src/elements/axis.ts +3 -3
  50. package/src/elements/unisense.ts +1 -1
  51. package/src/input.ts +27 -9
  52. package/docs/Increment.md +0 -1554
  53. package/docs/Touch.md +0 -1781
package/docs/Increment.md DELETED
@@ -1,1554 +0,0 @@
1
- # Class: Increment
2
-
3
- ## Hierarchy
4
-
5
- - [`Input`](../wiki/Input)<`number`\>
6
-
7
- ↳ **`Increment`**
8
-
9
- ## Table of contents
10
-
11
- ### Constructors
12
-
13
- - [constructor](../wiki/Increment#constructor)
14
-
15
- ### Properties
16
-
17
- - [[InputChanged]](../wiki/Increment#%5Binputchanged%5D)
18
- - [[InputChildless]](../wiki/Increment#%5Binputchildless%5D)
19
- - [[InputIcon]](../wiki/Increment#%5Binputicon%5D)
20
- - [[InputName]](../wiki/Increment#%5Binputname%5D)
21
- - [[InputParent]](../wiki/Increment#%5Binputparent%5D)
22
- - [id](../wiki/Increment#id)
23
- - [lastChange](../wiki/Increment#lastchange)
24
- - [lastInput](../wiki/Increment#lastinput)
25
- - [state](../wiki/Increment#state)
26
- - [threshold](../wiki/Increment#threshold)
27
- - [captureRejectionSymbol](../wiki/Increment#capturerejectionsymbol)
28
- - [captureRejections](../wiki/Increment#capturerejections)
29
- - [defaultMaxListeners](../wiki/Increment#defaultmaxlisteners)
30
- - [errorMonitor](../wiki/Increment#errormonitor)
31
-
32
- ### Accessors
33
-
34
- - [[toStringTag]](../wiki/Increment#%5Btostringtag%5D)
35
- - [active](../wiki/Increment#active)
36
-
37
- ### Methods
38
-
39
- - [[InputAdopt]](../wiki/Increment#%5Binputadopt%5D)
40
- - [[InputChangedPrimitive]](../wiki/Increment#%5Binputchangedprimitive%5D)
41
- - [[InputChangedThreshold]](../wiki/Increment#%5Binputchangedthreshold%5D)
42
- - [[InputChangedVirtual]](../wiki/Increment#%5Binputchangedvirtual%5D)
43
- - [[InputSetComparison]](../wiki/Increment#%5Binputsetcomparison%5D)
44
- - [[InputSet]](../wiki/Increment#%5Binputset%5D)
45
- - [[asyncIterator]](../wiki/Increment#%5Basynciterator%5D)
46
- - [[custom]](../wiki/Increment#%5Bcustom%5D)
47
- - [[toPrimitive]](../wiki/Increment#%5Btoprimitive%5D)
48
- - [addListener](../wiki/Increment#addlistener)
49
- - [emit](../wiki/Increment#emit)
50
- - [eventNames](../wiki/Increment#eventnames)
51
- - [getMaxListeners](../wiki/Increment#getmaxlisteners)
52
- - [listenerCount](../wiki/Increment#listenercount)
53
- - [listeners](../wiki/Increment#listeners)
54
- - [next](../wiki/Increment#next)
55
- - [off](../wiki/Increment#off)
56
- - [on](../wiki/Increment#on)
57
- - [once](../wiki/Increment#once)
58
- - [prependListener](../wiki/Increment#prependlistener)
59
- - [prependOnceListener](../wiki/Increment#prependoncelistener)
60
- - [promise](../wiki/Increment#promise)
61
- - [rawListeners](../wiki/Increment#rawlisteners)
62
- - [removeAllListeners](../wiki/Increment#removealllisteners)
63
- - [removeListener](../wiki/Increment#removelistener)
64
- - [setMaxListeners](../wiki/Increment#setmaxlisteners)
65
- - [toString](../wiki/Increment#tostring)
66
- - [getEventListeners](../wiki/Increment#geteventlisteners)
67
- - [listenerCount](../wiki/Increment#listenercount-1)
68
- - [on](../wiki/Increment#on-1)
69
- - [once](../wiki/Increment#once-1)
70
- - [setMaxListeners](../wiki/Increment#setmaxlisteners-1)
71
-
72
- ## Constructors
73
-
74
- ### constructor
75
-
76
- • **new Increment**(`params?`)
77
-
78
- #### Parameters
79
-
80
- | Name | Type |
81
- | :------ | :------ |
82
- | `params?` | [`InputParams`](../wiki/InputParams) |
83
-
84
- #### Inherited from
85
-
86
- [Input](../wiki/Input).[constructor](../wiki/Input#constructor)
87
-
88
- #### Defined in
89
-
90
- [src/input.ts:106](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L106)
91
-
92
- ## Properties
93
-
94
- ### [InputChanged]
95
-
96
- • **[InputChanged]**: (`state`: `number`, `newState`: `number`) => `boolean`
97
-
98
- #### Type declaration
99
-
100
- ▸ (`state`, `newState`): `boolean`
101
-
102
- ##### Parameters
103
-
104
- | Name | Type |
105
- | :------ | :------ |
106
- | `state` | `number` |
107
- | `newState` | `number` |
108
-
109
- ##### Returns
110
-
111
- `boolean`
112
-
113
- #### Inherited from
114
-
115
- [Input](../wiki/Input).[[InputChanged]](../wiki/Input#%5Binputchanged%5D)
116
-
117
- #### Defined in
118
-
119
- [src/input.ts:128](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L128)
120
-
121
- ___
122
-
123
- ### [InputChildless]
124
-
125
- • **[InputChildless]**: `boolean` = `true`
126
-
127
- #### Inherited from
128
-
129
- [Input](../wiki/Input).[[InputChildless]](../wiki/Input#%5Binputchildless%5D)
130
-
131
- #### Defined in
132
-
133
- [src/input.ts:162](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L162)
134
-
135
- ___
136
-
137
- ### [InputIcon]
138
-
139
- • `Readonly` **[InputIcon]**: `string`
140
-
141
- #### Inherited from
142
-
143
- [Input](../wiki/Input).[[InputIcon]](../wiki/Input#%5Binputicon%5D)
144
-
145
- #### Defined in
146
-
147
- [src/input.ts:157](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L157)
148
-
149
- ___
150
-
151
- ### [InputName]
152
-
153
- • `Readonly` **[InputName]**: `string`
154
-
155
- #### Inherited from
156
-
157
- [Input](../wiki/Input).[[InputName]](../wiki/Input#%5Binputname%5D)
158
-
159
- #### Defined in
160
-
161
- [src/input.ts:154](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L154)
162
-
163
- ___
164
-
165
- ### [InputParent]
166
-
167
- • `Optional` **[InputParent]**: [`Input`](../wiki/Input)<`unknown`\>
168
-
169
- #### Inherited from
170
-
171
- [Input](../wiki/Input).[[InputParent]](../wiki/Input#%5Binputparent%5D)
172
-
173
- #### Defined in
174
-
175
- [src/input.ts:160](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L160)
176
-
177
- ___
178
-
179
- ### id
180
-
181
- • `Readonly` **id**: `symbol`
182
-
183
- #### Inherited from
184
-
185
- [Input](../wiki/Input).[id](../wiki/Input#id)
186
-
187
- #### Defined in
188
-
189
- [src/input.ts:58](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L58)
190
-
191
- ___
192
-
193
- ### lastChange
194
-
195
- • **lastChange**: `number`
196
-
197
- #### Inherited from
198
-
199
- [Input](../wiki/Input).[lastChange](../wiki/Input#lastchange)
200
-
201
- #### Defined in
202
-
203
- [src/input.ts:61](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L61)
204
-
205
- ___
206
-
207
- ### lastInput
208
-
209
- • **lastInput**: `number`
210
-
211
- #### Inherited from
212
-
213
- [Input](../wiki/Input).[lastInput](../wiki/Input#lastinput)
214
-
215
- #### Defined in
216
-
217
- [src/input.ts:64](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L64)
218
-
219
- ___
220
-
221
- ### state
222
-
223
- • **state**: `number` = `0`
224
-
225
- #### Overrides
226
-
227
- [Input](../wiki/Input).[state](../wiki/Input#state)
228
-
229
- #### Defined in
230
-
231
- [src/elements/increment.ts:4](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/elements/increment.ts#L4)
232
-
233
- ___
234
-
235
- ### threshold
236
-
237
- • **threshold**: `number` = `0`
238
-
239
- #### Inherited from
240
-
241
- [Input](../wiki/Input).[threshold](../wiki/Input#threshold)
242
-
243
- #### Defined in
244
-
245
- [src/input.ts:67](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L67)
246
-
247
- ___
248
-
249
- ### captureRejectionSymbol
250
-
251
- ▪ `Static` `Readonly` **captureRejectionSymbol**: typeof [`captureRejectionSymbol`](../wiki/Dualsense#capturerejectionsymbol)
252
-
253
- #### Inherited from
254
-
255
- [Input](../wiki/Input).[captureRejectionSymbol](../wiki/Input#capturerejectionsymbol)
256
-
257
- #### Defined in
258
-
259
- node_modules/@types/node/events.d.ts:291
260
-
261
- ___
262
-
263
- ### captureRejections
264
-
265
- ▪ `Static` **captureRejections**: `boolean`
266
-
267
- Sets or gets the default captureRejection value for all emitters.
268
-
269
- #### Inherited from
270
-
271
- [Input](../wiki/Input).[captureRejections](../wiki/Input#capturerejections)
272
-
273
- #### Defined in
274
-
275
- node_modules/@types/node/events.d.ts:296
276
-
277
- ___
278
-
279
- ### defaultMaxListeners
280
-
281
- ▪ `Static` **defaultMaxListeners**: `number`
282
-
283
- #### Inherited from
284
-
285
- [Input](../wiki/Input).[defaultMaxListeners](../wiki/Input#defaultmaxlisteners)
286
-
287
- #### Defined in
288
-
289
- node_modules/@types/node/events.d.ts:297
290
-
291
- ___
292
-
293
- ### errorMonitor
294
-
295
- ▪ `Static` `Readonly` **errorMonitor**: typeof [`errorMonitor`](../wiki/Dualsense#errormonitor)
296
-
297
- This symbol shall be used to install a listener for only monitoring `'error'`
298
- events. Listeners installed using this symbol are called before the regular
299
- `'error'` listeners are called.
300
-
301
- Installing a listener using this symbol does not change the behavior once an
302
- `'error'` event is emitted, therefore the process will still crash if no
303
- regular `'error'` listener is installed.
304
-
305
- #### Inherited from
306
-
307
- [Input](../wiki/Input).[errorMonitor](../wiki/Input#errormonitor)
308
-
309
- #### Defined in
310
-
311
- node_modules/@types/node/events.d.ts:290
312
-
313
- ## Accessors
314
-
315
- ### [toStringTag]
316
-
317
- • `get` **[toStringTag]**(): `string`
318
-
319
- #### Returns
320
-
321
- `string`
322
-
323
- #### Inherited from
324
-
325
- Input.\_\_@toStringTag@66
326
-
327
- #### Defined in
328
-
329
- [src/input.ts:149](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L149)
330
-
331
- ___
332
-
333
- ### active
334
-
335
- • `get` **active**(): `boolean`
336
-
337
- #### Returns
338
-
339
- `boolean`
340
-
341
- #### Overrides
342
-
343
- Input.active
344
-
345
- #### Defined in
346
-
347
- [src/elements/increment.ts:6](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/elements/increment.ts#L6)
348
-
349
- ## Methods
350
-
351
- ### [InputAdopt]
352
-
353
- ▸ **[InputAdopt]**(): `void`
354
-
355
- Cascade events from nested Inputs.
356
- And decide if this is the root Input.
357
-
358
- #### Returns
359
-
360
- `void`
361
-
362
- #### Inherited from
363
-
364
- [Input](../wiki/Input).[[InputAdopt]](../wiki/Input#%5Binputadopt%5D)
365
-
366
- #### Defined in
367
-
368
- [src/input.ts:168](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L168)
369
-
370
- ___
371
-
372
- ### [InputChangedPrimitive]
373
-
374
- ▸ **[InputChangedPrimitive]**(`state`, `newState`): `boolean`
375
-
376
- #### Parameters
377
-
378
- | Name | Type |
379
- | :------ | :------ |
380
- | `state` | `number` |
381
- | `newState` | `number` |
382
-
383
- #### Returns
384
-
385
- `boolean`
386
-
387
- #### Inherited from
388
-
389
- [Input](../wiki/Input).[[InputChangedPrimitive]](../wiki/Input#%5Binputchangedprimitive%5D)
390
-
391
- #### Defined in
392
-
393
- [src/input.ts:190](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L190)
394
-
395
- ___
396
-
397
- ### [InputChangedThreshold]
398
-
399
- ▸ **[InputChangedThreshold]**(`state`, `newState`): `boolean`
400
-
401
- #### Parameters
402
-
403
- | Name | Type |
404
- | :------ | :------ |
405
- | `state` | `number` |
406
- | `newState` | `number` |
407
-
408
- #### Returns
409
-
410
- `boolean`
411
-
412
- #### Inherited from
413
-
414
- [Input](../wiki/Input).[[InputChangedThreshold]](../wiki/Input#%5Binputchangedthreshold%5D)
415
-
416
- #### Defined in
417
-
418
- [src/input.ts:194](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L194)
419
-
420
- ___
421
-
422
- ### [InputChangedVirtual]
423
-
424
- ▸ **[InputChangedVirtual]**(): `boolean`
425
-
426
- #### Returns
427
-
428
- `boolean`
429
-
430
- #### Inherited from
431
-
432
- [Input](../wiki/Input).[[InputChangedVirtual]](../wiki/Input#%5Binputchangedvirtual%5D)
433
-
434
- #### Defined in
435
-
436
- [src/input.ts:186](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L186)
437
-
438
- ___
439
-
440
- ### [InputSetComparison]
441
-
442
- ▸ **[InputSetComparison]**(): (`state`: `number`, `newState`: `number`) => `boolean`
443
-
444
- #### Returns
445
-
446
- `fn`
447
-
448
- ▸ (`state`, `newState`): `boolean`
449
-
450
- ##### Parameters
451
-
452
- | Name | Type |
453
- | :------ | :------ |
454
- | `state` | `number` |
455
- | `newState` | `number` |
456
-
457
- ##### Returns
458
-
459
- `boolean`
460
-
461
- #### Inherited from
462
-
463
- [Input](../wiki/Input).[[InputSetComparison]](../wiki/Input#%5Binputsetcomparison%5D)
464
-
465
- #### Defined in
466
-
467
- [src/input.ts:199](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L199)
468
-
469
- ___
470
-
471
- ### [InputSet]
472
-
473
- ▸ **[InputSet]**(`state`): `void`
474
-
475
- Update the input's state and trigger all necessary callbacks.
476
-
477
- #### Parameters
478
-
479
- | Name | Type |
480
- | :------ | :------ |
481
- | `state` | `number` |
482
-
483
- #### Returns
484
-
485
- `void`
486
-
487
- #### Inherited from
488
-
489
- [Input](../wiki/Input).[[InputSet]](../wiki/Input#%5Binputset%5D)
490
-
491
- #### Defined in
492
-
493
- [src/input.ts:215](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L215)
494
-
495
- ___
496
-
497
- ### [asyncIterator]
498
-
499
- ▸ **[asyncIterator]**(): `AsyncIterator`<[`Increment`](../wiki/Increment), `any`, `undefined`\>
500
-
501
- #### Returns
502
-
503
- `AsyncIterator`<[`Increment`](../wiki/Increment), `any`, `undefined`\>
504
-
505
- #### Inherited from
506
-
507
- [Input](../wiki/Input).[[asyncIterator]](../wiki/Input#%5Basynciterator%5D)
508
-
509
- #### Defined in
510
-
511
- [src/input.ts:139](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L139)
512
-
513
- ___
514
-
515
- ### [custom]
516
-
517
- ▸ **[custom]**(): `string`
518
-
519
- #### Returns
520
-
521
- `string`
522
-
523
- #### Inherited from
524
-
525
- [Input](../wiki/Input).[[custom]](../wiki/Input#%5Bcustom%5D)
526
-
527
- #### Defined in
528
-
529
- [src/input.ts:131](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L131)
530
-
531
- ___
532
-
533
- ### [toPrimitive]
534
-
535
- ▸ **[toPrimitive]**(`hint`): `string` \| `number`
536
-
537
- #### Parameters
538
-
539
- | Name | Type |
540
- | :------ | :------ |
541
- | `hint` | ``"string"`` \| ``"number"`` \| ``"default"`` |
542
-
543
- #### Returns
544
-
545
- `string` \| `number`
546
-
547
- #### Inherited from
548
-
549
- [Input](../wiki/Input).[[toPrimitive]](../wiki/Input#%5Btoprimitive%5D)
550
-
551
- #### Defined in
552
-
553
- [src/input.ts:143](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L143)
554
-
555
- ___
556
-
557
- ### addListener
558
-
559
- ▸ **addListener**(`eventName`, `listener`): [`Increment`](../wiki/Increment)
560
-
561
- Alias for `emitter.on(eventName, listener)`.
562
-
563
- **`since`** v0.1.26
564
-
565
- #### Parameters
566
-
567
- | Name | Type |
568
- | :------ | :------ |
569
- | `eventName` | `string` \| `symbol` |
570
- | `listener` | (...`args`: `any`[]) => `void` |
571
-
572
- #### Returns
573
-
574
- [`Increment`](../wiki/Increment)
575
-
576
- #### Inherited from
577
-
578
- [Input](../wiki/Input).[addListener](../wiki/Input#addlistener)
579
-
580
- #### Defined in
581
-
582
- node_modules/@types/node/events.d.ts:317
583
-
584
- ___
585
-
586
- ### emit
587
-
588
- ▸ **emit**(`event`, ...`args`): `boolean`
589
-
590
- #### Parameters
591
-
592
- | Name | Type |
593
- | :------ | :------ |
594
- | `event` | [`InputEvent`](../wiki/Exports#inputevent) |
595
- | `...args` | [[`Input`](../wiki/Input)<`number`\>, [`Input`](../wiki/Input)<`unknown`\> \| [`Input`](../wiki/Input)<`number`\>] |
596
-
597
- #### Returns
598
-
599
- `boolean`
600
-
601
- #### Inherited from
602
-
603
- [Input](../wiki/Input).[emit](../wiki/Input#emit)
604
-
605
- #### Defined in
606
-
607
- [src/input.ts:44](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L44)
608
-
609
- ___
610
-
611
- ### eventNames
612
-
613
- ▸ **eventNames**(): (`string` \| `symbol`)[]
614
-
615
- Returns an array listing the events for which the emitter has registered
616
- listeners. The values in the array are strings or `Symbol`s.
617
-
618
- ```js
619
- const EventEmitter = require('events');
620
- const myEE = new EventEmitter();
621
- myEE.on('foo', () => {});
622
- myEE.on('bar', () => {});
623
-
624
- const sym = Symbol('symbol');
625
- myEE.on(sym, () => {});
626
-
627
- console.log(myEE.eventNames());
628
- // Prints: [ 'foo', 'bar', Symbol(symbol) ]
629
- ```
630
-
631
- **`since`** v6.0.0
632
-
633
- #### Returns
634
-
635
- (`string` \| `symbol`)[]
636
-
637
- #### Inherited from
638
-
639
- [Input](../wiki/Input).[eventNames](../wiki/Input#eventnames)
640
-
641
- #### Defined in
642
-
643
- node_modules/@types/node/events.d.ts:632
644
-
645
- ___
646
-
647
- ### getMaxListeners
648
-
649
- ▸ **getMaxListeners**(): `number`
650
-
651
- Returns the current max listener value for the `EventEmitter` which is either
652
- set by `emitter.setMaxListeners(n)` or defaults to [defaultMaxListeners](../wiki/Increment#defaultmaxlisteners).
653
-
654
- **`since`** v1.0.0
655
-
656
- #### Returns
657
-
658
- `number`
659
-
660
- #### Inherited from
661
-
662
- [Input](../wiki/Input).[getMaxListeners](../wiki/Input#getmaxlisteners)
663
-
664
- #### Defined in
665
-
666
- node_modules/@types/node/events.d.ts:489
667
-
668
- ___
669
-
670
- ### listenerCount
671
-
672
- ▸ **listenerCount**(`eventName`): `number`
673
-
674
- Returns the number of listeners listening to the event named `eventName`.
675
-
676
- **`since`** v3.2.0
677
-
678
- #### Parameters
679
-
680
- | Name | Type | Description |
681
- | :------ | :------ | :------ |
682
- | `eventName` | `string` \| `symbol` | The name of the event being listened for |
683
-
684
- #### Returns
685
-
686
- `number`
687
-
688
- #### Inherited from
689
-
690
- [Input](../wiki/Input).[listenerCount](../wiki/Input#listenercount)
691
-
692
- #### Defined in
693
-
694
- node_modules/@types/node/events.d.ts:579
695
-
696
- ___
697
-
698
- ### listeners
699
-
700
- ▸ **listeners**(`eventName`): `Function`[]
701
-
702
- Returns a copy of the array of listeners for the event named `eventName`.
703
-
704
- ```js
705
- server.on('connection', (stream) => {
706
- console.log('someone connected!');
707
- });
708
- console.log(util.inspect(server.listeners('connection')));
709
- // Prints: [ [Function] ]
710
- ```
711
-
712
- **`since`** v0.1.26
713
-
714
- #### Parameters
715
-
716
- | Name | Type |
717
- | :------ | :------ |
718
- | `eventName` | `string` \| `symbol` |
719
-
720
- #### Returns
721
-
722
- `Function`[]
723
-
724
- #### Inherited from
725
-
726
- [Input](../wiki/Input).[listeners](../wiki/Input#listeners)
727
-
728
- #### Defined in
729
-
730
- node_modules/@types/node/events.d.ts:502
731
-
732
- ___
733
-
734
- ### next
735
-
736
- ▸ **next**(`type?`): `Promise`<`IteratorResult`<[`Increment`](../wiki/Increment), `any`\>\>
737
-
738
- Resolves on the next change to this input's state.
739
-
740
- #### Parameters
741
-
742
- | Name | Type | Default value |
743
- | :------ | :------ | :------ |
744
- | `type` | ``"change"`` \| ``"press"`` \| ``"release"`` | `"change"` |
745
-
746
- #### Returns
747
-
748
- `Promise`<`IteratorResult`<[`Increment`](../wiki/Increment), `any`\>\>
749
-
750
- #### Inherited from
751
-
752
- [Input](../wiki/Input).[next](../wiki/Input#next)
753
-
754
- #### Defined in
755
-
756
- [src/input.ts:78](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L78)
757
-
758
- ___
759
-
760
- ### off
761
-
762
- ▸ **off**(`eventName`, `listener`): [`Increment`](../wiki/Increment)
763
-
764
- Alias for `emitter.removeListener()`.
765
-
766
- **`since`** v10.0.0
767
-
768
- #### Parameters
769
-
770
- | Name | Type |
771
- | :------ | :------ |
772
- | `eventName` | `string` \| `symbol` |
773
- | `listener` | (...`args`: `any`[]) => `void` |
774
-
775
- #### Returns
776
-
777
- [`Increment`](../wiki/Increment)
778
-
779
- #### Inherited from
780
-
781
- [Input](../wiki/Input).[off](../wiki/Input#off)
782
-
783
- #### Defined in
784
-
785
- node_modules/@types/node/events.d.ts:462
786
-
787
- ___
788
-
789
- ### on
790
-
791
- ▸ **on**(`event`, `listener`): [`Increment`](../wiki/Increment)
792
-
793
- #### Parameters
794
-
795
- | Name | Type |
796
- | :------ | :------ |
797
- | `event` | [`InputEvent`](../wiki/Exports#inputevent) |
798
- | `listener` | (`input`: [`Input`](../wiki/Input)<`number`\>, `changed`: [`Input`](../wiki/Input)<`unknown`\>) => `unknown` |
799
-
800
- #### Returns
801
-
802
- [`Increment`](../wiki/Increment)
803
-
804
- #### Inherited from
805
-
806
- [Input](../wiki/Input).[on](../wiki/Input#on)
807
-
808
- #### Defined in
809
-
810
- [src/input.ts:37](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L37)
811
-
812
- ___
813
-
814
- ### once
815
-
816
- ▸ **once**(`eventName`, `listener`): [`Increment`](../wiki/Increment)
817
-
818
- Adds a **one-time**`listener` function for the event named `eventName`. The
819
- next time `eventName` is triggered, this listener is removed and then invoked.
820
-
821
- ```js
822
- server.once('connection', (stream) => {
823
- console.log('Ah, we have our first user!');
824
- });
825
- ```
826
-
827
- Returns a reference to the `EventEmitter`, so that calls can be chained.
828
-
829
- By default, event listeners are invoked in the order they are added. The`emitter.prependOnceListener()` method can be used as an alternative to add the
830
- event listener to the beginning of the listeners array.
831
-
832
- ```js
833
- const myEE = new EventEmitter();
834
- myEE.once('foo', () => console.log('a'));
835
- myEE.prependOnceListener('foo', () => console.log('b'));
836
- myEE.emit('foo');
837
- // Prints:
838
- // b
839
- // a
840
- ```
841
-
842
- **`since`** v0.3.0
843
-
844
- #### Parameters
845
-
846
- | Name | Type | Description |
847
- | :------ | :------ | :------ |
848
- | `eventName` | `string` \| `symbol` | The name of the event. |
849
- | `listener` | (...`args`: `any`[]) => `void` | The callback function |
850
-
851
- #### Returns
852
-
853
- [`Increment`](../wiki/Increment)
854
-
855
- #### Inherited from
856
-
857
- [Input](../wiki/Input).[once](../wiki/Input#once)
858
-
859
- #### Defined in
860
-
861
- node_modules/@types/node/events.d.ts:377
862
-
863
- ___
864
-
865
- ### prependListener
866
-
867
- ▸ **prependListener**(`eventName`, `listener`): [`Increment`](../wiki/Increment)
868
-
869
- Adds the `listener` function to the _beginning_ of the listeners array for the
870
- event named `eventName`. No checks are made to see if the `listener` has
871
- already been added. Multiple calls passing the same combination of `eventName`and `listener` will result in the `listener` being added, and called, multiple
872
- times.
873
-
874
- ```js
875
- server.prependListener('connection', (stream) => {
876
- console.log('someone connected!');
877
- });
878
- ```
879
-
880
- Returns a reference to the `EventEmitter`, so that calls can be chained.
881
-
882
- **`since`** v6.0.0
883
-
884
- #### Parameters
885
-
886
- | Name | Type | Description |
887
- | :------ | :------ | :------ |
888
- | `eventName` | `string` \| `symbol` | The name of the event. |
889
- | `listener` | (...`args`: `any`[]) => `void` | The callback function |
890
-
891
- #### Returns
892
-
893
- [`Increment`](../wiki/Increment)
894
-
895
- #### Inherited from
896
-
897
- [Input](../wiki/Input).[prependListener](../wiki/Input#prependlistener)
898
-
899
- #### Defined in
900
-
901
- node_modules/@types/node/events.d.ts:597
902
-
903
- ___
904
-
905
- ### prependOnceListener
906
-
907
- ▸ **prependOnceListener**(`eventName`, `listener`): [`Increment`](../wiki/Increment)
908
-
909
- Adds a **one-time**`listener` function for the event named `eventName` to the_beginning_ of the listeners array. The next time `eventName` is triggered, this
910
- listener is removed, and then invoked.
911
-
912
- ```js
913
- server.prependOnceListener('connection', (stream) => {
914
- console.log('Ah, we have our first user!');
915
- });
916
- ```
917
-
918
- Returns a reference to the `EventEmitter`, so that calls can be chained.
919
-
920
- **`since`** v6.0.0
921
-
922
- #### Parameters
923
-
924
- | Name | Type | Description |
925
- | :------ | :------ | :------ |
926
- | `eventName` | `string` \| `symbol` | The name of the event. |
927
- | `listener` | (...`args`: `any`[]) => `void` | The callback function |
928
-
929
- #### Returns
930
-
931
- [`Increment`](../wiki/Increment)
932
-
933
- #### Inherited from
934
-
935
- [Input](../wiki/Input).[prependOnceListener](../wiki/Input#prependoncelistener)
936
-
937
- #### Defined in
938
-
939
- node_modules/@types/node/events.d.ts:613
940
-
941
- ___
942
-
943
- ### promise
944
-
945
- ▸ **promise**(`type?`): `Promise`<[`Increment`](../wiki/Increment)\>
946
-
947
- Resolves on the next change to this input's state.
948
-
949
- #### Parameters
950
-
951
- | Name | Type | Default value |
952
- | :------ | :------ | :------ |
953
- | `type` | ``"change"`` \| ``"press"`` \| ``"release"`` | `"change"` |
954
-
955
- #### Returns
956
-
957
- `Promise`<[`Increment`](../wiki/Increment)\>
958
-
959
- #### Inherited from
960
-
961
- [Input](../wiki/Input).[promise](../wiki/Input#promise)
962
-
963
- #### Defined in
964
-
965
- [src/input.ts:91](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L91)
966
-
967
- ___
968
-
969
- ### rawListeners
970
-
971
- ▸ **rawListeners**(`eventName`): `Function`[]
972
-
973
- Returns a copy of the array of listeners for the event named `eventName`,
974
- including any wrappers (such as those created by `.once()`).
975
-
976
- ```js
977
- const emitter = new EventEmitter();
978
- emitter.once('log', () => console.log('log once'));
979
-
980
- // Returns a new Array with a function `onceWrapper` which has a property
981
- // `listener` which contains the original listener bound above
982
- const listeners = emitter.rawListeners('log');
983
- const logFnWrapper = listeners[0];
984
-
985
- // Logs "log once" to the console and does not unbind the `once` event
986
- logFnWrapper.listener();
987
-
988
- // Logs "log once" to the console and removes the listener
989
- logFnWrapper();
990
-
991
- emitter.on('log', () => console.log('log persistently'));
992
- // Will return a new Array with a single function bound by `.on()` above
993
- const newListeners = emitter.rawListeners('log');
994
-
995
- // Logs "log persistently" twice
996
- newListeners[0]();
997
- emitter.emit('log');
998
- ```
999
-
1000
- **`since`** v9.4.0
1001
-
1002
- #### Parameters
1003
-
1004
- | Name | Type |
1005
- | :------ | :------ |
1006
- | `eventName` | `string` \| `symbol` |
1007
-
1008
- #### Returns
1009
-
1010
- `Function`[]
1011
-
1012
- #### Inherited from
1013
-
1014
- [Input](../wiki/Input).[rawListeners](../wiki/Input#rawlisteners)
1015
-
1016
- #### Defined in
1017
-
1018
- node_modules/@types/node/events.d.ts:532
1019
-
1020
- ___
1021
-
1022
- ### removeAllListeners
1023
-
1024
- ▸ **removeAllListeners**(`event?`): [`Increment`](../wiki/Increment)
1025
-
1026
- Removes all listeners, or those of the specified `eventName`.
1027
-
1028
- It is bad practice to remove listeners added elsewhere in the code,
1029
- particularly when the `EventEmitter` instance was created by some other
1030
- component or module (e.g. sockets or file streams).
1031
-
1032
- Returns a reference to the `EventEmitter`, so that calls can be chained.
1033
-
1034
- **`since`** v0.1.26
1035
-
1036
- #### Parameters
1037
-
1038
- | Name | Type |
1039
- | :------ | :------ |
1040
- | `event?` | `string` \| `symbol` |
1041
-
1042
- #### Returns
1043
-
1044
- [`Increment`](../wiki/Increment)
1045
-
1046
- #### Inherited from
1047
-
1048
- [Input](../wiki/Input).[removeAllListeners](../wiki/Input#removealllisteners)
1049
-
1050
- #### Defined in
1051
-
1052
- node_modules/@types/node/events.d.ts:473
1053
-
1054
- ___
1055
-
1056
- ### removeListener
1057
-
1058
- ▸ **removeListener**(`eventName`, `listener`): [`Increment`](../wiki/Increment)
1059
-
1060
- Removes the specified `listener` from the listener array for the event named`eventName`.
1061
-
1062
- ```js
1063
- const callback = (stream) => {
1064
- console.log('someone connected!');
1065
- };
1066
- server.on('connection', callback);
1067
- // ...
1068
- server.removeListener('connection', callback);
1069
- ```
1070
-
1071
- `removeListener()` will remove, at most, one instance of a listener from the
1072
- listener array. If any single listener has been added multiple times to the
1073
- listener array for the specified `eventName`, then `removeListener()` must be
1074
- called multiple times to remove each instance.
1075
-
1076
- Once an event is emitted, all listeners attached to it at the
1077
- time of emitting are called in order. This implies that any`removeListener()` or `removeAllListeners()` calls _after_ emitting and_before_ the last listener finishes execution will
1078
- not remove them from`emit()` in progress. Subsequent events behave as expected.
1079
-
1080
- ```js
1081
- const myEmitter = new MyEmitter();
1082
-
1083
- const callbackA = () => {
1084
- console.log('A');
1085
- myEmitter.removeListener('event', callbackB);
1086
- };
1087
-
1088
- const callbackB = () => {
1089
- console.log('B');
1090
- };
1091
-
1092
- myEmitter.on('event', callbackA);
1093
-
1094
- myEmitter.on('event', callbackB);
1095
-
1096
- // callbackA removes listener callbackB but it will still be called.
1097
- // Internal listener array at time of emit [callbackA, callbackB]
1098
- myEmitter.emit('event');
1099
- // Prints:
1100
- // A
1101
- // B
1102
-
1103
- // callbackB is now removed.
1104
- // Internal listener array [callbackA]
1105
- myEmitter.emit('event');
1106
- // Prints:
1107
- // A
1108
- ```
1109
-
1110
- Because listeners are managed using an internal array, calling this will
1111
- change the position indices of any listener registered _after_ the listener
1112
- being removed. This will not impact the order in which listeners are called,
1113
- but it means that any copies of the listener array as returned by
1114
- the `emitter.listeners()` method will need to be recreated.
1115
-
1116
- When a single function has been added as a handler multiple times for a single
1117
- event (as in the example below), `removeListener()` will remove the most
1118
- recently added instance. In the example the `once('ping')`listener is removed:
1119
-
1120
- ```js
1121
- const ee = new EventEmitter();
1122
-
1123
- function pong() {
1124
- console.log('pong');
1125
- }
1126
-
1127
- ee.on('ping', pong);
1128
- ee.once('ping', pong);
1129
- ee.removeListener('ping', pong);
1130
-
1131
- ee.emit('ping');
1132
- ee.emit('ping');
1133
- ```
1134
-
1135
- Returns a reference to the `EventEmitter`, so that calls can be chained.
1136
-
1137
- **`since`** v0.1.26
1138
-
1139
- #### Parameters
1140
-
1141
- | Name | Type |
1142
- | :------ | :------ |
1143
- | `eventName` | `string` \| `symbol` |
1144
- | `listener` | (...`args`: `any`[]) => `void` |
1145
-
1146
- #### Returns
1147
-
1148
- [`Increment`](../wiki/Increment)
1149
-
1150
- #### Inherited from
1151
-
1152
- [Input](../wiki/Input).[removeListener](../wiki/Input#removelistener)
1153
-
1154
- #### Defined in
1155
-
1156
- node_modules/@types/node/events.d.ts:457
1157
-
1158
- ___
1159
-
1160
- ### setMaxListeners
1161
-
1162
- ▸ **setMaxListeners**(`n`): [`Increment`](../wiki/Increment)
1163
-
1164
- By default `EventEmitter`s will print a warning if more than `10` listeners are
1165
- added for a particular event. This is a useful default that helps finding
1166
- memory leaks. The `emitter.setMaxListeners()` method allows the limit to be
1167
- modified for this specific `EventEmitter` instance. The value can be set to`Infinity` (or `0`) to indicate an unlimited number of listeners.
1168
-
1169
- Returns a reference to the `EventEmitter`, so that calls can be chained.
1170
-
1171
- **`since`** v0.3.5
1172
-
1173
- #### Parameters
1174
-
1175
- | Name | Type |
1176
- | :------ | :------ |
1177
- | `n` | `number` |
1178
-
1179
- #### Returns
1180
-
1181
- [`Increment`](../wiki/Increment)
1182
-
1183
- #### Inherited from
1184
-
1185
- [Input](../wiki/Input).[setMaxListeners](../wiki/Input#setmaxlisteners)
1186
-
1187
- #### Defined in
1188
-
1189
- node_modules/@types/node/events.d.ts:483
1190
-
1191
- ___
1192
-
1193
- ### toString
1194
-
1195
- ▸ **toString**(): `string`
1196
-
1197
- Render a convenient debugging string.
1198
-
1199
- #### Returns
1200
-
1201
- `string`
1202
-
1203
- #### Inherited from
1204
-
1205
- [Input](../wiki/Input).[toString](../wiki/Input#tostring)
1206
-
1207
- #### Defined in
1208
-
1209
- [src/input.ts:102](https://github.com/nsfm/dualsense-ts/blob/e429a3c/src/input.ts#L102)
1210
-
1211
- ___
1212
-
1213
- ### getEventListeners
1214
-
1215
- ▸ `Static` **getEventListeners**(`emitter`, `name`): `Function`[]
1216
-
1217
- Returns a copy of the array of listeners for the event named `eventName`.
1218
-
1219
- For `EventEmitter`s this behaves exactly the same as calling `.listeners` on
1220
- the emitter.
1221
-
1222
- For `EventTarget`s this is the only way to get the event listeners for the
1223
- event target. This is useful for debugging and diagnostic purposes.
1224
-
1225
- ```js
1226
- const { getEventListeners, EventEmitter } = require('events');
1227
-
1228
- {
1229
- const ee = new EventEmitter();
1230
- const listener = () => console.log('Events are fun');
1231
- ee.on('foo', listener);
1232
- getEventListeners(ee, 'foo'); // [listener]
1233
- }
1234
- {
1235
- const et = new EventTarget();
1236
- const listener = () => console.log('Events are fun');
1237
- et.addEventListener('foo', listener);
1238
- getEventListeners(et, 'foo'); // [listener]
1239
- }
1240
- ```
1241
-
1242
- **`since`** v15.2.0, v14.17.0
1243
-
1244
- #### Parameters
1245
-
1246
- | Name | Type |
1247
- | :------ | :------ |
1248
- | `emitter` | `EventEmitter` \| `DOMEventTarget` |
1249
- | `name` | `string` \| `symbol` |
1250
-
1251
- #### Returns
1252
-
1253
- `Function`[]
1254
-
1255
- #### Inherited from
1256
-
1257
- [Input](../wiki/Input).[getEventListeners](../wiki/Input#geteventlisteners)
1258
-
1259
- #### Defined in
1260
-
1261
- node_modules/@types/node/events.d.ts:262
1262
-
1263
- ___
1264
-
1265
- ### listenerCount
1266
-
1267
- ▸ `Static` **listenerCount**(`emitter`, `eventName`): `number`
1268
-
1269
- A class method that returns the number of listeners for the given `eventName`registered on the given `emitter`.
1270
-
1271
- ```js
1272
- const { EventEmitter, listenerCount } = require('events');
1273
- const myEmitter = new EventEmitter();
1274
- myEmitter.on('event', () => {});
1275
- myEmitter.on('event', () => {});
1276
- console.log(listenerCount(myEmitter, 'event'));
1277
- // Prints: 2
1278
- ```
1279
-
1280
- **`since`** v0.9.12
1281
-
1282
- **`deprecated`** Since v3.2.0 - Use `listenerCount` instead.
1283
-
1284
- #### Parameters
1285
-
1286
- | Name | Type | Description |
1287
- | :------ | :------ | :------ |
1288
- | `emitter` | `EventEmitter` | The emitter to query |
1289
- | `eventName` | `string` \| `symbol` | The event name |
1290
-
1291
- #### Returns
1292
-
1293
- `number`
1294
-
1295
- #### Inherited from
1296
-
1297
- [Input](../wiki/Input).[listenerCount](../wiki/Input#listenercount-1)
1298
-
1299
- #### Defined in
1300
-
1301
- node_modules/@types/node/events.d.ts:234
1302
-
1303
- ___
1304
-
1305
- ### on
1306
-
1307
- ▸ `Static` **on**(`emitter`, `eventName`, `options?`): `AsyncIterableIterator`<`any`\>
1308
-
1309
- ```js
1310
- const { on, EventEmitter } = require('events');
1311
-
1312
- (async () => {
1313
- const ee = new EventEmitter();
1314
-
1315
- // Emit later on
1316
- process.nextTick(() => {
1317
- ee.emit('foo', 'bar');
1318
- ee.emit('foo', 42);
1319
- });
1320
-
1321
- for await (const event of on(ee, 'foo')) {
1322
- // The execution of this inner block is synchronous and it
1323
- // processes one event at a time (even with await). Do not use
1324
- // if concurrent execution is required.
1325
- console.log(event); // prints ['bar'] [42]
1326
- }
1327
- // Unreachable here
1328
- })();
1329
- ```
1330
-
1331
- Returns an `AsyncIterator` that iterates `eventName` events. It will throw
1332
- if the `EventEmitter` emits `'error'`. It removes all listeners when
1333
- exiting the loop. The `value` returned by each iteration is an array
1334
- composed of the emitted event arguments.
1335
-
1336
- An `AbortSignal` can be used to cancel waiting on events:
1337
-
1338
- ```js
1339
- const { on, EventEmitter } = require('events');
1340
- const ac = new AbortController();
1341
-
1342
- (async () => {
1343
- const ee = new EventEmitter();
1344
-
1345
- // Emit later on
1346
- process.nextTick(() => {
1347
- ee.emit('foo', 'bar');
1348
- ee.emit('foo', 42);
1349
- });
1350
-
1351
- for await (const event of on(ee, 'foo', { signal: ac.signal })) {
1352
- // The execution of this inner block is synchronous and it
1353
- // processes one event at a time (even with await). Do not use
1354
- // if concurrent execution is required.
1355
- console.log(event); // prints ['bar'] [42]
1356
- }
1357
- // Unreachable here
1358
- })();
1359
-
1360
- process.nextTick(() => ac.abort());
1361
- ```
1362
-
1363
- **`since`** v13.6.0, v12.16.0
1364
-
1365
- #### Parameters
1366
-
1367
- | Name | Type | Description |
1368
- | :------ | :------ | :------ |
1369
- | `emitter` | `EventEmitter` | - |
1370
- | `eventName` | `string` | The name of the event being listened for |
1371
- | `options?` | `StaticEventEmitterOptions` | - |
1372
-
1373
- #### Returns
1374
-
1375
- `AsyncIterableIterator`<`any`\>
1376
-
1377
- that iterates `eventName` events emitted by the `emitter`
1378
-
1379
- #### Inherited from
1380
-
1381
- [Input](../wiki/Input).[on](../wiki/Input#on-1)
1382
-
1383
- #### Defined in
1384
-
1385
- node_modules/@types/node/events.d.ts:217
1386
-
1387
- ___
1388
-
1389
- ### once
1390
-
1391
- ▸ `Static` **once**(`emitter`, `eventName`, `options?`): `Promise`<`any`[]\>
1392
-
1393
- Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
1394
- event or that is rejected if the `EventEmitter` emits `'error'` while waiting.
1395
- The `Promise` will resolve with an array of all the arguments emitted to the
1396
- given event.
1397
-
1398
- This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event
1399
- semantics and does not listen to the `'error'` event.
1400
-
1401
- ```js
1402
- const { once, EventEmitter } = require('events');
1403
-
1404
- async function run() {
1405
- const ee = new EventEmitter();
1406
-
1407
- process.nextTick(() => {
1408
- ee.emit('myevent', 42);
1409
- });
1410
-
1411
- const [value] = await once(ee, 'myevent');
1412
- console.log(value);
1413
-
1414
- const err = new Error('kaboom');
1415
- process.nextTick(() => {
1416
- ee.emit('error', err);
1417
- });
1418
-
1419
- try {
1420
- await once(ee, 'myevent');
1421
- } catch (err) {
1422
- console.log('error happened', err);
1423
- }
1424
- }
1425
-
1426
- run();
1427
- ```
1428
-
1429
- The special handling of the `'error'` event is only used when `events.once()`is used to wait for another event. If `events.once()` is used to wait for the
1430
- '`error'` event itself, then it is treated as any other kind of event without
1431
- special handling:
1432
-
1433
- ```js
1434
- const { EventEmitter, once } = require('events');
1435
-
1436
- const ee = new EventEmitter();
1437
-
1438
- once(ee, 'error')
1439
- .then(([err]) => console.log('ok', err.message))
1440
- .catch((err) => console.log('error', err.message));
1441
-
1442
- ee.emit('error', new Error('boom'));
1443
-
1444
- // Prints: ok boom
1445
- ```
1446
-
1447
- An `AbortSignal` can be used to cancel waiting for the event:
1448
-
1449
- ```js
1450
- const { EventEmitter, once } = require('events');
1451
-
1452
- const ee = new EventEmitter();
1453
- const ac = new AbortController();
1454
-
1455
- async function foo(emitter, event, signal) {
1456
- try {
1457
- await once(emitter, event, { signal });
1458
- console.log('event emitted!');
1459
- } catch (error) {
1460
- if (error.name === 'AbortError') {
1461
- console.error('Waiting for the event was canceled!');
1462
- } else {
1463
- console.error('There was an error', error.message);
1464
- }
1465
- }
1466
- }
1467
-
1468
- foo(ee, 'foo', ac.signal);
1469
- ac.abort(); // Abort waiting for the event
1470
- ee.emit('foo'); // Prints: Waiting for the event was canceled!
1471
- ```
1472
-
1473
- **`since`** v11.13.0, v10.16.0
1474
-
1475
- #### Parameters
1476
-
1477
- | Name | Type |
1478
- | :------ | :------ |
1479
- | `emitter` | `NodeEventTarget` |
1480
- | `eventName` | `string` \| `symbol` |
1481
- | `options?` | `StaticEventEmitterOptions` |
1482
-
1483
- #### Returns
1484
-
1485
- `Promise`<`any`[]\>
1486
-
1487
- #### Inherited from
1488
-
1489
- [Input](../wiki/Input).[once](../wiki/Input#once-1)
1490
-
1491
- #### Defined in
1492
-
1493
- node_modules/@types/node/events.d.ts:157
1494
-
1495
- ▸ `Static` **once**(`emitter`, `eventName`, `options?`): `Promise`<`any`[]\>
1496
-
1497
- #### Parameters
1498
-
1499
- | Name | Type |
1500
- | :------ | :------ |
1501
- | `emitter` | `DOMEventTarget` |
1502
- | `eventName` | `string` |
1503
- | `options?` | `StaticEventEmitterOptions` |
1504
-
1505
- #### Returns
1506
-
1507
- `Promise`<`any`[]\>
1508
-
1509
- #### Inherited from
1510
-
1511
- [Input](../wiki/Input).[once](../wiki/Input#once-1)
1512
-
1513
- #### Defined in
1514
-
1515
- node_modules/@types/node/events.d.ts:158
1516
-
1517
- ___
1518
-
1519
- ### setMaxListeners
1520
-
1521
- ▸ `Static` **setMaxListeners**(`n?`, ...`eventTargets`): `void`
1522
-
1523
- ```js
1524
- const {
1525
- setMaxListeners,
1526
- EventEmitter
1527
- } = require('events');
1528
-
1529
- const target = new EventTarget();
1530
- const emitter = new EventEmitter();
1531
-
1532
- setMaxListeners(5, target, emitter);
1533
- ```
1534
-
1535
- **`since`** v15.4.0
1536
-
1537
- #### Parameters
1538
-
1539
- | Name | Type | Description |
1540
- | :------ | :------ | :------ |
1541
- | `n?` | `number` | A non-negative number. The maximum number of listeners per `EventTarget` event. |
1542
- | `...eventTargets` | (`EventEmitter` \| `DOMEventTarget`)[] | - |
1543
-
1544
- #### Returns
1545
-
1546
- `void`
1547
-
1548
- #### Inherited from
1549
-
1550
- [Input](../wiki/Input).[setMaxListeners](../wiki/Input#setmaxlisteners-1)
1551
-
1552
- #### Defined in
1553
-
1554
- node_modules/@types/node/events.d.ts:280