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