alicezetion 1.9.6 → 1.9.8

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