rahad-media-downloader 2.1.12 → 2.1.13

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