tiny-essentials 1.18.1 → 1.19.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.
Files changed (74) hide show
  1. package/README.md +17 -3
  2. package/dist/node_modules/firebase-functions/lib/common/trace.cjs +0 -1
  3. package/dist/node_modules/firebase-functions/lib/logger/index.cjs +1 -0
  4. package/dist/v1/ColorSafeStringify.min.js +1 -1
  5. package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
  6. package/dist/v1/TinyBasicsEs.js +13 -6
  7. package/dist/v1/TinyBasicsEs.min.js +1 -1
  8. package/dist/v1/TinyClipboard.min.js +1 -1
  9. package/dist/v1/TinyColorConverter.js +617 -0
  10. package/dist/v1/TinyColorConverter.min.js +1 -0
  11. package/dist/v1/TinyDomReadyManager.min.js +1 -1
  12. package/dist/v1/TinyDragger.min.js +1 -1
  13. package/dist/v1/TinyEssentials.js +2635 -482
  14. package/dist/v1/TinyEssentials.min.js +1 -1
  15. package/dist/v1/TinyEvents.js +402 -0
  16. package/dist/v1/TinyEvents.min.js +1 -0
  17. package/dist/v1/TinyHtml.min.js +1 -1
  18. package/dist/v1/TinyLocalStorage.js +1292 -0
  19. package/dist/v1/TinyLocalStorage.min.js +1 -0
  20. package/dist/v1/TinyNotifications.min.js +1 -1
  21. package/dist/v1/TinyNotifyCenter.min.js +1 -1
  22. package/dist/v1/TinyPromiseQueue.min.js +1 -1
  23. package/dist/v1/TinyRateLimiter.js +2 -1
  24. package/dist/v1/TinyRateLimiter.min.js +1 -1
  25. package/dist/v1/TinySmartScroller.js +570 -52
  26. package/dist/v1/TinySmartScroller.min.js +1 -1
  27. package/dist/v1/TinyTextRangeEditor.min.js +1 -1
  28. package/dist/v1/TinyTimeout.js +233 -0
  29. package/dist/v1/TinyTimeout.min.js +1 -0
  30. package/dist/v1/TinyToastNotify.min.js +1 -1
  31. package/dist/v1/TinyUploadClicker.js +1457 -106
  32. package/dist/v1/TinyUploadClicker.min.js +1 -1
  33. package/dist/v1/UltraRandomMsgGen.min.js +1 -1
  34. package/dist/v1/basics/html.cjs +13 -6
  35. package/dist/v1/basics/html.d.mts +12 -4
  36. package/dist/v1/basics/html.mjs +13 -6
  37. package/dist/v1/build/TinyColorConverter.cjs +7 -0
  38. package/dist/v1/build/TinyColorConverter.d.mts +3 -0
  39. package/dist/v1/build/TinyColorConverter.mjs +2 -0
  40. package/dist/v1/build/TinyEvents.cjs +7 -0
  41. package/dist/v1/build/TinyEvents.d.mts +3 -0
  42. package/dist/v1/build/TinyEvents.mjs +2 -0
  43. package/dist/v1/build/TinyLocalStorage.cjs +7 -0
  44. package/dist/v1/build/TinyLocalStorage.d.mts +3 -0
  45. package/dist/v1/build/TinyLocalStorage.mjs +2 -0
  46. package/dist/v1/build/TinyTimeout.cjs +7 -0
  47. package/dist/v1/build/TinyTimeout.d.mts +3 -0
  48. package/dist/v1/build/TinyTimeout.mjs +2 -0
  49. package/dist/v1/index.cjs +8 -0
  50. package/dist/v1/index.d.mts +5 -1
  51. package/dist/v1/index.mjs +5 -1
  52. package/dist/v1/libs/TinyColorConverter.cjs +578 -0
  53. package/dist/v1/libs/TinyColorConverter.d.mts +396 -0
  54. package/dist/v1/libs/TinyColorConverter.mjs +520 -0
  55. package/dist/v1/libs/TinyEvents.cjs +363 -0
  56. package/dist/v1/libs/TinyEvents.d.mts +160 -0
  57. package/dist/v1/libs/TinyEvents.mjs +328 -0
  58. package/dist/v1/libs/TinyLocalStorage.cjs +847 -0
  59. package/dist/v1/libs/TinyLocalStorage.d.mts +407 -0
  60. package/dist/v1/libs/TinyLocalStorage.mjs +740 -0
  61. package/dist/v1/libs/TinySmartScroller.cjs +207 -52
  62. package/dist/v1/libs/TinySmartScroller.d.mts +164 -16
  63. package/dist/v1/libs/TinySmartScroller.mjs +181 -52
  64. package/dist/v1/libs/TinyTimeout.cjs +194 -0
  65. package/dist/v1/libs/TinyTimeout.d.mts +89 -0
  66. package/dist/v1/libs/TinyTimeout.mjs +179 -0
  67. package/dist/v1/libs/TinyUploadClicker.cjs +1 -0
  68. package/docs/v1/README.md +4 -0
  69. package/docs/v1/libs/TinyColorConverter.md +220 -0
  70. package/docs/v1/libs/TinyEvents.md +199 -0
  71. package/docs/v1/libs/TinyLocalStorage.md +350 -0
  72. package/docs/v1/libs/TinyRateLimiter.md +0 -3
  73. package/docs/v1/libs/TinyTimeout.md +190 -0
  74. package/package.json +28 -5
