@sapphire/event-iterator 1.6.1 → 1.6.2-next.075ec73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,134 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [1.6.1](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.6.0...@sapphire/event-iterator@1.6.1) (2022-04-01)
6
+
7
+ **Note:** Version bump only for package @sapphire/event-iterator
8
+
9
+ # [1.6.0](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.5.0...@sapphire/event-iterator@1.6.0) (2022-03-06)
10
+
11
+ ### Features
12
+
13
+ - allow module: NodeNext ([#306](https://github.com/sapphiredev/utilities/issues/306)) ([9dc6dd6](https://github.com/sapphiredev/utilities/commit/9dc6dd619efab879bb2b0b3c9e64304e10a67ed6))
14
+ - **ts-config:** add multi-config structure ([#281](https://github.com/sapphiredev/utilities/issues/281)) ([b5191d7](https://github.com/sapphiredev/utilities/commit/b5191d7f2416dc5838590c4ff221454925553e37))
15
+
16
+ # [1.5.0](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.4.0...@sapphire/event-iterator@1.5.0) (2022-01-28)
17
+
18
+ ### Features
19
+
20
+ - change build system to tsup ([#270](https://github.com/sapphiredev/utilities/issues/270)) ([365a53a](https://github.com/sapphiredev/utilities/commit/365a53a5517a01a0926cf28a83c96b63f32ed9f8))
21
+
22
+ # [1.4.0](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.3.3...@sapphire/event-iterator@1.4.0) (2022-01-10)
23
+
24
+ ### Features
25
+
26
+ - **event-iterator:** do not bundle for browsers ([#237](https://github.com/sapphiredev/utilities/issues/237)) ([c922e61](https://github.com/sapphiredev/utilities/commit/c922e613bacdfb1dd428cc174c0742b24642827e))
27
+
28
+ ## [1.3.3](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.3.2...@sapphire/event-iterator@1.3.3) (2021-11-06)
29
+
30
+ **Note:** Version bump only for package @sapphire/event-iterator
31
+
32
+ ## [1.3.2](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.3.1...@sapphire/event-iterator@1.3.2) (2021-10-17)
33
+
34
+ ### Bug Fixes
35
+
36
+ - allow more node & npm versions in engines field ([5977d2a](https://github.com/sapphiredev/utilities/commit/5977d2a30a4b2cfdf84aff3f33af03ffde1bbec5))
37
+
38
+ ## [1.3.1](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.3.0...@sapphire/event-iterator@1.3.1) (2021-10-11)
39
+
40
+ **Note:** Version bump only for package @sapphire/event-iterator
41
+
42
+ # [1.3.0](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.2.4...@sapphire/event-iterator@1.3.0) (2021-10-04)
43
+
44
+ ### Features
45
+
46
+ - **event-iterator:** set minimum NodeJS to v14 ([57110ee](https://github.com/sapphiredev/utilities/commit/57110ee1a25879d7cde62b4cfc4d9e128886bd54))
47
+
48
+ ## [1.2.4](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.2.3...@sapphire/event-iterator@1.2.4) (2021-06-27)
49
+
50
+ **Note:** Version bump only for package @sapphire/event-iterator
51
+
52
+ ## [1.2.3](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.2.2...@sapphire/event-iterator@1.2.3) (2021-06-06)
53
+
54
+ ### Bug Fixes
55
+
56
+ - remove peer deps, update dev deps, update READMEs ([#124](https://github.com/sapphiredev/utilities/issues/124)) ([67256ed](https://github.com/sapphiredev/utilities/commit/67256ed43b915b02a8b5c68230ba82d6210c5032))
57
+
58
+ ## [1.2.2](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.2.1...@sapphire/event-iterator@1.2.2) (2021-05-20)
59
+
60
+ ### Bug Fixes
61
+
62
+ - **event-iterator:** mark package as side effect free ([780129d](https://github.com/sapphiredev/utilities/commit/780129d1c8d16bb39f80cb70f70074229106bae7))
63
+
64
+ ## [1.2.1](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.2.0...@sapphire/event-iterator@1.2.1) (2021-05-02)
65
+
66
+ ### Bug Fixes
67
+
68
+ - drop the `www.` from the SapphireJS URL ([494d89f](https://github.com/sapphiredev/utilities/commit/494d89ffa04f78c195b93d7905b3232884f7d7e2))
69
+ - update all the SapphireJS URLs from `.com` to `.dev` ([f59b46d](https://github.com/sapphiredev/utilities/commit/f59b46d1a0ebd39cad17b17d71cd3b9da808d5fd))
70
+
71
+ # [1.2.0](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.1.8...@sapphire/event-iterator@1.2.0) (2021-04-21)
72
+
73
+ ### Features
74
+
75
+ - add @sapphire/embed-jsx ([#100](https://github.com/sapphiredev/utilities/issues/100)) ([7277a23](https://github.com/sapphiredev/utilities/commit/7277a236015236ed8e81b7882875410facc4ce17))
76
+
77
+ ## [1.1.8](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.1.7...@sapphire/event-iterator@1.1.8) (2021-04-19)
78
+
79
+ ### Bug Fixes
80
+
81
+ - change all Sapphire URLs from "project"->"community" & use our domain where applicable 👨‍🌾🚜 ([#102](https://github.com/sapphiredev/utilities/issues/102)) ([835b408](https://github.com/sapphiredev/utilities/commit/835b408e8e57130c3787aca2e32613346ff23e4d))
82
+
83
+ ## [1.1.7](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.1.6...@sapphire/event-iterator@1.1.7) (2021-04-03)
84
+
85
+ **Note:** Version bump only for package @sapphire/event-iterator
86
+
87
+ ## [1.1.6](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.1.5...@sapphire/event-iterator@1.1.6) (2021-03-16)
88
+
89
+ ### Bug Fixes
90
+
91
+ - remove terser from all packages ([#79](https://github.com/sapphiredev/utilities/issues/79)) ([1cfe4e7](https://github.com/sapphiredev/utilities/commit/1cfe4e7c804e62c142495686d2b83b81d0026c02))
92
+
93
+ ## [1.1.5](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.1.4...@sapphire/event-iterator@1.1.5) (2021-02-16)
94
+
95
+ **Note:** Version bump only for package @sapphire/event-iterator
96
+
97
+ ## [1.1.4](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.1.3...@sapphire/event-iterator@1.1.4) (2021-01-16)
98
+
99
+ **Note:** Version bump only for package @sapphire/event-iterator
100
+
101
+ ## [1.1.3](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.1.2...@sapphire/event-iterator@1.1.3) (2021-01-01)
102
+
103
+ **Note:** Version bump only for package @sapphire/event-iterator
104
+
105
+ ## [1.1.2](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.1.1...@sapphire/event-iterator@1.1.2) (2020-12-26)
106
+
107
+ **Note:** Version bump only for package @sapphire/event-iterator
108
+
109
+ ## [1.1.1](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.1.0...@sapphire/event-iterator@1.1.1) (2020-12-22)
110
+
111
+ **Note:** Version bump only for package @sapphire/event-iterator
112
+
113
+ # [1.1.0](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.0.1...@sapphire/event-iterator@1.1.0) (2020-11-15)
114
+
115
+ ### Bug Fixes
116
+
117
+ - **event-iterator:** pass keep_classnames to terser ([d903fe6](https://github.com/sapphiredev/utilities/commit/d903fe60d6ea3705b88e39c3dd9e7d0f60fea8a0))
118
+ - **event-iterator:** pass keep_fnames to terser ([d1398cd](https://github.com/sapphiredev/utilities/commit/d1398cd7c1f5c0445e141551dc3fe8ba4800cbad))
119
+
120
+ ### Features
121
+
122
+ - added time-utilities package ([#26](https://github.com/sapphiredev/utilities/issues/26)) ([f17a333](https://github.com/sapphiredev/utilities/commit/f17a3339667a452e8745fad7884272176e5d65e8))
123
+
124
+ ## [1.0.1](https://github.com/sapphiredev/utilities/compare/@sapphire/event-iterator@1.0.0...@sapphire/event-iterator@1.0.1) (2020-11-04)
125
+
126
+ ### Bug Fixes
127
+
128
+ - **event-iterator:** properly specify ESM and CommonJS exports ([ee0c114](https://github.com/sapphiredev/utilities/commit/ee0c114b09c9d003cce79a5899d4b109a04bdf6b))
129
+
130
+ # 1.0.0 (2020-10-11)
131
+
132
+ ### Features
133
+
134
+ - added event-iterator package ([#19](https://github.com/sapphiredev/utilities/issues/19)) ([8c80a76](https://github.com/sapphiredev/utilities/commit/8c80a76f81069429a882550589f43d4b4f8a4bcb))
package/README.md CHANGED
@@ -129,6 +129,15 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
129
129
  </tr>
130
130
  <tr>
131
131
  <td align="center"><a href="https://c43721.dev/"><img src="https://avatars.githubusercontent.com/u/55610086?v=4?s=100" width="100px;" alt=""/><br /><sub><b>c43721</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=c43721" title="Code">💻</a></td>
132
+ <td align="center"><a href="https://commandtechno.com/"><img src="https://avatars.githubusercontent.com/u/68407783?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Commandtechno</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Commandtechno" title="Code">💻</a></td>
133
+ <td align="center"><a href="https://github.com/dhruv-kaushikk"><img src="https://avatars.githubusercontent.com/u/73697546?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=dhruv-kaushikk" title="Code">💻</a></td>
134
+ <td align="center"><a href="https://axis.moe/"><img src="https://avatars.githubusercontent.com/u/54381371?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=axisiscool" title="Code">💻</a></td>
135
+ <td align="center"><a href="https://github.com/imranbarbhuiya"><img src="https://avatars.githubusercontent.com/u/74945038?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Parbez</b></sub></a><br /><a href="#maintenance-imranbarbhuiya" title="Maintenance">🚧</a></td>
136
+ <td align="center"><a href="https://github.com/NotKaskus"><img src="https://avatars.githubusercontent.com/u/75168528?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Paul Andrew</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=NotKaskus" title="Documentation">📖</a></td>
137
+ <td align="center"><a href="https://linktr.ee/mzato0001"><img src="https://avatars.githubusercontent.com/u/62367547?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mzato</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Mzato0001" title="Code">💻</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AMzato0001" title="Bug reports">🐛</a></td>
138
+ </tr>
139
+ <tr>
140
+ <td align="center"><a href="https://github.com/MajesticString"><img src="https://avatars.githubusercontent.com/u/66224939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harry Allen</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=MajesticString" title="Documentation">📖</a></td>
132
141
  </tr>
133
142
  </table>
134
143
 
package/dist/index.js CHANGED
@@ -142,6 +142,7 @@ var EventIterator = class {
142
142
  __privateGet(this, _queue).push(value);
143
143
  }
144
144
  };
145
+ __name(EventIterator, "EventIterator");
145
146
  _ended = new WeakMap();
146
147
  _idle = new WeakMap();
147
148
  _queue = new WeakMap();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { EventEmitter } from 'node:events';\n\n/**\n * A filter for an EventIterator.\n */\nexport type EventIteratorFilter<V> = (value: V) => boolean;\n\n/**\n * Options to be passed to an EventIterator.\n */\nexport interface EventIteratorOptions<V> {\n\t/**\n\t * The filter.\n\t */\n\tfilter?: EventIteratorFilter<V>;\n\n\t/**\n\t * The timeout in ms before ending the EventIterator.\n\t */\n\tidle?: number;\n\n\t/**\n\t * The limit of events that pass the filter to iterate.\n\t */\n\tlimit?: number;\n}\n\n/**\n * An EventIterator, used for asynchronously iterating over received values.\n */\nexport class EventIterator<V extends unknown[]> implements AsyncIterableIterator<V> {\n\t/**\n\t * The emitter to listen to.\n\t */\n\tpublic readonly emitter: EventEmitter;\n\n\t/**\n\t * The event the event iterator is listening for to receive values from.\n\t */\n\tpublic readonly event: string;\n\n\t/**\n\t * The filter used to filter out values.\n\t */\n\tpublic filter: EventIteratorFilter<V>;\n\n\t/**\n\t * Whether or not the EventIterator has ended.\n\t */\n\t#ended = false;\n\n\t/**\n\t * The amount of idle time in ms before moving on.\n\t */\n\t#idle?: number;\n\n\t/**\n\t * The queue of received values.\n\t */\n\t#queue: V[] = [];\n\n\t/**\n\t * The amount of events that have passed the filter.\n\t */\n\t#passed = 0;\n\n\t/**\n\t * The limit before ending the EventIterator.\n\t */\n\t#limit: number;\n\n\t/**\n\t * The timer to track when this will idle out.\n\t */\n\t#idleTimer: NodeJS.Timer | null = null;\n\n\t/**\n\t * The push handler with context bound to the instance.\n\t */\n\t#push: (this: EventIterator<V>, ...value: V) => void;\n\n\t/**\n\t * @param emitter The event emitter to listen to.\n\t * @param event The event we're listening for to receives values from.\n\t * @param limit The amount of values to receive before ending the iterator.\n\t * @param options Any extra options.\n\t */\n\tpublic constructor(emitter: EventEmitter, event: string, options: EventIteratorOptions<V> = {}) {\n\t\tthis.emitter = emitter;\n\t\tthis.event = event;\n\t\tthis.#limit = options.limit ?? Infinity;\n\t\tthis.#idle = options.idle;\n\t\tthis.filter = options.filter ?? ((): boolean => true);\n\n\t\t// This timer is to idle out on lack of valid responses\n\t\tif (this.#idle) this.#idleTimer = setTimeout(this.end.bind(this), this.#idle);\n\n\t\t// @ts-expect-error Silence weird compiler issue regarding `this.push`'s arguments not being `any`.\n\t\tthis.#push = this.push.bind(this);\n\t\tconst maxListeners = this.emitter.getMaxListeners();\n\t\tif (maxListeners !== 0) this.emitter.setMaxListeners(maxListeners + 1);\n\n\t\t// @ts-expect-error Silence weird compiler issue regarding `this.push`'s arguments not being `any`.\n\t\tthis.emitter.on(this.event, this.#push);\n\t}\n\n\t/**\n\t * Whether or not the EventIterator has ended.\n\t */\n\tpublic get ended(): boolean {\n\t\treturn this.#ended;\n\t}\n\n\t/**\n\t * Ends the EventIterator.\n\t */\n\tpublic end(): void {\n\t\tif (this.#ended) return;\n\t\tthis.#ended = true;\n\t\tthis.#queue = [];\n\n\t\t// @ts-expect-error Silence weird compiler issue regarding `this.push`'s arguments not being `any`.\n\t\tthis.emitter.off(this.event, this.#push);\n\t\tconst maxListeners = this.emitter.getMaxListeners();\n\t\tif (maxListeners !== 0) this.emitter.setMaxListeners(maxListeners - 1);\n\t}\n\n\t/**\n\t * The next value that's received from the EventEmitter.\n\t */\n\tpublic async next(): Promise<IteratorResult<V>> {\n\t\t// If there are elements in the queue, return an undone response:\n\t\tif (this.#queue.length) {\n\t\t\tconst value = this.#queue.shift()!;\n\t\t\tif (!this.filter(value)) return this.next();\n\t\t\tif (++this.#passed >= this.#limit) this.end();\n\t\t\tif (this.#idleTimer) this.#idleTimer.refresh();\n\t\t\treturn { done: false, value };\n\t\t}\n\n\t\t// If the iterator ended, clean-up timer and return a done response:\n\t\tif (this.#ended) {\n\t\t\tif (this.#idleTimer) clearTimeout(this.#idleTimer);\n\t\t\treturn { done: true, value: undefined as never };\n\t\t}\n\n\t\t// Listen for a new element from the emitter:\n\t\treturn new Promise<IteratorResult<V>>((resolve) => {\n\t\t\tlet idleTimer: NodeJS.Timer | null = null;\n\n\t\t\t// If there is an idle time set, we will create a temporary timer,\n\t\t\t// which will cause the iterator to end if no new elements are received:\n\t\t\tif (this.#idle) {\n\t\t\t\tidleTimer = setTimeout(() => {\n\t\t\t\t\tthis.end();\n\t\t\t\t\tresolve(this.next());\n\t\t\t\t}, this.#idle);\n\t\t\t}\n\n\t\t\t// Once it has received at least one value, we will clear the timer (if defined),\n\t\t\t// and resolve with the new value:\n\t\t\tthis.emitter.once(this.event, () => {\n\t\t\t\tif (idleTimer) clearTimeout(idleTimer);\n\t\t\t\tresolve(this.next());\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Handles what happens when you break or return from a loop.\n\t */\n\tpublic return(): Promise<IteratorResult<V>> {\n\t\tthis.end();\n\t\treturn Promise.resolve({ done: true, value: undefined as never });\n\t}\n\n\t/**\n\t * Handles what happens when you encounter an error in a loop.\n\t */\n\tpublic throw(): Promise<IteratorResult<V>> {\n\t\tthis.end();\n\t\treturn Promise.resolve({ done: true, value: undefined as never });\n\t}\n\n\t/**\n\t * The symbol allowing EventIterators to be used in for-await-of loops.\n\t */\n\tpublic [Symbol.asyncIterator](): AsyncIterableIterator<V> {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Pushes a value into the queue.\n\t */\n\tprotected push(...value: V): void {\n\t\tthis.#queue.push(value);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BO,0BAA6E;AAAA,EAyD5E,YAAY,SAAuB,OAAe,UAAmC,CAAC,GAAG;AArDhF;AAKA;AAKT;AAKP,+BAAS;AAKT;AAKA,+BAAc,CAAC;AAKf,gCAAU;AAKV;AAKA,mCAAkC;AAKlC;AASC,SAAK,UAAU;AACf,SAAK,QAAQ;AACb,uBAAK,QAAS,QAAQ,SAAS;AAC/B,uBAAK,OAAQ,QAAQ;AACrB,SAAK,SAAS,QAAQ,UAAW,OAAe;AAGhD,QAAI,mBAAK;AAAO,yBAAK,YAAa,WAAW,KAAK,IAAI,KAAK,IAAI,GAAG,mBAAK,MAAK;AAG5E,uBAAK,OAAQ,KAAK,KAAK,KAAK,IAAI;AAChC,UAAM,eAAe,KAAK,QAAQ,gBAAgB;AAClD,QAAI,iBAAiB;AAAG,WAAK,QAAQ,gBAAgB,eAAe,CAAC;AAGrE,SAAK,QAAQ,GAAG,KAAK,OAAO,mBAAK,MAAK;AAAA,EACvC;AAAA,MAKW,QAAiB;AAC3B,WAAO,mBAAK;AAAA,EACb;AAAA,EAKO,MAAY;AAClB,Q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B,CAAC;AAAA,EACjE;AAAA,GAKQ,OAAO,iBAA2C;AACzD,WAAO;AAAA,EACR;AAAA,EAKU,QAAQ,OAAgB;AACjC,uBAAK,QAAO,KAAK,KAAK;AAAA,EACvB;AACD;AAvKO,AAmBN;AAKA;AAKA;AAKA;AAKA;AAKA;AAKA;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { EventEmitter } from 'node:events';\n\n/**\n * A filter for an EventIterator.\n */\nexport type EventIteratorFilter<V> = (value: V) => boolean;\n\n/**\n * Options to be passed to an EventIterator.\n */\nexport interface EventIteratorOptions<V> {\n\t/**\n\t * The filter.\n\t */\n\tfilter?: EventIteratorFilter<V>;\n\n\t/**\n\t * The timeout in ms before ending the EventIterator.\n\t */\n\tidle?: number;\n\n\t/**\n\t * The limit of events that pass the filter to iterate.\n\t */\n\tlimit?: number;\n}\n\n/**\n * An EventIterator, used for asynchronously iterating over received values.\n */\nexport class EventIterator<V extends unknown[]> implements AsyncIterableIterator<V> {\n\t/**\n\t * The emitter to listen to.\n\t */\n\tpublic readonly emitter: EventEmitter;\n\n\t/**\n\t * The event the event iterator is listening for to receive values from.\n\t */\n\tpublic readonly event: string;\n\n\t/**\n\t * The filter used to filter out values.\n\t */\n\tpublic filter: EventIteratorFilter<V>;\n\n\t/**\n\t * Whether or not the EventIterator has ended.\n\t */\n\t#ended = false;\n\n\t/**\n\t * The amount of idle time in ms before moving on.\n\t */\n\t#idle?: number;\n\n\t/**\n\t * The queue of received values.\n\t */\n\t#queue: V[] = [];\n\n\t/**\n\t * The amount of events that have passed the filter.\n\t */\n\t#passed = 0;\n\n\t/**\n\t * The limit before ending the EventIterator.\n\t */\n\t#limit: number;\n\n\t/**\n\t * The timer to track when this will idle out.\n\t */\n\t#idleTimer: NodeJS.Timer | null = null;\n\n\t/**\n\t * The push handler with context bound to the instance.\n\t */\n\t#push: (this: EventIterator<V>, ...value: V) => void;\n\n\t/**\n\t * @param emitter The event emitter to listen to.\n\t * @param event The event we're listening for to receives values from.\n\t * @param limit The amount of values to receive before ending the iterator.\n\t * @param options Any extra options.\n\t */\n\tpublic constructor(emitter: EventEmitter, event: string, options: EventIteratorOptions<V> = {}) {\n\t\tthis.emitter = emitter;\n\t\tthis.event = event;\n\t\tthis.#limit = options.limit ?? Infinity;\n\t\tthis.#idle = options.idle;\n\t\tthis.filter = options.filter ?? ((): boolean => true);\n\n\t\t// This timer is to idle out on lack of valid responses\n\t\tif (this.#idle) this.#idleTimer = setTimeout(this.end.bind(this), this.#idle);\n\n\t\tthis.#push = this.push.bind(this);\n\t\tconst maxListeners = this.emitter.getMaxListeners();\n\t\tif (maxListeners !== 0) this.emitter.setMaxListeners(maxListeners + 1);\n\n\t\t// @ts-expect-error Silence weird compiler issue regarding `this.push`'s arguments not being `any`.\n\t\tthis.emitter.on(this.event, this.#push);\n\t}\n\n\t/**\n\t * Whether or not the EventIterator has ended.\n\t */\n\tpublic get ended(): boolean {\n\t\treturn this.#ended;\n\t}\n\n\t/**\n\t * Ends the EventIterator.\n\t */\n\tpublic end(): void {\n\t\tif (this.#ended) return;\n\t\tthis.#ended = true;\n\t\tthis.#queue = [];\n\n\t\t// @ts-expect-error Silence weird compiler issue regarding `this.push`'s arguments not being `any`.\n\t\tthis.emitter.off(this.event, this.#push);\n\t\tconst maxListeners = this.emitter.getMaxListeners();\n\t\tif (maxListeners !== 0) this.emitter.setMaxListeners(maxListeners - 1);\n\t}\n\n\t/**\n\t * The next value that's received from the EventEmitter.\n\t */\n\tpublic async next(): Promise<IteratorResult<V>> {\n\t\t// If there are elements in the queue, return an undone response:\n\t\tif (this.#queue.length) {\n\t\t\tconst value = this.#queue.shift()!;\n\t\t\tif (!this.filter(value)) return this.next();\n\t\t\tif (++this.#passed >= this.#limit) this.end();\n\t\t\tif (this.#idleTimer) this.#idleTimer.refresh();\n\t\t\treturn { done: false, value };\n\t\t}\n\n\t\t// If the iterator ended, clean-up timer and return a done response:\n\t\tif (this.#ended) {\n\t\t\tif (this.#idleTimer) clearTimeout(this.#idleTimer);\n\t\t\treturn { done: true, value: undefined as never };\n\t\t}\n\n\t\t// Listen for a new element from the emitter:\n\t\treturn new Promise<IteratorResult<V>>((resolve) => {\n\t\t\tlet idleTimer: NodeJS.Timer | null = null;\n\n\t\t\t// If there is an idle time set, we will create a temporary timer,\n\t\t\t// which will cause the iterator to end if no new elements are received:\n\t\t\tif (this.#idle) {\n\t\t\t\tidleTimer = setTimeout(() => {\n\t\t\t\t\tthis.end();\n\t\t\t\t\tresolve(this.next());\n\t\t\t\t}, this.#idle);\n\t\t\t}\n\n\t\t\t// Once it has received at least one value, we will clear the timer (if defined),\n\t\t\t// and resolve with the new value:\n\t\t\tthis.emitter.once(this.event, () => {\n\t\t\t\tif (idleTimer) clearTimeout(idleTimer);\n\t\t\t\tresolve(this.next());\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Handles what happens when you break or return from a loop.\n\t */\n\tpublic return(): Promise<IteratorResult<V>> {\n\t\tthis.end();\n\t\treturn Promise.resolve({ done: true, value: undefined as never });\n\t}\n\n\t/**\n\t * Handles what happens when you encounter an error in a loop.\n\t */\n\tpublic throw(): Promise<IteratorResult<V>> {\n\t\tthis.end();\n\t\treturn Promise.resolve({ done: true, value: undefined as never });\n\t}\n\n\t/**\n\t * The symbol allowing EventIterators to be used in for-await-of loops.\n\t */\n\tpublic [Symbol.asyncIterator](): AsyncIterableIterator<V> {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Pushes a value into the queue.\n\t */\n\tprotected push(...value: V): void {\n\t\tthis.#queue.push(value);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BO,IAAM,gBAAN,MAA6E;AAAA,EAyDnF,AAAO,YAAY,SAAuB,OAAe,UAAmC,CAAC,GAAG;AArDhG,wBAAgB;AAKhB,wBAAgB;AAKhB,wBAAO;AAKP,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E,MAAM,MAAM,OAAO,OAAmB;AAAA,IAChD;AAGA,WAAO,IAAI,QAA2B,CAAC,YAAY;AAClD,UAAI,YAAiC;AAIrC,UAAI,mBAAK,QAAO;AACf,oBAAY,WAAW,MAAM;AAC5B,eAAK,IAAI;AACT,kBAAQ,KAAK,KAAK,CAAC;AAAA,QACpB,GAAG,mBAAK,MAAK;AAAA,MACd;AAIA,WAAK,QAAQ,KAAK,KAAK,OAAO,MAAM;AACnC,YAAI;AAAW,uBAAa,SAAS;AACrC,gBAAQ,KAAK,KAAK,CAAC;AAAA,MACpB,CAAC;AAAA,IACF,CAAC;AAAA,EACF;AAAA,EAKA,AAAO,SAAqC;AAC3C,SAAK,IAAI;AACT,WAAO,QAAQ,QAAQ,EAAE,MAAM,MAAM,OAAO,OAAmB,CAAC;AAAA,EACjE;AAAA,EAKA,AAAO,QAAoC;AAC1C,SAAK,IAAI;AACT,WAAO,QAAQ,QAAQ,EAAE,MAAM,MAAM,OAAO,OAAmB,CAAC;AAAA,EACjE;AAAA,EAKA,CAAQ,OAAO,iBAA2C;AACzD,WAAO;AAAA,EACR;AAAA,EAKA,AAAU,QAAQ,OAAgB;AACjC,uBAAK,QAAO,KAAK,KAAK;AAAA,EACvB;AACD;AAtKa;AAmBZ;AAKA;AAKA;AAKA;AAKA;AAKA;AAKA;","names":[]}
package/dist/index.mjs CHANGED
@@ -120,6 +120,7 @@ var EventIterator = class {
120
120
  __privateGet(this, _queue).push(value);
121
121
  }
122
122
  };
123
+ __name(EventIterator, "EventIterator");
123
124
  _ended = new WeakMap();
124
125
  _idle = new WeakMap();
125
126
  _queue = new WeakMap();
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { EventEmitter } from 'node:events';\n\n/**\n * A filter for an EventIterator.\n */\nexport type EventIteratorFilter<V> = (value: V) => boolean;\n\n/**\n * Options to be passed to an EventIterator.\n */\nexport interface EventIteratorOptions<V> {\n\t/**\n\t * The filter.\n\t */\n\tfilter?: EventIteratorFilter<V>;\n\n\t/**\n\t * The timeout in ms before ending the EventIterator.\n\t */\n\tidle?: number;\n\n\t/**\n\t * The limit of events that pass the filter to iterate.\n\t */\n\tlimit?: number;\n}\n\n/**\n * An EventIterator, used for asynchronously iterating over received values.\n */\nexport class EventIterator<V extends unknown[]> implements AsyncIterableIterator<V> {\n\t/**\n\t * The emitter to listen to.\n\t */\n\tpublic readonly emitter: EventEmitter;\n\n\t/**\n\t * The event the event iterator is listening for to receive values from.\n\t */\n\tpublic readonly event: string;\n\n\t/**\n\t * The filter used to filter out values.\n\t */\n\tpublic filter: EventIteratorFilter<V>;\n\n\t/**\n\t * Whether or not the EventIterator has ended.\n\t */\n\t#ended = false;\n\n\t/**\n\t * The amount of idle time in ms before moving on.\n\t */\n\t#idle?: number;\n\n\t/**\n\t * The queue of received values.\n\t */\n\t#queue: V[] = [];\n\n\t/**\n\t * The amount of events that have passed the filter.\n\t */\n\t#passed = 0;\n\n\t/**\n\t * The limit before ending the EventIterator.\n\t */\n\t#limit: number;\n\n\t/**\n\t * The timer to track when this will idle out.\n\t */\n\t#idleTimer: NodeJS.Timer | null = null;\n\n\t/**\n\t * The push handler with context bound to the instance.\n\t */\n\t#push: (this: EventIterator<V>, ...value: V) => void;\n\n\t/**\n\t * @param emitter The event emitter to listen to.\n\t * @param event The event we're listening for to receives values from.\n\t * @param limit The amount of values to receive before ending the iterator.\n\t * @param options Any extra options.\n\t */\n\tpublic constructor(emitter: EventEmitter, event: string, options: EventIteratorOptions<V> = {}) {\n\t\tthis.emitter = emitter;\n\t\tthis.event = event;\n\t\tthis.#limit = options.limit ?? Infinity;\n\t\tthis.#idle = options.idle;\n\t\tthis.filter = options.filter ?? ((): boolean => true);\n\n\t\t// This timer is to idle out on lack of valid responses\n\t\tif (this.#idle) this.#idleTimer = setTimeout(this.end.bind(this), this.#idle);\n\n\t\t// @ts-expect-error Silence weird compiler issue regarding `this.push`'s arguments not being `any`.\n\t\tthis.#push = this.push.bind(this);\n\t\tconst maxListeners = this.emitter.getMaxListeners();\n\t\tif (maxListeners !== 0) this.emitter.setMaxListeners(maxListeners + 1);\n\n\t\t// @ts-expect-error Silence weird compiler issue regarding `this.push`'s arguments not being `any`.\n\t\tthis.emitter.on(this.event, this.#push);\n\t}\n\n\t/**\n\t * Whether or not the EventIterator has ended.\n\t */\n\tpublic get ended(): boolean {\n\t\treturn this.#ended;\n\t}\n\n\t/**\n\t * Ends the EventIterator.\n\t */\n\tpublic end(): void {\n\t\tif (this.#ended) return;\n\t\tthis.#ended = true;\n\t\tthis.#queue = [];\n\n\t\t// @ts-expect-error Silence weird compiler issue regarding `this.push`'s arguments not being `any`.\n\t\tthis.emitter.off(this.event, this.#push);\n\t\tconst maxListeners = this.emitter.getMaxListeners();\n\t\tif (maxListeners !== 0) this.emitter.setMaxListeners(maxListeners - 1);\n\t}\n\n\t/**\n\t * The next value that's received from the EventEmitter.\n\t */\n\tpublic async next(): Promise<IteratorResult<V>> {\n\t\t// If there are elements in the queue, return an undone response:\n\t\tif (this.#queue.length) {\n\t\t\tconst value = this.#queue.shift()!;\n\t\t\tif (!this.filter(value)) return this.next();\n\t\t\tif (++this.#passed >= this.#limit) this.end();\n\t\t\tif (this.#idleTimer) this.#idleTimer.refresh();\n\t\t\treturn { done: false, value };\n\t\t}\n\n\t\t// If the iterator ended, clean-up timer and return a done response:\n\t\tif (this.#ended) {\n\t\t\tif (this.#idleTimer) clearTimeout(this.#idleTimer);\n\t\t\treturn { done: true, value: undefined as never };\n\t\t}\n\n\t\t// Listen for a new element from the emitter:\n\t\treturn new Promise<IteratorResult<V>>((resolve) => {\n\t\t\tlet idleTimer: NodeJS.Timer | null = null;\n\n\t\t\t// If there is an idle time set, we will create a temporary timer,\n\t\t\t// which will cause the iterator to end if no new elements are received:\n\t\t\tif (this.#idle) {\n\t\t\t\tidleTimer = setTimeout(() => {\n\t\t\t\t\tthis.end();\n\t\t\t\t\tresolve(this.next());\n\t\t\t\t}, this.#idle);\n\t\t\t}\n\n\t\t\t// Once it has received at least one value, we will clear the timer (if defined),\n\t\t\t// and resolve with the new value:\n\t\t\tthis.emitter.once(this.event, () => {\n\t\t\t\tif (idleTimer) clearTimeout(idleTimer);\n\t\t\t\tresolve(this.next());\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Handles what happens when you break or return from a loop.\n\t */\n\tpublic return(): Promise<IteratorResult<V>> {\n\t\tthis.end();\n\t\treturn Promise.resolve({ done: true, value: undefined as never });\n\t}\n\n\t/**\n\t * Handles what happens when you encounter an error in a loop.\n\t */\n\tpublic throw(): Promise<IteratorResult<V>> {\n\t\tthis.end();\n\t\treturn Promise.resolve({ done: true, value: undefined as never });\n\t}\n\n\t/**\n\t * The symbol allowing EventIterators to be used in for-await-of loops.\n\t */\n\tpublic [Symbol.asyncIterator](): AsyncIterableIterator<V> {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Pushes a value into the queue.\n\t */\n\tprotected push(...value: V): void {\n\t\tthis.#queue.push(value);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AA8BO,0BAA6E;AAAA,EAyD5E,YAAY,SAAuB,OAAe,UAAmC,CAAC,GAAG;AArDhF;AAKA;AAKT;AAKP,+BAAS;AAKT;AAKA,+BAAc,CAAC;AAKf,gCAAU;AAKV;AAKA,mCAAkC;AAKlC;AASC,SAAK,UAAU;AACf,SAAK,QAAQ;AACb,uBAAK,QAAS,QAAQ,SAAS;AAC/B,uBAAK,OAAQ,QAAQ;AACrB,SAAK,SAAS,QAAQ,UAAW,OAAe;AAGhD,QAAI,mBAAK;AAAO,yBAAK,YAAa,WAAW,KAAK,IAAI,KAAK,IAAI,GAAG,mBAAK,MAAK;AAG5E,uBAAK,OAAQ,KAAK,KAAK,KAAK,IAAI;AAChC,UAAM,eAAe,KAAK,QAAQ,gBAAgB;AAClD,QAAI,iBAAiB;AAAG,WAAK,QAAQ,gBAAgB,eAAe,CAAC;AAGrE,SAAK,QAA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AAO,OAAmB,CAAC;AAAA,EACjE;AAAA,EAKO,QAAoC;AAC1C,SAAK,IAAI;AACT,WAAO,QAAQ,QAAQ,EAAE,MAAM,MAAM,OAAO,OAAmB,CAAC;AAAA,EACjE;AAAA,GAKQ,OAAO,iBAA2C;AACzD,WAAO;AAAA,EACR;AAAA,EAKU,QAAQ,OAAgB;AACjC,uBAAK,QAAO,KAAK,KAAK;AAAA,EACvB;AACD;AAvKO,AAmBN;AAKA;AAKA;AAKA;AAKA;AAKA;AAKA;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { EventEmitter } from 'node:events';\n\n/**\n * A filter for an EventIterator.\n */\nexport type EventIteratorFilter<V> = (value: V) => boolean;\n\n/**\n * Options to be passed to an EventIterator.\n */\nexport interface EventIteratorOptions<V> {\n\t/**\n\t * The filter.\n\t */\n\tfilter?: EventIteratorFilter<V>;\n\n\t/**\n\t * The timeout in ms before ending the EventIterator.\n\t */\n\tidle?: number;\n\n\t/**\n\t * The limit of events that pass the filter to iterate.\n\t */\n\tlimit?: number;\n}\n\n/**\n * An EventIterator, used for asynchronously iterating over received values.\n */\nexport class EventIterator<V extends unknown[]> implements AsyncIterableIterator<V> {\n\t/**\n\t * The emitter to listen to.\n\t */\n\tpublic readonly emitter: EventEmitter;\n\n\t/**\n\t * The event the event iterator is listening for to receive values from.\n\t */\n\tpublic readonly event: string;\n\n\t/**\n\t * The filter used to filter out values.\n\t */\n\tpublic filter: EventIteratorFilter<V>;\n\n\t/**\n\t * Whether or not the EventIterator has ended.\n\t */\n\t#ended = false;\n\n\t/**\n\t * The amount of idle time in ms before moving on.\n\t */\n\t#idle?: number;\n\n\t/**\n\t * The queue of received values.\n\t */\n\t#queue: V[] = [];\n\n\t/**\n\t * The amount of events that have passed the filter.\n\t */\n\t#passed = 0;\n\n\t/**\n\t * The limit before ending the EventIterator.\n\t */\n\t#limit: number;\n\n\t/**\n\t * The timer to track when this will idle out.\n\t */\n\t#idleTimer: NodeJS.Timer | null = null;\n\n\t/**\n\t * The push handler with context bound to the instance.\n\t */\n\t#push: (this: EventIterator<V>, ...value: V) => void;\n\n\t/**\n\t * @param emitter The event emitter to listen to.\n\t * @param event The event we're listening for to receives values from.\n\t * @param limit The amount of values to receive before ending the iterator.\n\t * @param options Any extra options.\n\t */\n\tpublic constructor(emitter: EventEmitter, event: string, options: EventIteratorOptions<V> = {}) {\n\t\tthis.emitter = emitter;\n\t\tthis.event = event;\n\t\tthis.#limit = options.limit ?? Infinity;\n\t\tthis.#idle = options.idle;\n\t\tthis.filter = options.filter ?? ((): boolean => true);\n\n\t\t// This timer is to idle out on lack of valid responses\n\t\tif (this.#idle) this.#idleTimer = setTimeout(this.end.bind(this), this.#idle);\n\n\t\tthis.#push = this.push.bind(this);\n\t\tconst maxListeners = this.emitter.getMaxListeners();\n\t\tif (maxListeners !== 0) this.emitter.setMaxListeners(maxListeners + 1);\n\n\t\t// @ts-expect-error Silence weird compiler issue regarding `this.push`'s arguments not being `any`.\n\t\tthis.emitter.on(this.event, this.#push);\n\t}\n\n\t/**\n\t * Whether or not the EventIterator has ended.\n\t */\n\tpublic get ended(): boolean {\n\t\treturn this.#ended;\n\t}\n\n\t/**\n\t * Ends the EventIterator.\n\t */\n\tpublic end(): void {\n\t\tif (this.#ended) return;\n\t\tthis.#ended = true;\n\t\tthis.#queue = [];\n\n\t\t// @ts-expect-error Silence weird compiler issue regarding `this.push`'s arguments not being `any`.\n\t\tthis.emitter.off(this.event, this.#push);\n\t\tconst maxListeners = this.emitter.getMaxListeners();\n\t\tif (maxListeners !== 0) this.emitter.setMaxListeners(maxListeners - 1);\n\t}\n\n\t/**\n\t * The next value that's received from the EventEmitter.\n\t */\n\tpublic async next(): Promise<IteratorResult<V>> {\n\t\t// If there are elements in the queue, return an undone response:\n\t\tif (this.#queue.length) {\n\t\t\tconst value = this.#queue.shift()!;\n\t\t\tif (!this.filter(value)) return this.next();\n\t\t\tif (++this.#passed >= this.#limit) this.end();\n\t\t\tif (this.#idleTimer) this.#idleTimer.refresh();\n\t\t\treturn { done: false, value };\n\t\t}\n\n\t\t// If the iterator ended, clean-up timer and return a done response:\n\t\tif (this.#ended) {\n\t\t\tif (this.#idleTimer) clearTimeout(this.#idleTimer);\n\t\t\treturn { done: true, value: undefined as never };\n\t\t}\n\n\t\t// Listen for a new element from the emitter:\n\t\treturn new Promise<IteratorResult<V>>((resolve) => {\n\t\t\tlet idleTimer: NodeJS.Timer | null = null;\n\n\t\t\t// If there is an idle time set, we will create a temporary timer,\n\t\t\t// which will cause the iterator to end if no new elements are received:\n\t\t\tif (this.#idle) {\n\t\t\t\tidleTimer = setTimeout(() => {\n\t\t\t\t\tthis.end();\n\t\t\t\t\tresolve(this.next());\n\t\t\t\t}, this.#idle);\n\t\t\t}\n\n\t\t\t// Once it has received at least one value, we will clear the timer (if defined),\n\t\t\t// and resolve with the new value:\n\t\t\tthis.emitter.once(this.event, () => {\n\t\t\t\tif (idleTimer) clearTimeout(idleTimer);\n\t\t\t\tresolve(this.next());\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Handles what happens when you break or return from a loop.\n\t */\n\tpublic return(): Promise<IteratorResult<V>> {\n\t\tthis.end();\n\t\treturn Promise.resolve({ done: true, value: undefined as never });\n\t}\n\n\t/**\n\t * Handles what happens when you encounter an error in a loop.\n\t */\n\tpublic throw(): Promise<IteratorResult<V>> {\n\t\tthis.end();\n\t\treturn Promise.resolve({ done: true, value: undefined as never });\n\t}\n\n\t/**\n\t * The symbol allowing EventIterators to be used in for-await-of loops.\n\t */\n\tpublic [Symbol.asyncIterator](): AsyncIterableIterator<V> {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Pushes a value into the queue.\n\t */\n\tprotected push(...value: V): void {\n\t\tthis.#queue.push(value);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AA8BO,IAAM,gBAAN,MAA6E;AAAA,EAyDnF,AAAO,YAAY,SAAuB,OAAe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AK,SAAQ;AAChB,UAAI,mBAAK;AAAY,qBAAa,mBAAK,WAAU;AACjD,aAAO,EAAE,MAAM,MAAM,OAAO,OAAmB;AAAA,IAChD;AAGA,WAAO,IAAI,QAA2B,CAAC,YAAY;AAClD,UAAI,YAAiC;AAIrC,UAAI,mBAAK,QAAO;AACf,oBAAY,WAAW,MAAM;AAC5B,eAAK,IAAI;AACT,kBAAQ,KAAK,KAAK,CAAC;AAAA,QACpB,GAAG,mBAAK,MAAK;AAAA,MACd;AAIA,WAAK,QAAQ,KAAK,KAAK,OAAO,MAAM;AACnC,YAAI;AAAW,uBAAa,SAAS;AACrC,gBAAQ,KAAK,KAAK,CAAC;AAAA,MACpB,CAAC;AAAA,IACF,CAAC;AAAA,EACF;AAAA,EAKA,AAAO,SAAqC;AAC3C,SAAK,IAAI;AACT,WAAO,QAAQ,QAAQ,EAAE,MAAM,MAAM,OAAO,OAAmB,CAAC;AAAA,EACjE;AAAA,EAKA,AAAO,QAAoC;AAC1C,SAAK,IAAI;AACT,WAAO,QAAQ,QAAQ,EAAE,MAAM,MAAM,OAAO,OAAmB,CAAC;AAAA,EACjE;AAAA,EAKA,CAAQ,OAAO,iBAA2C;AACzD,WAAO;AAAA,EACR;AAAA,EAKA,AAAU,QAAQ,OAAgB;AACjC,uBAAK,QAAO,KAAK,KAAK;AAAA,EACvB;AACD;AAtKa;AAmBZ;AAKA;AAKA;AAKA;AAKA;AAKA;AAKA;","names":[]}
package/package.json CHANGED
@@ -1,57 +1,62 @@
1
1
  {
2
- "name": "@sapphire/event-iterator",
3
- "version": "1.6.1",
4
- "description": "Turns event emitter events into async iterators.",
5
- "author": "@sapphire",
6
- "license": "MIT",
7
- "main": "dist/index.js",
8
- "module": "dist/index.mjs",
9
- "types": "dist/index.d.ts",
10
- "typedocMain": "src/index.ts",
11
- "exports": {
12
- "import": "./dist/index.mjs",
13
- "require": "./dist/index.js",
14
- "types": "./dist/index.d.ts"
15
- },
16
- "sideEffects": false,
17
- "homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/event-iterator",
18
- "scripts": {
19
- "test": "jest",
20
- "lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
21
- "build": "tsup && tsc -b src",
22
- "prepublishOnly": "yarn build"
23
- },
24
- "dependencies": {
25
- "tslib": "^2.3.1"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/sapphiredev/utilities.git",
30
- "directory": "packages/event-iterator"
31
- },
32
- "files": [
33
- "dist",
34
- "!dist/*.tsbuildinfo"
35
- ],
36
- "engines": {
37
- "node": ">=v14.0.0",
38
- "npm": ">=7.0.0"
39
- },
40
- "keywords": [
41
- "@sapphire/event-iterator",
42
- "bot",
43
- "typescript",
44
- "ts",
45
- "yarn",
46
- "discord",
47
- "sapphire",
48
- "standalone"
49
- ],
50
- "bugs": {
51
- "url": "https://github.com/sapphiredev/utilities/issues"
52
- },
53
- "publishConfig": {
54
- "access": "public"
55
- },
56
- "gitHead": "bf5ac56e547bfdbfac38e020882004e0f136546e"
57
- }
2
+ "name": "@sapphire/event-iterator",
3
+ "version": "1.6.2-next.075ec73.0",
4
+ "description": "Turns event emitter events into async iterators.",
5
+ "author": "@sapphire",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "module": "dist/index.mjs",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ },
15
+ "sideEffects": false,
16
+ "homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/event-iterator",
17
+ "scripts": {
18
+ "test": "vitest run",
19
+ "lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
20
+ "build": "tsup && tsc -b src",
21
+ "prepack": "yarn build",
22
+ "bump": "cliff-jumper",
23
+ "check-update": "cliff-jumper --dry-run"
24
+ },
25
+ "dependencies": {
26
+ "tslib": "^2.4.0"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/sapphiredev/utilities.git",
31
+ "directory": "packages/event-iterator"
32
+ },
33
+ "files": [
34
+ "dist/**/*.js*",
35
+ "dist/**/*.mjs*",
36
+ "dist/**/*.d*"
37
+ ],
38
+ "engines": {
39
+ "node": ">=v14.0.0",
40
+ "npm": ">=7.0.0"
41
+ },
42
+ "keywords": [
43
+ "@sapphire/event-iterator",
44
+ "bot",
45
+ "typescript",
46
+ "ts",
47
+ "yarn",
48
+ "discord",
49
+ "sapphire",
50
+ "standalone"
51
+ ],
52
+ "bugs": {
53
+ "url": "https://github.com/sapphiredev/utilities/issues"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "devDependencies": {
59
+ "tsup": "^6.1.2",
60
+ "typescript": "^4.7.4"
61
+ }
62
+ }
package/LICENSE.md DELETED
@@ -1,24 +0,0 @@
1
- # The MIT License (MIT)
2
-
3
- Copyright © `2020` `The Sapphire Community and its contributors`
4
-
5
- Permission is hereby granted, free of charge, to any person
6
- obtaining a copy of this software and associated documentation
7
- files (the “Software”), to deal in the Software without
8
- restriction, including without limitation the rights to use,
9
- copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the
11
- Software is furnished to do so, subject to the following
12
- conditions:
13
-
14
- The above copyright notice and this permission notice shall be
15
- included in all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
18
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
- OTHER DEALINGS IN THE SOFTWARE.