@types/node 18.19.22 → 18.19.24

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 (57) hide show
  1. node v18.19/README.md +1 -1
  2. node v18.19/crypto.d.ts +1 -1
  3. node v18.19/package.json +3 -10
  4. node v18.19/ts4.8/assert/strict.d.ts +0 -8
  5. node v18.19/ts4.8/assert.d.ts +0 -985
  6. node v18.19/ts4.8/async_hooks.d.ts +0 -522
  7. node v18.19/ts4.8/buffer.d.ts +0 -2353
  8. node v18.19/ts4.8/child_process.d.ts +0 -1544
  9. node v18.19/ts4.8/cluster.d.ts +0 -432
  10. node v18.19/ts4.8/console.d.ts +0 -412
  11. node v18.19/ts4.8/constants.d.ts +0 -19
  12. node v18.19/ts4.8/crypto.d.ts +0 -4457
  13. node v18.19/ts4.8/dgram.d.ts +0 -596
  14. node v18.19/ts4.8/diagnostics_channel.d.ts +0 -546
  15. node v18.19/ts4.8/dns/promises.d.ts +0 -381
  16. node v18.19/ts4.8/dns.d.ts +0 -809
  17. node v18.19/ts4.8/dom-events.d.ts +0 -122
  18. node v18.19/ts4.8/domain.d.ts +0 -170
  19. node v18.19/ts4.8/events.d.ts +0 -819
  20. node v18.19/ts4.8/fs/promises.d.ts +0 -1205
  21. node v18.19/ts4.8/fs.d.ts +0 -4231
  22. node v18.19/ts4.8/globals.d.ts +0 -377
  23. node v18.19/ts4.8/globals.global.d.ts +0 -1
  24. node v18.19/ts4.8/http.d.ts +0 -1803
  25. node v18.19/ts4.8/http2.d.ts +0 -2386
  26. node v18.19/ts4.8/https.d.ts +0 -544
  27. node v18.19/ts4.8/index.d.ts +0 -88
  28. node v18.19/ts4.8/inspector.d.ts +0 -2739
  29. node v18.19/ts4.8/module.d.ts +0 -298
  30. node v18.19/ts4.8/net.d.ts +0 -918
  31. node v18.19/ts4.8/os.d.ts +0 -473
  32. node v18.19/ts4.8/path.d.ts +0 -191
  33. node v18.19/ts4.8/perf_hooks.d.ts +0 -626
  34. node v18.19/ts4.8/process.d.ts +0 -1548
  35. node v18.19/ts4.8/punycode.d.ts +0 -117
  36. node v18.19/ts4.8/querystring.d.ts +0 -141
  37. node v18.19/ts4.8/readline/promises.d.ts +0 -143
  38. node v18.19/ts4.8/readline.d.ts +0 -666
  39. node v18.19/ts4.8/repl.d.ts +0 -430
  40. node v18.19/ts4.8/stream/consumers.d.ts +0 -12
  41. node v18.19/ts4.8/stream/promises.d.ts +0 -83
  42. node v18.19/ts4.8/stream/web.d.ts +0 -352
  43. node v18.19/ts4.8/stream.d.ts +0 -1731
  44. node v18.19/ts4.8/string_decoder.d.ts +0 -67
  45. node v18.19/ts4.8/test.d.ts +0 -1113
  46. node v18.19/ts4.8/timers/promises.d.ts +0 -93
  47. node v18.19/ts4.8/timers.d.ts +0 -126
  48. node v18.19/ts4.8/tls.d.ts +0 -1203
  49. node v18.19/ts4.8/trace_events.d.ts +0 -171
  50. node v18.19/ts4.8/tty.d.ts +0 -206
  51. node v18.19/ts4.8/url.d.ts +0 -954
  52. node v18.19/ts4.8/util.d.ts +0 -2075
  53. node v18.19/ts4.8/v8.d.ts +0 -753
  54. node v18.19/ts4.8/vm.d.ts +0 -667
  55. node v18.19/ts4.8/wasi.d.ts +0 -158
  56. node v18.19/ts4.8/worker_threads.d.ts +0 -692
  57. node v18.19/ts4.8/zlib.d.ts +0 -517