@@ -0,0 +1,179 @@
1
+ /**
2
+ * A utility class to manage dynamically adjusted timeouts based on how often
3
+ * each unique ID is triggered. Also provides polling support for asynchronous conditions.
4
+ */
5
+ class TinyTimeout {
6
+ /** @type {boolean} Whether this instance has been destroyed. */
7
+ #isDestroyed = false;
8
+ /** @type {boolean} Whether to allow auto-updating an ID's timeout config if `value` changes. */
9
+ #allowAutoConfigChange;
10
+ /** @type {number} The interval time (ms) used to decrement cooldown counters. */
11
+ #cooldownWatcherTime;
12
+ /** @type {NodeJS.Timeout|null} Reference to the internal cooldown interval. */
13
+ #cooldownWatcher = null;
14
+ /**
15
+ * Internal map that keeps track of how many times each ID has been triggered,
16
+ * along with the base multiplier used to calculate delays.
17
+ *
18
+ * @type {Map<string, { value: number, now: number }>}
19
+ */
20
+ #timeoutFixer = new Map();
21
+ /**
22
+ * Creates a new instance of TinyTimeout.
23
+ *
24
+ * @param {Object} [options={}] Optional configuration object.
25
+ * @param {number} [options.cooldownWatcherTime=5000] Interval in milliseconds for reducing `now` counters.
26
+ * @param {boolean} [options.allowAutoConfigChange=false] Whether to allow auto value changes for existing IDs.
27
+ */
28
+ constructor({ cooldownWatcherTime = 5000, allowAutoConfigChange = false } = {}) {
29
+ if (!Number.isFinite(cooldownWatcherTime) || cooldownWatcherTime <= 0)
30
+ throw new TypeError(`Expected 'cooldownWatcherTime' to be a positive number.`);
31
+ if (typeof allowAutoConfigChange !== 'boolean')
32
+ throw new TypeError(`Expected 'allowAutoConfigChange' to be a boolean.`);
33
+ this.#cooldownWatcherTime = cooldownWatcherTime;
34
+ this.#allowAutoConfigChange = allowAutoConfigChange;
35
+ this.setCooldownWatcherTime(cooldownWatcherTime);
36
+ }
37
+ /**
38
+ * Whether this instance has been destroyed and is no longer usable.
39
+ *
40
+ * @returns {boolean}
41
+ */
42
+ isDestroyed() {
43
+ return this.#isDestroyed;
44
+ }
45
+ /**
46
+ * Whether auto config change is enabled.
47
+ *
48
+ * @returns {boolean}
49
+ */
50
+ getAllowAutoConfigChange() {
51
+ return this.#allowAutoConfigChange;
52
+ }
53
+ /**
54
+ * Gets the interval time used for cooldown decrementing.
55
+ *
56
+ * @returns {number}
57
+ */
58
+ getCooldownWatcherTime() {
59
+ return this.#cooldownWatcherTime;
60
+ }
61
+ /**
62
+ * Sets whether to allow auto-updating an ID's timeout config if `value` changes.
63
+ *
64
+ * @param {boolean} value
65
+ */
66
+ setAllowAutoConfigChange(value) {
67
+ if (typeof value !== 'boolean')
68
+ throw new TypeError(`Expected 'value' to be a boolean.`);
69
+ this.#allowAutoConfigChange = value;
70
+ }
71
+ /**
72
+ * Sets the cooldown watcher interval time.
73
+ * Automatically resets the interval if it was already running.
74
+ *
75
+ * @param {number} value
76
+ */
77
+ setCooldownWatcherTime(value) {
78
+ if (this.#isDestroyed)
79
+ throw new Error('TinyTimeout has been destroyed.');
80
+ if (!Number.isFinite(value) || value <= 0)
81
+ throw new TypeError(`Expected 'value' to be a positive number.`);
82
+ this.#cooldownWatcherTime = value;
83
+ if (this.#cooldownWatcher)
84
+ clearInterval(this.#cooldownWatcher);
85
+ this.#cooldownWatcher = setInterval(() => {
86
+ this.#timeoutFixer.forEach((data) => {
87
+ if (data.now > 0)
88
+ data.now--;
89
+ });
90
+ }, this.#cooldownWatcherTime);
91
+ }
92
+ /**
93
+ * Schedules a callback using a dynamically adjusted timeout based on usage frequency.
94
+ * The more often an ID is triggered, the longer the timeout becomes,
95
+ * scaled by the provided `value`. Optionally, the delay can be limited by `limit`.
96
+ *
97
+ * @param {string} id - A unique identifier to track timeout usage.
98
+ * @param {Function} callback - The function to execute after the delay.
99
+ * @param {number} value - Base delay multiplier in milliseconds.
100
+ * @param {number|null} [limit=null] - Optional maximum delay cap.
101
+ * @returns {number} Handle to the scheduled timeout.
102
+ * @throws {Error} Throws if the instance has been destroyed or arguments are invalid.
103
+ */
104
+ set(id, callback, value, limit = null) {
105
+ if (this.#isDestroyed)
106
+ throw new Error('TinyTimeout has been destroyed.');
107
+ if (typeof id !== 'string' || id.trim() === '')
108
+ throw new TypeError(`Expected 'id' to be a non-empty string.`);
109
+ if (typeof callback !== 'function')
110
+ throw new TypeError(`Expected 'callback' to be a function.`);
111
+ if (!Number.isFinite(value) || value < 0)
112
+ throw new TypeError(`Expected 'value' to be a non-negative number.`);
113
+ if (limit !== null && (!Number.isFinite(limit) || limit < 0))
114
+ throw new TypeError(`Expected 'limit' to be null or a non-negative number.`);
115
+ let entry = this.#timeoutFixer.get(id);
116
+ if (!entry || (this.#allowAutoConfigChange && value !== entry.value)) {
117
+ entry = { value, now: 0 };
118
+ this.#timeoutFixer.set(id, entry);
119
+ }
120
+ const delay = entry.value * entry.now;
121
+ entry.now++;
122
+ return setTimeout(callback, typeof limit === 'number' ? Math.min(delay, limit) : delay);
123
+ }
124
+ /**
125
+ * Waits until a provided function returns `true`, checking repeatedly at the defined interval.
126
+ * Useful for polling asynchronous conditions.
127
+ *
128
+ * @param {() => boolean} getValue - A function that returns `true` when the condition is met.
129
+ * @param {number} [checkInterval=100] - How often (in ms) to check the condition.
130
+ * @returns {Promise<void>} Resolves when the condition is met.
131
+ * @throws {TypeError} If arguments are invalid.
132
+ */
133
+ static waitForTrue(getValue, checkInterval = 100) {
134
+ if (typeof getValue !== 'function')
135
+ throw new TypeError(`Expected 'getValue' to be a function.`);
136
+ if (!Number.isFinite(checkInterval) || checkInterval <= 0)
137
+ throw new TypeError(`Expected 'checkInterval' to be a positive number.`);
138
+ return new Promise((resolve) => {
139
+ const interval = setInterval(() => {
140
+ if (getValue()) {
141
+ clearInterval(interval);
142
+ resolve();
143
+ }
144
+ }, checkInterval);
145
+ });
146
+ }
147
+ /**
148
+ * Instance version of `waitForTrue`, which defaults to using the instance's
149
+ * cooldownWatcherTime if not explicitly provided.
150
+ *
151
+ * @param {() => boolean} getValue - A function that returns `true` when the condition is met.
152
+ * @param {number|null} [checkInterval=100] - How often (in ms) to check the condition.
153
+ * @returns {Promise<void>} Resolves when the condition is met.
154
+ * @throws {Error} If the instance is destroyed or arguments are invalid.
155
+ */
156
+ waitForTrue(getValue, checkInterval = 100) {
157
+ if (this.#isDestroyed)
158
+ throw new Error('TinyTimeout has been destroyed.');
159
+ if (typeof getValue !== 'function')
160
+ throw new TypeError(`Expected 'getValue' to be a function.`);
161
+ if (checkInterval !== null && (!Number.isFinite(checkInterval) || checkInterval <= 0))
162
+ throw new TypeError(`Expected 'checkInterval' to be null or a positive number.`);
163
+ return TinyTimeout.waitForTrue(getValue, checkInterval ?? this.#cooldownWatcherTime);
164
+ }
165
+ /**
166
+ * Cleans up all internal references and stops the cooldown watcher.
167
+ * After calling this, the instance becomes unusable.
168
+ */
169
+ destroy() {
170
+ if (this.#isDestroyed)
171
+ return;
172
+ this.#isDestroyed = true;
173
+ if (this.#cooldownWatcher)
174
+ clearInterval(this.#cooldownWatcher);
175
+ this.#cooldownWatcher = null;
176
+ this.#timeoutFixer.clear();
177
+ }
178
+ }
179
+ export default TinyTimeout;
@@ -6,6 +6,7 @@ require('./TinyHtml.cjs');
6
6
  require('fs');
7
7
  require('path');
8
8
  require('fs/promises');
9
+ require('./TinyLocalStorage.cjs');
9
10
 
10
11
  /**
11
12
  * @typedef {Object} UploaderConfig
package/docs/v1/README.md CHANGED
@@ -40,6 +40,10 @@ This folder contains the core scripts we have worked on so far. Each file is a m
40
40
  - 📋 **[TinyClipboard](./libs/TinyClipboard.md)** — A clipboard management utility with support for modern APIs, legacy fallbacks, and custom copy handlers for text and blobs, plus flexible read operations and clipboard item filtering.
41
41
  - 🍮 **[UltraRandomMsgGen](./libs/UltraRandomMsgGen.md)** — A whimsical random message generator using grammar templates, word sets, emojis, and chaotic modes to craft playful text outputs.
42
42
  - ✍️ **[TinyTextRangeEditor](./libs/TinyTextRangeEditor.md)** — An flexible text range manipulation utility for `input` and `textarea` elements. Supports selection, cursor control, tag insertion, attribute handling, inline editing, formatting, and advanced wrap/toggle logic with optional spacing auto-completion.
43
+ - ⏳ **[TinyTimeout](./libs/TinyTimeout.md)** — A dynamic timeout and delay manager with support for usage-based throttling, delay scaling, configurable decay intervals, and asynchronous polling for conditions.
44
+ - 🌈 **[TinyColorConverter](./libs/TinyColorConverter.md)** — A complete color conversion toolkit supporting hex, RGB(A), HSL(A), and integer formats, with smooth gradient generation, color parsing, and multi-format output conversion.
45
+ - 📡 **[TinyEvents](./libs/TinyEvents.md)** — A lightweight and dependency-free event emitter inspired by Node.js, supporting persistent and one-time listeners, listener inspection, and max listener limits.
46
+ - 📦 **[TinyLocalStorage](./libs/TinyLocalStorage.md)** — A tiny wrapper for `localStorage` with full support for objects, arrays, `Map`, `Set`, and typed value helpers like string, number, and boolean.
43
47
 
44
48
  ### 3. **`fileManager/`**
45
49
  * 📁 **[Main](./fileManager/main.md)** — A Node.js file/directory utility module with support for JSON, backups, renaming, size analysis, and more.
@@ -0,0 +1,220 @@
1
+ # 🎨 `TinyColorConverter`
2
+
3
+ A JavaScript class for **color conversion and manipulation** between Hex, RGB(A), HSL(A), and integer formats. It also supports generation of color gradients and random color generation.
4
+
5
+ ---
6
+
7
+ ## 📦 Features
8
+
9
+ * Convert between Hex, RGB, RGBA, HSL, HSLA, and integers
10
+ * Parse various color input formats
11
+ * Generate pastel or full-spectrum rainbow gradients 🌈
12
+ * Return colors in multiple formats (strings, arrays, objects)
13
+ * Get random colors easily!
14
+
15
+ ---
16
+
17
+ ## 🧱 Types
18
+
19
+ ### `RgbColor`
20
+
21
+ ```ts
22
+ [number, number, number]
23
+ ```
24
+
25
+ * Red, Green, Blue — integers from `0` to `255`
26
+
27
+ ### `RgbaColor`
28
+
29
+ ```ts
30
+ [number, number, number, number]
31
+ ```
32
+
33
+ * Red, Green, Blue, Alpha — all from `0` to `255`
34
+
35
+ ### `HslColor`
36
+
37
+ ```ts
38
+ [number, number, number]
39
+ ```
40
+
41
+ * Hue `0–360`, Saturation and Lightness `0–100`
42
+
43
+ ### `HslaColor`
44
+
45
+ ```ts
46
+ [number, number, number, number]
47
+ ```
48
+
49
+ * Like `HslColor`, but with alpha (0–255)
50
+
51
+ ### `HexColor`
52
+
53
+ ```ts
54
+ string
55
+ ```
56
+
57
+ * Hex string, like `#ff33aa`
58
+
59
+ ### `ColorTypes`
60
+
61
+ ```ts
62
+ HexColor | number | RgbColor | RgbaColor
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 🧪 Result Object Types
68
+
69
+ ### `RgbResult`
70
+
71
+ ```ts
72
+ { r: number, g: number, b: number }
73
+ ```
74
+
75
+ ### `RgbaResult`
76
+
77
+ ```ts
78
+ { r: number, g: number, b: number, a: number }
79
+ ```
80
+
81
+ ### `HexResult`
82
+
83
+ ```ts
84
+ { hex: string }
85
+ ```
86
+
87
+ ### `HslResult`
88
+
89
+ ```ts
90
+ { h: number, s: number, l: number }
91
+ ```
92
+
93
+ ---
94
+
95
+ ## 🎲 Random Color
96
+
97
+ ### `TinyColorConverter.randomColor()`
98
+
99
+ Returns a completely random hex color.
100
+
101
+ ```ts
102
+ const hex = TinyColorConverter.randomColor(); // #a4f23b
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 🌈 Rainbow Gradient Generator
108
+
109
+ All three gradient methods use sine wave patterns to generate smooth, eye-pleasing color palettes.
110
+
111
+ ### `TinyColorConverter.rcaRgb(len = 24, pastel = false)`
112
+
113
+ Returns an array of `RgbResult` colors.
114
+
115
+ ### `TinyColorConverter.rcaHex(len = 24, pastel = false)`
116
+
117
+ Returns an array of `HexResult` colors.
118
+
119
+ ### `TinyColorConverter.rcaHsl(len = 24, pastel = false)`
120
+
121
+ Returns an array of `HslResult` colors.
122
+
123
+ > 📌 Set `pastel: true` for lighter, more desaturated tones.
124
+
125
+ ---
126
+
127
+ ## 🛠️ Color Conversion Methods
128
+
129
+ ### Hex <=> Int
130
+
131
+ * `hexToInt(hex): number`
132
+ * `intToHex(int): HexColor`
133
+
134
+ ### Hex <=> RGBA
135
+
136
+ * `hexToRgba(hex): RgbaColor`
137
+ * `hexToRgb(hex): RgbColor`
138
+ * `rgbToHex(r, g, b): HexColor`
139
+
140
+ ### Hex <=> HSL(A)
141
+
142
+ * `hexToHsl(hex): HslColor`
143
+ * `hexToHsla(hex): HslaColor`
144
+ * `hslToHex(h, s, l): HexColor`
145
+
146
+ ### HSL <=> RGB(A)
147
+
148
+ * `hslToRgba(h, s, l, a?): RgbaColor`
149
+ * `hslToRgb(h, s, l, a?): RgbColor`
150
+ * `rgbaToHsl(r, g, b, a?): HslColor`
151
+ * `rgbaToHsla(r, g, b, a?): HslaColor`
152
+
153
+ ### Int <=> RGBA
154
+
155
+ * `intToRgba(int): RgbaColor`
156
+ * `rgbToInt(r, g, b): number`
157
+
158
+ ---
159
+
160
+ ## 🔄 Parsing & String Formats
161
+
162
+ * `parseInput(input: ColorTypes, isHsl: boolean): RgbaColor`
163
+ * `rgbStringToRgbaArray("rgba(...)"): RgbaColor`
164
+ * `hslStringToRgbaArray("hsl(...)"): RgbaColor`
165
+
166
+ ---
167
+
168
+ ## 🧪 Instance API
169
+
170
+ ```ts
171
+ const color = new TinyColorConverter('#ff66cc');
172
+ ```
173
+
174
+ ### `.setColor(input: ColorTypes)`
175
+
176
+ Sets a new color and parses it internally.
177
+
178
+ ### `.getOriginal(): ColorTypes`
179
+
180
+ Returns the original color input.
181
+
182
+ ### `.toRgbaArray(): RgbaColor`
183
+
184
+ Returns the RGBA array.
185
+
186
+ ### `.toHex(): HexColor`
187
+
188
+ Returns the color as hex string.
189
+
190
+ ### `.toInt(): number`
191
+
192
+ Returns the color as a single 24-bit integer.
193
+
194
+ ### `.toRgbString(): string`
195
+
196
+ Returns `'rgb(r, g, b)'` format.
197
+
198
+ ### `.toRgbaString(): string`
199
+
200
+ Returns `'rgba(r, g, b, a)'` format.
201
+
202
+ ### `.toHslString(): string`
203
+
204
+ Returns `'hsl(h, s%, l%)'` format.
205
+
206
+ ### `.toHslaString(): string`
207
+
208
+ Returns `'hsla(h, s%, l%, a)'` format.
209
+
210
+ ### `.toHslaArray(): HslaColor`
211
+
212
+ Returns an array: `[h, s, l, a]`
213
+
214
+ ---
215
+
216
+ ## 🔒 Internal State (Private)
217
+
218
+ * `#original` → stores the input color
219
+ * `#rgba` → RGBA representation
220
+ * `#checkIsHsl` → checks if array input should be interpreted as HSL
@@ -0,0 +1,199 @@
1
+ # 📦 TinyEvents
2
+
3
+ A **lightweight event emitter** class similar to Node.js's `EventEmitter`, written in modern JavaScript with no dependencies. Perfect for publish/subscribe patterns in modular apps.
4
+
5
+ ---
6
+
7
+ ## 🧠 What is TinyEvents?
8
+
9
+ `TinyEvents` enables your components or modules to **subscribe to**, **emit**, and **manage custom events**.
10
+
11
+ It supports:
12
+
13
+ * 🔁 Persistent listeners (`on`, `appendListener`, `prependListener`)
14
+ * 🔂 One-time listeners (`once`, `appendListenerOnce`, `prependListenerOnce`)
15
+ * 📤 Emitting events (`emit`)
16
+ * 🔍 Inspecting listeners (`listenerCount`, `listeners`, `onceListeners`, `allListeners`, `eventNames`)
17
+ * 🧹 Removing listeners (`off`, `offAll`, `offAllTypes`)
18
+ * 🚦 Controlling listener count (`setMaxListeners`, `getMaxListeners`)
19
+
20
+ ---
21
+
22
+ ## 🔧 API Reference
23
+
24
+ ### `on(event: string, handler: function): void`
25
+
26
+ Adds a listener for the specified event.
27
+
28
+ ```js
29
+ emitter.on('hello', (name) => console.log(`Hi, ${name}`));
30
+ ```
31
+
32
+ ---
33
+
34
+ ### `once(event: string, handler: function): function`
35
+
36
+ Adds a one-time listener that is automatically removed after it runs once.
37
+
38
+ ```js
39
+ emitter.once('data', console.log);
40
+ ```
41
+
42
+ ---
43
+
44
+ ### `appendListener(event: string, handler: function): void`
45
+
46
+ Alias for `on()`.
47
+
48
+ ---
49
+
50
+ ### `appendListenerOnce(event: string, handler: function): function`
51
+
52
+ Alias for `once()`.
53
+
54
+ ---
55
+
56
+ ### `prependListener(event: string, handler: function): void`
57
+
58
+ Adds a listener to the **start** of the listener array (called before others).
59
+
60
+ ---
61
+
62
+ ### `prependListenerOnce(event: string, handler: function): function`
63
+
64
+ Adds a one-time listener to the **start** of the listener array.
65
+
66
+ ---
67
+
68
+ ### `emit(event: string, ...payload: any[]): boolean`
69
+
70
+ Calls all listeners for an event, passing any number of arguments.
71
+
72
+ Returns `true` if any listeners were called, otherwise `false`.
73
+
74
+ ```js
75
+ emitter.emit('greet', 'Yasmin', 21);
76
+ ```
77
+
78
+ ---
79
+
80
+ ### `off(event: string, handler: function): void`
81
+
82
+ Removes a specific listener from an event.
83
+
84
+ ---
85
+
86
+ ### `offAll(event: string): void`
87
+
88
+ Removes **all listeners** for a specific event.
89
+
90
+ ---
91
+
92
+ ### `offAllTypes(): void`
93
+
94
+ Clears **all listeners** from **all events**.
95
+
96
+ ---
97
+
98
+ ### `listenerCount(event: string): number`
99
+
100
+ Returns how many listeners are currently registered for the event.
101
+
102
+ ---
103
+
104
+ ### `listeners(event: string): function[]`
105
+
106
+ Returns an array of **non-once** listener functions for an event.
107
+
108
+ ---
109
+
110
+ ### `onceListeners(event: string): function[]`
111
+
112
+ Returns an array of **once-only** listener functions for an event.
113
+
114
+ ---
115
+
116
+ ### `allListeners(event: string): function[]`
117
+
118
+ Returns all listeners, including wrapped `once()` functions.
119
+
120
+ ---
121
+
122
+ ### `eventNames(): string[]`
123
+
124
+ Returns an array of event names that currently have listeners.
125
+
126
+ ---
127
+
128
+ ### `setMaxListeners(n: number): void`
129
+
130
+ Sets the maximum allowed listeners per event. Shows a warning if exceeded.
131
+
132
+ ---
133
+
134
+ ### `getMaxListeners(): number`
135
+
136
+ Returns the current max listener limit (default: 10).
137
+
138
+ ---
139
+
140
+ ### `setThrowOnMaxListeners(shouldThrow: boolean): void`
141
+
142
+ Enables or disables the behavior of throwing an error when the number of listeners exceeds the maximum limit.
143
+
144
+ * If `true`, the class will **throw an error** instead of just logging a warning.
145
+ * If `false`, it will default to console warning (default behavior).
146
+
147
+ #### Parameters:
148
+
149
+ * `shouldThrow` *(boolean)* – Whether to throw an error when the listener limit is exceeded.
150
+
151
+ ---
152
+
153
+ ### `getThrowOnMaxListeners(): boolean`
154
+
155
+ Returns whether the emitter is currently set to throw an error when the maximum number of listeners is exceeded.
156
+
157
+ #### Returns:
158
+
159
+ * *(boolean)* – `true` if error throwing is enabled, otherwise `false`.
160
+
161
+ ---
162
+
163
+ ## 🧪 Example
164
+
165
+ ```js
166
+ import TinyEvents from './TinyEvents.js';
167
+
168
+ const emitter = new TinyEvents();
169
+
170
+ function greet(name) {
171
+ console.log(`👋 Hello, ${name}`);
172
+ }
173
+
174
+ emitter.on('greet', greet);
175
+ emitter.emit('greet', 'Yasmin'); // "👋 Hello, Yasmin"
176
+ emitter.off('greet', greet);
177
+ ```
178
+
179
+ ---
180
+
181
+ ## 🛡️ Type Definitions
182
+
183
+ ```ts
184
+ /**
185
+ * A generic event listener callback function.
186
+ * @callback handler
187
+ * @param {...any} payload - Arguments passed when event is emitted.
188
+ * @returns {void}
189
+ */
190
+ ```
191
+
192
+ ---
193
+
194
+ ## ✅ Why Use It?
195
+
196
+ * No dependencies
197
+ * Fully typed (with JSDoc)
198
+ * Inspired by Node.js EventEmitter
199
+ * Works in browser or Node