@@ -1,819 +0,0 @@
1
- /**
2
- * Much of the Node.js core API is built around an idiomatic asynchronous
3
- * event-driven architecture in which certain kinds of objects (called "emitters")
4
- * emit named events that cause `Function` objects ("listeners") to be called.
5
- *
6
- * For instance: a `net.Server` object emits an event each time a peer
7
- * connects to it; a `fs.ReadStream` emits an event when the file is opened;
8
- * a `stream` emits an event whenever data is available to be read.
9
- *
10
- * All objects that emit events are instances of the `EventEmitter` class. These
11
- * objects expose an `eventEmitter.on()` function that allows one or more
12
- * functions to be attached to named events emitted by the object. Typically,
13
- * event names are camel-cased strings but any valid JavaScript property key
14
- * can be used.
15
- *
16
- * When the `EventEmitter` object emits an event, all of the functions attached
17
- * to that specific event are called _synchronously_. Any values returned by the
18
- * called listeners are _ignored_ and discarded.
19
- *
20
- * The following example shows a simple `EventEmitter` instance with a single
21
- * listener. The `eventEmitter.on()` method is used to register listeners, while
22
- * the `eventEmitter.emit()` method is used to trigger the event.
23
- *
24
- * ```js
25
- * const EventEmitter = require('events');
26
- *
27
- * class MyEmitter extends EventEmitter {}
28
- *
29
- * const myEmitter = new MyEmitter();
30
- * myEmitter.on('event', () => {
31
- * console.log('an event occurred!');
32
- * });
33
- * myEmitter.emit('event');
34
- * ```
35
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/events.js)
36
- */
37
- declare module "events" {
38
- import { AsyncResource, AsyncResourceOptions } from "node:async_hooks";
39
-
40
- // NOTE: This class is in the docs but is **not actually exported** by Node.
41
- // If https://github.com/nodejs/node/issues/39903 gets resolved and Node
42
- // actually starts exporting the class, uncomment below.
43
-
44
- // import { EventListener, EventListenerObject } from '__dom-events';
45
- // /** The NodeEventTarget is a Node.js-specific extension to EventTarget that emulates a subset of the EventEmitter API. */
46
- // interface NodeEventTarget extends EventTarget {
47
- // /**
48
- // * Node.js-specific extension to the `EventTarget` class that emulates the equivalent `EventEmitter` API.
49
- // * The only difference between `addListener()` and `addEventListener()` is that addListener() will return a reference to the EventTarget.
50
- // */
51
- // addListener(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this;
52
- // /** Node.js-specific extension to the `EventTarget` class that returns an array of event `type` names for which event listeners are registered. */
53
- // eventNames(): string[];
54
- // /** Node.js-specific extension to the `EventTarget` class that returns the number of event listeners registered for the `type`. */
55
- // listenerCount(type: string): number;
56
- // /** Node.js-specific alias for `eventTarget.removeListener()`. */
57
- // off(type: string, listener: EventListener | EventListenerObject): this;
58
- // /** Node.js-specific alias for `eventTarget.addListener()`. */
59
- // on(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this;
60
- // /** Node.js-specific extension to the `EventTarget` class that adds a `once` listener for the given event `type`. This is equivalent to calling `on` with the `once` option set to `true`. */
61
- // once(type: string, listener: EventListener | EventListenerObject): this;
62
- // /**
63
- // * Node.js-specific extension to the `EventTarget` class.
64
- // * If `type` is specified, removes all registered listeners for `type`,
65
- // * otherwise removes all registered listeners.
66
- // */
67
- // removeAllListeners(type: string): this;
68
- // /**
69
- // * Node.js-specific extension to the `EventTarget` class that removes the listener for the given `type`.
70
- // * The only difference between `removeListener()` and `removeEventListener()` is that `removeListener()` will return a reference to the `EventTarget`.
71
- // */
72
- // removeListener(type: string, listener: EventListener | EventListenerObject): this;
73
- // }
74
-
75
- interface EventEmitterOptions {
76
- /**
77
- * Enables automatic capturing of promise rejection.
78
- */
79
- captureRejections?: boolean | undefined;
80
- }
81
- // Any EventTarget with a Node-style `once` function
82
- interface _NodeEventTarget {
83
- once(eventName: string | symbol, listener: (...args: any[]) => void): this;
84
- }
85
- // Any EventTarget with a DOM-style `addEventListener`
86
- interface _DOMEventTarget {
87
- addEventListener(
88
- eventName: string,
89
- listener: (...args: any[]) => void,
90
- opts?: {
91
- once: boolean;
92
- },
93
- ): any;
94
- }
95
- interface StaticEventEmitterOptions {
96
- signal?: AbortSignal | undefined;
97
- }
98
- interface EventEmitter<T extends EventMap<T> = DefaultEventMap> extends NodeJS.EventEmitter<T> {}
99
- type EventMap<T> = Record<keyof T, any[]> | DefaultEventMap;
100
- type DefaultEventMap = [never];
101
- type AnyRest = [...args: any[]];
102
- type Args<K, T> = T extends DefaultEventMap ? AnyRest : (
103
- K extends keyof T ? T[K] : never
104
- );
105
- type Key<K, T> = T extends DefaultEventMap ? string | symbol : K | keyof T;
106
- type Key2<K, T> = T extends DefaultEventMap ? string | symbol : K & keyof T;
107
- type Listener<K, T, F> = T extends DefaultEventMap ? F : (
108
- K extends keyof T ? (
109
- T[K] extends unknown[] ? (...args: T[K]) => void : never
110
- )
111
- : never
112
- );
113
- type Listener1<K, T> = Listener<K, T, (...args: any[]) => void>;
114
- type Listener2<K, T> = Listener<K, T, Function>;
115
- /**
116
- * The `EventEmitter` class is defined and exposed by the `events` module:
117
- *
118
- * ```js
119
- * const EventEmitter = require('events');
120
- * ```
121
- *
122
- * All `EventEmitter`s emit the event `'newListener'` when new listeners are
123
- * added and `'removeListener'` when existing listeners are removed.
124
- *
125
- * It supports the following option:
126
- * @since v0.1.26
127
- */
128
- class EventEmitter<T extends EventMap<T> = DefaultEventMap> {
129
- constructor(options?: EventEmitterOptions);
130
-
131
- [EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
132
-
133
- /**
134
- * Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
135
- * event or that is rejected if the `EventEmitter` emits `'error'` while waiting.
136
- * The `Promise` will resolve with an array of all the arguments emitted to the
137
- * given event.
138
- *
139
- * 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
140
- * semantics and does not listen to the `'error'` event.
141
- *
142
- * ```js
143
- * const { once, EventEmitter } = require('events');
144
- *
145
- * async function run() {
146
- * const ee = new EventEmitter();
147
- *
148
- * process.nextTick(() => {
149
- * ee.emit('myevent', 42);
150
- * });
151
- *
152
- * const [value] = await once(ee, 'myevent');
153
- * console.log(value);
154
- *
155
- * const err = new Error('kaboom');
156
- * process.nextTick(() => {
157
- * ee.emit('error', err);
158
- * });
159
- *
160
- * try {
161
- * await once(ee, 'myevent');
162
- * } catch (err) {
163
- * console.log('error happened', err);
164
- * }
165
- * }
166
- *
167
- * run();
168
- * ```
169
- *
170
- * 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
171
- * '`error'` event itself, then it is treated as any other kind of event without
172
- * special handling:
173
- *
174
- * ```js
175
- * const { EventEmitter, once } = require('events');
176
- *
177
- * const ee = new EventEmitter();
178
- *
179
- * once(ee, 'error')
180
- * .then(([err]) => console.log('ok', err.message))
181
- * .catch((err) => console.log('error', err.message));
182
- *
183
- * ee.emit('error', new Error('boom'));
184
- *
185
- * // Prints: ok boom
186
- * ```
187
- *
188
- * An `AbortSignal` can be used to cancel waiting for the event:
189
- *
190
- * ```js
191
- * const { EventEmitter, once } = require('events');
192
- *
193
- * const ee = new EventEmitter();
194
- * const ac = new AbortController();
195
- *
196
- * async function foo(emitter, event, signal) {
197
- * try {
198
- * await once(emitter, event, { signal });
199
- * console.log('event emitted!');
200
- * } catch (error) {
201
- * if (error.name === 'AbortError') {
202
- * console.error('Waiting for the event was canceled!');
203
- * } else {
204
- * console.error('There was an error', error.message);
205
- * }
206
- * }
207
- * }
208
- *
209
- * foo(ee, 'foo', ac.signal);
210
- * ac.abort(); // Abort waiting for the event
211
- * ee.emit('foo'); // Prints: Waiting for the event was canceled!
212
- * ```
213
- * @since v11.13.0, v10.16.0
214
- */
215
- static once(
216
- emitter: _NodeEventTarget,
217
- eventName: string | symbol,
218
- options?: StaticEventEmitterOptions,
219
- ): Promise<any[]>;
220
- static once(emitter: _DOMEventTarget, eventName: string, options?: StaticEventEmitterOptions): Promise<any[]>;
221
- /**
222
- * ```js
223
- * const { on, EventEmitter } = require('events');
224
- *
225
- * (async () => {
226
- * const ee = new EventEmitter();
227
- *
228
- * // Emit later on
229
- * process.nextTick(() => {
230
- * ee.emit('foo', 'bar');
231
- * ee.emit('foo', 42);
232
- * });
233
- *
234
- * for await (const event of on(ee, 'foo')) {
235
- * // The execution of this inner block is synchronous and it
236
- * // processes one event at a time (even with await). Do not use
237
- * // if concurrent execution is required.
238
- * console.log(event); // prints ['bar'] [42]
239
- * }
240
- * // Unreachable here
241
- * })();
242
- * ```
243
- *
244
- * Returns an `AsyncIterator` that iterates `eventName` events. It will throw
245
- * if the `EventEmitter` emits `'error'`. It removes all listeners when
246
- * exiting the loop. The `value` returned by each iteration is an array
247
- * composed of the emitted event arguments.
248
- *
249
- * An `AbortSignal` can be used to cancel waiting on events:
250
- *
251
- * ```js
252
- * const { on, EventEmitter } = require('events');
253
- * const ac = new AbortController();
254
- *
255
- * (async () => {
256
- * const ee = new EventEmitter();
257
- *
258
- * // Emit later on
259
- * process.nextTick(() => {
260
- * ee.emit('foo', 'bar');
261
- * ee.emit('foo', 42);
262
- * });
263
- *
264
- * for await (const event of on(ee, 'foo', { signal: ac.signal })) {
265
- * // The execution of this inner block is synchronous and it
266
- * // processes one event at a time (even with await). Do not use
267
- * // if concurrent execution is required.
268
- * console.log(event); // prints ['bar'] [42]
269
- * }
270
- * // Unreachable here
271
- * })();
272
- *
273
- * process.nextTick(() => ac.abort());
274
- * ```
275
- * @since v13.6.0, v12.16.0
276
- * @param eventName The name of the event being listened for
277
- * @return that iterates `eventName` events emitted by the `emitter`
278
- */
279
- static on(
280
- emitter: NodeJS.EventEmitter,
281
- eventName: string,
282
- options?: StaticEventEmitterOptions,
283
- ): AsyncIterableIterator<any>;
284
- /**
285
- * A class method that returns the number of listeners for the given `eventName`registered on the given `emitter`.
286
- *
287
- * ```js
288
- * const { EventEmitter, listenerCount } = require('events');
289
- * const myEmitter = new EventEmitter();
290
- * myEmitter.on('event', () => {});
291
- * myEmitter.on('event', () => {});
292
- * console.log(listenerCount(myEmitter, 'event'));
293
- * // Prints: 2
294
- * ```
295
- * @since v0.9.12
296
- * @deprecated Since v3.2.0 - Use `listenerCount` instead.
297
- * @param emitter The emitter to query
298
- * @param eventName The event name
299
- */
300
- static listenerCount(emitter: NodeJS.EventEmitter, eventName: string | symbol): number;
301
- /**
302
- * Returns a copy of the array of listeners for the event named `eventName`.
303
- *
304
- * For `EventEmitter`s this behaves exactly the same as calling `.listeners` on
305
- * the emitter.
306
- *
307
- * For `EventTarget`s this is the only way to get the event listeners for the
308
- * event target. This is useful for debugging and diagnostic purposes.
309
- *
310
- * ```js
311
- * const { getEventListeners, EventEmitter } = require('events');
312
- *
313
- * {
314
- * const ee = new EventEmitter();
315
- * const listener = () => console.log('Events are fun');
316
- * ee.on('foo', listener);
317
- * getEventListeners(ee, 'foo'); // [listener]
318
- * }
319
- * {
320
- * const et = new EventTarget();
321
- * const listener = () => console.log('Events are fun');
322
- * et.addEventListener('foo', listener);
323
- * getEventListeners(et, 'foo'); // [listener]
324
- * }
325
- * ```
326
- * @since v15.2.0, v14.17.0
327
- */
328
- static getEventListeners(emitter: _DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
329
- /**
330
- * Returns the currently set max amount of listeners.
331
- *
332
- * For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on
333
- * the emitter.
334
- *
335
- * For `EventTarget`s this is the only way to get the max event listeners for the
336
- * event target. If the number of event handlers on a single EventTarget exceeds
337
- * the max set, the EventTarget will print a warning.
338
- *
339
- * ```js
340
- * import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
341
- *
342
- * {
343
- * const ee = new EventEmitter();
344
- * console.log(getMaxListeners(ee)); // 10
345
- * setMaxListeners(11, ee);
346
- * console.log(getMaxListeners(ee)); // 11
347
- * }
348
- * {
349
- * const et = new EventTarget();
350
- * console.log(getMaxListeners(et)); // 10
351
- * setMaxListeners(11, et);
352
- * console.log(getMaxListeners(et)); // 11
353
- * }
354
- * ```
355
- * @since v18.17.0
356
- */
357
- static getMaxListeners(emitter: _DOMEventTarget | NodeJS.EventEmitter): number;
358
- /**
359
- * ```js
360
- * const {
361
- * setMaxListeners,
362
- * EventEmitter
363
- * } = require('events');
364
- *
365
- * const target = new EventTarget();
366
- * const emitter = new EventEmitter();
367
- *
368
- * setMaxListeners(5, target, emitter);
369
- * ```
370
- * @since v15.4.0
371
- * @param n A non-negative number. The maximum number of listeners per `EventTarget` event.
372
- * @param eventsTargets Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter}
373
- * objects.
374
- */
375
- static setMaxListeners(n?: number, ...eventTargets: Array<_DOMEventTarget | NodeJS.EventEmitter>): void;
376
- /**
377
- * Listens once to the `abort` event on the provided `signal`.
378
- *
379
- * Listening to the `abort` event on abort signals is unsafe and may
380
- * lead to resource leaks since another third party with the signal can
381
- * call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change
382
- * this since it would violate the web standard. Additionally, the original
383
- * API makes it easy to forget to remove listeners.
384
- *
385
- * This API allows safely using `AbortSignal`s in Node.js APIs by solving these
386
- * two issues by listening to the event such that `stopImmediatePropagation` does
387
- * not prevent the listener from running.
388
- *
389
- * Returns a disposable so that it may be unsubscribed from more easily.
390
- *
391
- * ```js
392
- * import { addAbortListener } from 'node:events';
393
- *
394
- * function example(signal) {
395
- * let disposable;
396
- * try {
397
- * signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
398
- * disposable = addAbortListener(signal, (e) => {
399
- * // Do something when signal is aborted.
400
- * });
401
- * } finally {
402
- * disposable?.[Symbol.dispose]();
403
- * }
404
- * }
405
- * ```
406
- * @since v18.18.0
407
- * @experimental
408
- * @return Disposable that removes the `abort` listener.
409
- */
410
- static addAbortListener(signal: AbortSignal, resource: (event: Event) => void): Disposable;
411
- /**
412
- * This symbol shall be used to install a listener for only monitoring `'error'`
413
- * events. Listeners installed using this symbol are called before the regular
414
- * `'error'` listeners are called.
415
- *
416
- * Installing a listener using this symbol does not change the behavior once an
417
- * `'error'` event is emitted, therefore the process will still crash if no
418
- * regular `'error'` listener is installed.
419
- */
420
- static readonly errorMonitor: unique symbol;
421
- static readonly captureRejectionSymbol: unique symbol;
422
- /**
423
- * Sets or gets the default captureRejection value for all emitters.
424
- */
425
- // TODO: These should be described using static getter/setter pairs:
426
- static captureRejections: boolean;
427
- static defaultMaxListeners: number;
428
- }
429
- import internal = require("node:events");
430
- namespace EventEmitter {
431
- // Should just be `export { EventEmitter }`, but that doesn't work in TypeScript 3.4
432
- export { internal as EventEmitter };
433
- export interface Abortable {
434
- /**
435
- * When provided the corresponding `AbortController` can be used to cancel an asynchronous action.
436
- */
437
- signal?: AbortSignal | undefined;
438
- }
439
-
440
- export interface EventEmitterReferencingAsyncResource extends AsyncResource {
441
- readonly eventEmitter: EventEmitterAsyncResource;
442
- }
443
-
444
- export interface EventEmitterAsyncResourceOptions extends AsyncResourceOptions, EventEmitterOptions {
445
- /**
446
- * The type of async event, this is required when instantiating `EventEmitterAsyncResource`
447
- * directly rather than as a child class.
448
- * @default new.target.name if instantiated as a child class.
449
- */
450
- name?: string;
451
- }
452
-
453
- /**
454
- * Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that require
455
- * manual async tracking. Specifically, all events emitted by instances of
456
- * `EventEmitterAsyncResource` will run within its async context.
457
- *
458
- * The EventEmitterAsyncResource class has the same methods and takes the
459
- * same options as EventEmitter and AsyncResource themselves.
460
- * @throws if `options.name` is not provided when instantiated directly.
461
- * @since v17.4.0, v16.14.0
462
- */
463
- export class EventEmitterAsyncResource extends EventEmitter {
464
- /**
465
- * @param options Only optional in child class.
466
- */
467
- constructor(options?: EventEmitterAsyncResourceOptions);
468
- /**
469
- * Call all destroy hooks. This should only ever be called once. An
470
- * error will be thrown if it is called more than once. This must be
471
- * manually called. If the resource is left to be collected by the GC then
472
- * the destroy hooks will never be called.
473
- */
474
- emitDestroy(): void;
475
- /** The unique asyncId assigned to the resource. */
476
- readonly asyncId: number;
477
- /** The same triggerAsyncId that is passed to the AsyncResource constructor. */
478
- readonly triggerAsyncId: number;
479
- /** The underlying AsyncResource */
480
- readonly asyncResource: EventEmitterReferencingAsyncResource;
481
- }
482
- }
483
- global {
484
- namespace NodeJS {
485
- interface EventEmitter<T extends EventMap<T> = DefaultEventMap> {
486
- [EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
487
- /**
488
- * Alias for `emitter.on(eventName, listener)`.
489
- * @since v0.1.26
490
- */
491
- addListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
492
- /**
493
- * Adds the `listener` function to the end of the listeners array for the
494
- * event named `eventName`. No checks are made to see if the `listener` has
495
- * already been added. Multiple calls passing the same combination of `eventName`and `listener` will result in the `listener` being added, and called, multiple
496
- * times.
497
- *
498
- * ```js
499
- * server.on('connection', (stream) => {
500
- * console.log('someone connected!');
501
- * });
502
- * ```
503
- *
504
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
505
- *
506
- * By default, event listeners are invoked in the order they are added. The`emitter.prependListener()` method can be used as an alternative to add the
507
- * event listener to the beginning of the listeners array.
508
- *
509
- * ```js
510
- * const myEE = new EventEmitter();
511
- * myEE.on('foo', () => console.log('a'));
512
- * myEE.prependListener('foo', () => console.log('b'));
513
- * myEE.emit('foo');
514
- * // Prints:
515
- * // b
516
- * // a
517
- * ```
518
- * @since v0.1.101
519
- * @param eventName The name of the event.
520
- * @param listener The callback function
521
- */
522
- on<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
523
- /**
524
- * Adds a **one-time**`listener` function for the event named `eventName`. The
525
- * next time `eventName` is triggered, this listener is removed and then invoked.
526
- *
527
- * ```js
528
- * server.once('connection', (stream) => {
529
- * console.log('Ah, we have our first user!');
530
- * });
531
- * ```
532
- *
533
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
534
- *
535
- * 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
536
- * event listener to the beginning of the listeners array.
537
- *
538
- * ```js
539
- * const myEE = new EventEmitter();
540
- * myEE.once('foo', () => console.log('a'));
541
- * myEE.prependOnceListener('foo', () => console.log('b'));
542
- * myEE.emit('foo');
543
- * // Prints:
544
- * // b
545
- * // a
546
- * ```
547
- * @since v0.3.0
548
- * @param eventName The name of the event.
549
- * @param listener The callback function
550
- */
551
- once<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
552
- /**
553
- * Removes the specified `listener` from the listener array for the event named`eventName`.
554
- *
555
- * ```js
556
- * const callback = (stream) => {
557
- * console.log('someone connected!');
558
- * };
559
- * server.on('connection', callback);
560
- * // ...
561
- * server.removeListener('connection', callback);
562
- * ```
563
- *
564
- * `removeListener()` will remove, at most, one instance of a listener from the
565
- * listener array. If any single listener has been added multiple times to the
566
- * listener array for the specified `eventName`, then `removeListener()` must be
567
- * called multiple times to remove each instance.
568
- *
569
- * Once an event is emitted, all listeners attached to it at the
570
- * time of emitting are called in order. This implies that any`removeListener()` or `removeAllListeners()` calls _after_ emitting and _before_ the last listener finishes execution
571
- * will not remove them from`emit()` in progress. Subsequent events behave as expected.
572
- *
573
- * ```js
574
- * const myEmitter = new MyEmitter();
575
- *
576
- * const callbackA = () => {
577
- * console.log('A');
578
- * myEmitter.removeListener('event', callbackB);
579
- * };
580
- *
581
- * const callbackB = () => {
582
- * console.log('B');
583
- * };
584
- *
585
- * myEmitter.on('event', callbackA);
586
- *
587
- * myEmitter.on('event', callbackB);
588
- *
589
- * // callbackA removes listener callbackB but it will still be called.
590
- * // Internal listener array at time of emit [callbackA, callbackB]
591
- * myEmitter.emit('event');
592
- * // Prints:
593
- * // A
594
- * // B
595
- *
596
- * // callbackB is now removed.
597
- * // Internal listener array [callbackA]
598
- * myEmitter.emit('event');
599
- * // Prints:
600
- * // A
601
- * ```
602
- *
603
- * Because listeners are managed using an internal array, calling this will
604
- * change the position indices of any listener registered _after_ the listener
605
- * being removed. This will not impact the order in which listeners are called,
606
- * but it means that any copies of the listener array as returned by
607
- * the `emitter.listeners()` method will need to be recreated.
608
- *
609
- * When a single function has been added as a handler multiple times for a single
610
- * event (as in the example below), `removeListener()` will remove the most
611
- * recently added instance. In the example the `once('ping')`listener is removed:
612
- *
613
- * ```js
614
- * const ee = new EventEmitter();
615
- *
616
- * function pong() {
617
- * console.log('pong');
618
- * }
619
- *
620
- * ee.on('ping', pong);
621
- * ee.once('ping', pong);
622
- * ee.removeListener('ping', pong);
623
- *
624
- * ee.emit('ping');
625
- * ee.emit('ping');
626
- * ```
627
- *
628
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
629
- * @since v0.1.26
630
- */
631
- removeListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
632
- /**
633
- * Alias for `emitter.removeListener()`.
634
- * @since v10.0.0
635
- */
636
- off<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
637
- /**
638
- * Removes all listeners, or those of the specified `eventName`.
639
- *
640
- * It is bad practice to remove listeners added elsewhere in the code,
641
- * particularly when the `EventEmitter` instance was created by some other
642
- * component or module (e.g. sockets or file streams).
643
- *
644
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
645
- * @since v0.1.26
646
- */
647
- removeAllListeners(event?: Key<unknown, T>): this;
648
- /**
649
- * By default `EventEmitter`s will print a warning if more than `10` listeners are
650
- * added for a particular event. This is a useful default that helps finding
651
- * memory leaks. The `emitter.setMaxListeners()` method allows the limit to be
652
- * modified for this specific `EventEmitter` instance. The value can be set to`Infinity` (or `0`) to indicate an unlimited number of listeners.
653
- *
654
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
655
- * @since v0.3.5
656
- */
657
- setMaxListeners(n: number): this;
658
- /**
659
- * Returns the current max listener value for the `EventEmitter` which is either
660
- * set by `emitter.setMaxListeners(n)` or defaults to {@link defaultMaxListeners}.
661
- * @since v1.0.0
662
- */
663
- getMaxListeners(): number;
664
- /**
665
- * Returns a copy of the array of listeners for the event named `eventName`.
666
- *
667
- * ```js
668
- * server.on('connection', (stream) => {
669
- * console.log('someone connected!');
670
- * });
671
- * console.log(util.inspect(server.listeners('connection')));
672
- * // Prints: [ [Function] ]
673
- * ```
674
- * @since v0.1.26
675
- */
676
- listeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
677
- /**
678
- * Returns a copy of the array of listeners for the event named `eventName`,
679
- * including any wrappers (such as those created by `.once()`).
680
- *
681
- * ```js
682
- * const emitter = new EventEmitter();
683
- * emitter.once('log', () => console.log('log once'));
684
- *
685
- * // Returns a new Array with a function `onceWrapper` which has a property
686
- * // `listener` which contains the original listener bound above
687
- * const listeners = emitter.rawListeners('log');
688
- * const logFnWrapper = listeners[0];
689
- *
690
- * // Logs "log once" to the console and does not unbind the `once` event
691
- * logFnWrapper.listener();
692
- *
693
- * // Logs "log once" to the console and removes the listener
694
- * logFnWrapper();
695
- *
696
- * emitter.on('log', () => console.log('log persistently'));
697
- * // Will return a new Array with a single function bound by `.on()` above
698
- * const newListeners = emitter.rawListeners('log');
699
- *
700
- * // Logs "log persistently" twice
701
- * newListeners[0]();
702
- * emitter.emit('log');
703
- * ```
704
- * @since v9.4.0
705
- */
706
- rawListeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
707
- /**
708
- * Synchronously calls each of the listeners registered for the event named`eventName`, in the order they were registered, passing the supplied arguments
709
- * to each.
710
- *
711
- * Returns `true` if the event had listeners, `false` otherwise.
712
- *
713
- * ```js
714
- * const EventEmitter = require('events');
715
- * const myEmitter = new EventEmitter();
716
- *
717
- * // First listener
718
- * myEmitter.on('event', function firstListener() {
719
- * console.log('Helloooo! first listener');
720
- * });
721
- * // Second listener
722
- * myEmitter.on('event', function secondListener(arg1, arg2) {
723
- * console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
724
- * });
725
- * // Third listener
726
- * myEmitter.on('event', function thirdListener(...args) {
727
- * const parameters = args.join(', ');
728
- * console.log(`event with parameters ${parameters} in third listener`);
729
- * });
730
- *
731
- * console.log(myEmitter.listeners('event'));
732
- *
733
- * myEmitter.emit('event', 1, 2, 3, 4, 5);
734
- *
735
- * // Prints:
736
- * // [
737
- * // [Function: firstListener],
738
- * // [Function: secondListener],
739
- * // [Function: thirdListener]
740
- * // ]
741
- * // Helloooo! first listener
742
- * // event with parameters 1, 2 in second listener
743
- * // event with parameters 1, 2, 3, 4, 5 in third listener
744
- * ```
745
- * @since v0.1.26
746
- */
747
- emit<K>(eventName: Key<K, T>, ...args: Args<K, T>): boolean;
748
- /**
749
- * Returns the number of listeners listening to the event named `eventName`.
750
- *
751
- * If `listener` is provided, it will return how many times the listener
752
- * is found in the list of the listeners of the event.
753
- * @since v3.2.0
754
- * @param eventName The name of the event being listened for
755
- * @param listener The event handler function
756
- */
757
- listenerCount<K>(eventName: Key<K, T>, listener?: Listener2<K, T>): number;
758
- /**
759
- * Adds the `listener` function to the _beginning_ of the listeners array for the
760
- * event named `eventName`. No checks are made to see if the `listener` has
761
- * already been added. Multiple calls passing the same combination of `eventName`and `listener` will result in the `listener` being added, and called, multiple
762
- * times.
763
- *
764
- * ```js
765
- * server.prependListener('connection', (stream) => {
766
- * console.log('someone connected!');
767
- * });
768
- * ```
769
- *
770
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
771
- * @since v6.0.0
772
- * @param eventName The name of the event.
773
- * @param listener The callback function
774
- */
775
- prependListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
776
- /**
777
- * 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
778
- * listener is removed, and then invoked.
779
- *
780
- * ```js
781
- * server.prependOnceListener('connection', (stream) => {
782
- * console.log('Ah, we have our first user!');
783
- * });
784
- * ```
785
- *
786
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
787
- * @since v6.0.0
788
- * @param eventName The name of the event.
789
- * @param listener The callback function
790
- */
791
- prependOnceListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
792
- /**
793
- * Returns an array listing the events for which the emitter has registered
794
- * listeners. The values in the array are strings or `Symbol`s.
795
- *
796
- * ```js
797
- * const EventEmitter = require('events');
798
- * const myEE = new EventEmitter();
799
- * myEE.on('foo', () => {});
800
- * myEE.on('bar', () => {});
801
- *
802
- * const sym = Symbol('symbol');
803
- * myEE.on(sym, () => {});
804
- *
805
- * console.log(myEE.eventNames());
806
- * // Prints: [ 'foo', 'bar', Symbol(symbol) ]
807
- * ```
808
- * @since v6.0.0
809
- */
810
- eventNames(): Array<(string | symbol) & Key2<unknown, T>>;
811
- }
812
- }
813
- }
814
- export = EventEmitter;
815
- }
816
- declare module "node:events" {
817
- import events = require("events");
818
- export = events;
819
- }