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.
- package/README.md +17 -3
- package/dist/node_modules/firebase-functions/lib/common/trace.cjs +0 -1
- package/dist/node_modules/firebase-functions/lib/logger/index.cjs +1 -0
- package/dist/v1/ColorSafeStringify.min.js +1 -1
- package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
- package/dist/v1/TinyBasicsEs.js +13 -6
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyClipboard.min.js +1 -1
- package/dist/v1/TinyColorConverter.js +617 -0
- package/dist/v1/TinyColorConverter.min.js +1 -0
- package/dist/v1/TinyDomReadyManager.min.js +1 -1
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +2635 -482
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyEvents.js +402 -0
- package/dist/v1/TinyEvents.min.js +1 -0
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinyLocalStorage.js +1292 -0
- package/dist/v1/TinyLocalStorage.min.js +1 -0
- package/dist/v1/TinyNotifications.min.js +1 -1
- package/dist/v1/TinyNotifyCenter.min.js +1 -1
- package/dist/v1/TinyPromiseQueue.min.js +1 -1
- package/dist/v1/TinyRateLimiter.js +2 -1
- package/dist/v1/TinyRateLimiter.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +570 -52
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyTextRangeEditor.min.js +1 -1
- package/dist/v1/TinyTimeout.js +233 -0
- package/dist/v1/TinyTimeout.min.js +1 -0
- package/dist/v1/TinyToastNotify.min.js +1 -1
- package/dist/v1/TinyUploadClicker.js +1457 -106
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/UltraRandomMsgGen.min.js +1 -1
- package/dist/v1/basics/html.cjs +13 -6
- package/dist/v1/basics/html.d.mts +12 -4
- package/dist/v1/basics/html.mjs +13 -6
- package/dist/v1/build/TinyColorConverter.cjs +7 -0
- package/dist/v1/build/TinyColorConverter.d.mts +3 -0
- package/dist/v1/build/TinyColorConverter.mjs +2 -0
- package/dist/v1/build/TinyEvents.cjs +7 -0
- package/dist/v1/build/TinyEvents.d.mts +3 -0
- package/dist/v1/build/TinyEvents.mjs +2 -0
- package/dist/v1/build/TinyLocalStorage.cjs +7 -0
- package/dist/v1/build/TinyLocalStorage.d.mts +3 -0
- package/dist/v1/build/TinyLocalStorage.mjs +2 -0
- package/dist/v1/build/TinyTimeout.cjs +7 -0
- package/dist/v1/build/TinyTimeout.d.mts +3 -0
- package/dist/v1/build/TinyTimeout.mjs +2 -0
- package/dist/v1/index.cjs +8 -0
- package/dist/v1/index.d.mts +5 -1
- package/dist/v1/index.mjs +5 -1
- package/dist/v1/libs/TinyColorConverter.cjs +578 -0
- package/dist/v1/libs/TinyColorConverter.d.mts +396 -0
- package/dist/v1/libs/TinyColorConverter.mjs +520 -0
- package/dist/v1/libs/TinyEvents.cjs +363 -0
- package/dist/v1/libs/TinyEvents.d.mts +160 -0
- package/dist/v1/libs/TinyEvents.mjs +328 -0
- package/dist/v1/libs/TinyLocalStorage.cjs +847 -0
- package/dist/v1/libs/TinyLocalStorage.d.mts +407 -0
- package/dist/v1/libs/TinyLocalStorage.mjs +740 -0
- package/dist/v1/libs/TinySmartScroller.cjs +207 -52
- package/dist/v1/libs/TinySmartScroller.d.mts +164 -16
- package/dist/v1/libs/TinySmartScroller.mjs +181 -52
- package/dist/v1/libs/TinyTimeout.cjs +194 -0
- package/dist/v1/libs/TinyTimeout.d.mts +89 -0
- package/dist/v1/libs/TinyTimeout.mjs +179 -0
- package/dist/v1/libs/TinyUploadClicker.cjs +1 -0
- package/docs/v1/README.md +4 -0
- package/docs/v1/libs/TinyColorConverter.md +220 -0
- package/docs/v1/libs/TinyEvents.md +199 -0
- package/docs/v1/libs/TinyLocalStorage.md +350 -0
- package/docs/v1/libs/TinyRateLimiter.md +0 -3
- package/docs/v1/libs/TinyTimeout.md +190 -0
- package/package.json +28 -5
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
# ๐ฆ TinyLocalStorage
|
|
2
|
+
|
|
3
|
+
Tiny wrapper for `localStorage` with full support for complex structures like `Map`, `Set`, `Date`, `RegExp`, `BigInt`, and even custom types. Offers a type-safe interface and a powerful event system via `TinyEvents`.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ๐ Quick Start
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
const storage = new TinyLocalStorage();
|
|
11
|
+
|
|
12
|
+
storage.setString('name', 'Yasmin');
|
|
13
|
+
storage.setNumber('age', 25);
|
|
14
|
+
storage.setBool('likesCats', true);
|
|
15
|
+
storage.setJson('myMap', new Map([['a', 1], ['b', 2]]));
|
|
16
|
+
storage.setDate('today', new Date());
|
|
17
|
+
|
|
18
|
+
console.log(storage.getString('name')); // "Yasmin"
|
|
19
|
+
console.log(storage.getJson('myMap')); // Map { 'a' => 1, 'b' => 2 }
|
|
20
|
+
console.log(storage.getDate('today') instanceof Date); // true
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## ๐ง Features
|
|
26
|
+
|
|
27
|
+
* โ
Store & restore `Map`, `Set`, `Date`, `RegExp`, `BigInt`, `Symbol`, `null`, `undefined`.
|
|
28
|
+
* โ
Custom type encoding and decoding system.
|
|
29
|
+
* โ
Type-safe methods for string, number and boolean.
|
|
30
|
+
* โ
Built-in event system (`TinyEvents`) with optional native `storage` listener.
|
|
31
|
+
* โ
Optional fallback when decoding fails.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## ๐ฆ Storage Methods
|
|
36
|
+
|
|
37
|
+
### `setJson(key, data)`
|
|
38
|
+
|
|
39
|
+
Stores any supported JSON-like structure, including `Map`, `Set`, `Date`, `RegExp`, `BigInt`, etc.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
setJson(name: string, data: LocalStorageJsonValue): void
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### `getJson(key, fallback?)`
|
|
46
|
+
|
|
47
|
+
Retrieves and decodes the previously stored structure. Optional fallback allows recovery on decode failure.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
getJson(
|
|
51
|
+
name: string,
|
|
52
|
+
defaultData?: 'array' | 'obj' | 'map' | 'set' | 'null'
|
|
53
|
+
): LocalStorageJsonValue | null
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
### `setItem(key, rawString)`
|
|
59
|
+
|
|
60
|
+
Stores a raw `string` value as-is.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
setItem(name: string, data: string): void
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### `getItem(key)`
|
|
67
|
+
|
|
68
|
+
Retrieves a raw `string` value.
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
getItem(name: string): string | null
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
### `setString(key, string)`
|
|
77
|
+
|
|
78
|
+
Stores a `string` value.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
setString(name: string, data: string): void
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### `getString(key)`
|
|
85
|
+
|
|
86
|
+
Retrieves a `string` value.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
getString(name: string): string | null
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### `setNumber(key, number)`
|
|
95
|
+
|
|
96
|
+
Stores a `number` value.
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
setNumber(name: string, data: number): void
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### `getNumber(key)`
|
|
103
|
+
|
|
104
|
+
Retrieves a `number` value.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
getNumber(name: string): number | null
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### `setBool(key, boolean)`
|
|
113
|
+
|
|
114
|
+
Stores a `boolean` value.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
setBool(name: string, data: boolean): void
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### `getBool(key)`
|
|
121
|
+
|
|
122
|
+
Retrieves a `boolean` value.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
getBool(name: string): boolean | null
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
### `setDate(key, date)`
|
|
131
|
+
|
|
132
|
+
Stores a `Date` object.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
setDate(name: string, data: Date): void
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### `getDate(key)`
|
|
139
|
+
|
|
140
|
+
Retrieves a `Date` object.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
getDate(name: string): Date | null
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
### `setRegExp(key, pattern)`
|
|
149
|
+
|
|
150
|
+
Stores a `RegExp` object.
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
setRegExp(name: string, data: RegExp): void
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### `getRegExp(key)`
|
|
157
|
+
|
|
158
|
+
Retrieves a `RegExp` object.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
getRegExp(name: string): RegExp | null
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
### `setBigInt(key, value)`
|
|
167
|
+
|
|
168
|
+
Stores a `BigInt` value.
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
setBigInt(name: string, data: bigint): void
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### `getBigInt(key)`
|
|
175
|
+
|
|
176
|
+
Retrieves a `BigInt` value.
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
getBigInt(name: string): bigint | null
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
### `setSymbol(key, value)`
|
|
185
|
+
|
|
186
|
+
Stores a `Symbol`. Only global symbols (`Symbol.for`) will preserve identity.
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
setSymbol(name: string, data: symbol): void
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### `getSymbol(key)`
|
|
193
|
+
|
|
194
|
+
Retrieves a `Symbol` value.
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
getSymbol(name: string): symbol | null
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
### `getValue(key)`
|
|
203
|
+
|
|
204
|
+
Retrieves any previously stored value, regardless of type.
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
getValue(name: string): any | null
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## โ Deletion Methods
|
|
213
|
+
|
|
214
|
+
### `removeItem(key)`
|
|
215
|
+
|
|
216
|
+
Removes a specific key from `localStorage`.
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
removeItem(name: string): void
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### `clearLocalStorage()`
|
|
223
|
+
|
|
224
|
+
Clears all keys in the active storage.
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## ๐ Storage Configuration
|
|
229
|
+
|
|
230
|
+
### `setLocalStorage(storage)`
|
|
231
|
+
|
|
232
|
+
Switch between `localStorage` and `sessionStorage`.
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
setLocalStorage(storage: Storage): void
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### `localStorageExists()`
|
|
239
|
+
|
|
240
|
+
Returns `true` if the browser supports the configured storage backend.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## ๐งฉ Custom Type Registration
|
|
245
|
+
|
|
246
|
+
### `registerJsonType(type, encodeFn, decodeFn)`
|
|
247
|
+
|
|
248
|
+
Registers support for custom types with encoder/decoder logic.
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
registerJsonType(
|
|
252
|
+
type: any,
|
|
253
|
+
encodeFn: (value: any, encodeSpecialJson: EncodeFn) => any,
|
|
254
|
+
decodeFn: {
|
|
255
|
+
check: (value: any) => boolean,
|
|
256
|
+
decode: (value: any, decodeSpecialJson: DecodeFn) => any
|
|
257
|
+
}
|
|
258
|
+
): void
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
### `deleteJsonType(type)`
|
|
264
|
+
|
|
265
|
+
Unregisters a previously registered custom type.
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
deleteJsonType(type: any): void
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Removes the encoder and decoder associated with the given type. Useful for cleanup or reconfiguration.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## ๐ฅ Events (via TinyEvents)
|
|
276
|
+
|
|
277
|
+
### Built-in Events
|
|
278
|
+
|
|
279
|
+
| Event Name | Triggered When... |
|
|
280
|
+
| -------------- | ------------------------------------------- |
|
|
281
|
+
| `'setJson'` | `.setJson()` is called |
|
|
282
|
+
| `'setItem'` | `.setItem()` is called |
|
|
283
|
+
| `'setString'` | `.setString()` is called |
|
|
284
|
+
| `'setNumber'` | `.setNumber()` is called |
|
|
285
|
+
| `'setBool'` | `.setBool()` is called |
|
|
286
|
+
| `'setSymbol'` | `.setSymbol()` is called |
|
|
287
|
+
| `'setBigInt'` | `.setBigInt()` is called |
|
|
288
|
+
| `'setRegExp'` | `.setRegExp()` is called |
|
|
289
|
+
| `'setDate'` | `.setDate()` is called |
|
|
290
|
+
| `'removeItem'` | `.removeItem()` is called |
|
|
291
|
+
| `'storage'` | Browser's native `storage` event (optional) |
|
|
292
|
+
|
|
293
|
+
All events receive `{ key, value }` or `{ key }` depending on context.
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## ๐งน Destroying
|
|
298
|
+
|
|
299
|
+
### `destroy()`
|
|
300
|
+
|
|
301
|
+
Cleans up listeners and internal event systems.
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
destroy(): void
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## ๐งช Type Definition
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
type LocalStorageJsonValue =
|
|
313
|
+
| Record<string | number | symbol, any>
|
|
314
|
+
| any[]
|
|
315
|
+
| Map<string | number | symbol, any>
|
|
316
|
+
| Set<any>;
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## ๐ Internal Helpers
|
|
322
|
+
|
|
323
|
+
### `encodeSpecialJson(value)`
|
|
324
|
+
|
|
325
|
+
Recursively encodes supported complex types into serializable JSON-like structures.
|
|
326
|
+
|
|
327
|
+
### `decodeSpecialJson(value)`
|
|
328
|
+
|
|
329
|
+
Decodes those JSON-like structures back into `Map`, `Set`, `Date`, etc.
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## ๐งช Example: Map, Set, Date, RegExp
|
|
334
|
+
|
|
335
|
+
```js
|
|
336
|
+
const map = new Map([['x', 123]]);
|
|
337
|
+
const set = new Set(['apple', 'banana']);
|
|
338
|
+
const date = new Date();
|
|
339
|
+
const regex = /hello/i;
|
|
340
|
+
|
|
341
|
+
storage.setJson('dataMap', map);
|
|
342
|
+
storage.setJson('dataSet', set);
|
|
343
|
+
storage.setDate('today', date);
|
|
344
|
+
storage.setRegExp('pattern', regex);
|
|
345
|
+
|
|
346
|
+
console.log(storage.getJson('dataMap') instanceof Map); // true
|
|
347
|
+
console.log(storage.getJson('dataSet') instanceof Set); // true
|
|
348
|
+
console.log(storage.getDate('today') instanceof Date); // true
|
|
349
|
+
console.log(storage.getRegExp('pattern') instanceof RegExp); // true
|
|
350
|
+
```
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# ๐ TinyTimeout
|
|
2
|
+
|
|
3
|
+
`TinyTimeout` is a smart utility class designed to help manage dynamically scaled `setTimeout` calls based on how frequently a given ID is triggered. It also supports condition polling (`waitForTrue`) for asynchronous workflows. This is especially useful for cooldown systems, progressive delays, or throttling logic.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## โจ Features
|
|
8
|
+
|
|
9
|
+
* โฑ๏ธ **Dynamic Timeout Scaling** based on trigger frequency
|
|
10
|
+
* ๐ **Auto-decrement cooldowns** over time
|
|
11
|
+
* โ๏ธ Optional **value override support** per ID
|
|
12
|
+
* ๐ **Polling Support** with `waitForTrue`
|
|
13
|
+
* ๐งผ Easy cleanup with `destroy()`
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## ๐ Usage
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
const timeout = new TinyTimeout();
|
|
21
|
+
|
|
22
|
+
// Schedule a timeout with ID tracking and increasing delay
|
|
23
|
+
timeout.set('example-id', () => {
|
|
24
|
+
console.log('Triggered after dynamic delay!');
|
|
25
|
+
}, 200); // 200ms base multiplier
|
|
26
|
+
|
|
27
|
+
// Optional limit
|
|
28
|
+
timeout.set('example-id', () => {
|
|
29
|
+
console.log('Max delay limited to 2000ms');
|
|
30
|
+
}, 500, 2000);
|
|
31
|
+
|
|
32
|
+
// Wait until some condition becomes true
|
|
33
|
+
await timeout.waitForTrue(() => document.readyState === 'complete');
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## ๐ง Constructor
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
new TinyTimeout(options?: {
|
|
42
|
+
cooldownWatcherTime?: number;
|
|
43
|
+
allowAutoConfigChange?: boolean;
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
| Option | Type | Default | Description |
|
|
48
|
+
| ----------------------- | --------- | ------- | -------------------------------------------------------- |
|
|
49
|
+
| `cooldownWatcherTime` | `number` | `5000` | Interval (ms) to decrease cooldown counters. |
|
|
50
|
+
| `allowAutoConfigChange` | `boolean` | `false` | Whether to auto update the base value of an existing ID. |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## ๐ Methods
|
|
55
|
+
|
|
56
|
+
### ๐ง `set(id, callback, value, limit?)`
|
|
57
|
+
|
|
58
|
+
Schedules a timeout using a delay based on how frequently the ID has been triggered.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
set(id: string, callback: Function, value: number, limit?: number | null): number;
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
| Parameter | Type | Required | Description |
|
|
65
|
+
| ---------- | ---------------- | --------- | --------------------------------------------------------------------------- |
|
|
66
|
+
| `id` | `string` | โ
| Unique identifier for the timeout logic. |
|
|
67
|
+
| `callback` | `Function` | โ
| Function to execute after the delay. |
|
|
68
|
+
| `value` | `number` | โ
| Base multiplier for delay in milliseconds. |
|
|
69
|
+
| `limit` | `number \| null` | โ | Optional maximum delay in milliseconds to cap the calculated timeout. |
|
|
70
|
+
|
|
71
|
+
๐ **Returns:**
|
|
72
|
+
A numeric ID returned by `setTimeout`, which can be manually canceled later using `clearTimeout(id)` if necessary.
|
|
73
|
+
|
|
74
|
+
๐ ๏ธ **Behavior:**
|
|
75
|
+
- The more often an `id` is used consecutively, the longer the timeout becomes.
|
|
76
|
+
- This delay is calculated as `value * now`, where `now` increases each time the `id` is triggered.
|
|
77
|
+
- The delay will never exceed `limit` if itโs provided.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
### ๐ `waitForTrue(getValue, checkInterval = 100)`
|
|
82
|
+
|
|
83
|
+
Waits until a provided function returns `true`, polling periodically.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
static waitForTrue(getValue: () => boolean, checkInterval?: number): Promise<void>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
* `getValue`: Function that returns `true` when the wait should end.
|
|
90
|
+
* `checkInterval`: Polling interval in milliseconds.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### ๐งฉ `waitForTrue(getValue, checkInterval?)` *(instance version)*
|
|
95
|
+
|
|
96
|
+
Same as `waitForTrue`, but uses the instance's `cooldownWatcherTime` as the default if `checkInterval` is `null`.
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
waitForTrue(getValue: () => boolean, checkInterval?: number | null): Promise<void>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
### ๐ ๏ธ `setCooldownWatcherTime(value)`
|
|
105
|
+
|
|
106
|
+
Updates the cooldown decrement interval. Automatically restarts the internal timer.
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
setCooldownWatcherTime(value: number): void
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
### โ๏ธ `setAllowAutoConfigChange(value)`
|
|
115
|
+
|
|
116
|
+
Enables or disables automatic value reconfiguration for known IDs.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
setAllowAutoConfigChange(value: boolean): void
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
### โ `getCooldownWatcherTime()`
|
|
125
|
+
|
|
126
|
+
Returns the current interval used for decrementing cooldowns.
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
getCooldownWatcherTime(): number
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
### โ `getAllowAutoConfigChange()`
|
|
135
|
+
|
|
136
|
+
Returns whether auto-config change is enabled.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
getAllowAutoConfigChange(): boolean
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
### ๐ฅ `destroy()`
|
|
145
|
+
|
|
146
|
+
Cleans up all internals, clears intervals, and invalidates the instance.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
destroy(): void
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
### โ
`isDestroyed()`
|
|
155
|
+
|
|
156
|
+
Checks if the instance has already been destroyed.
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
isDestroyed(): boolean
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## ๐งผ Best Practices
|
|
165
|
+
|
|
166
|
+
* Use meaningful `id`s to separate timeout logic across components or users.
|
|
167
|
+
* Consider enabling `allowAutoConfigChange` if base delays change dynamically in your app.
|
|
168
|
+
* Always call `destroy()` when you're done to avoid memory leaks!
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## ๐งช Example
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
const t = new TinyTimeout({ cooldownWatcherTime: 3000 });
|
|
176
|
+
|
|
177
|
+
t.set('search', () => console.log('Search triggered'), 100);
|
|
178
|
+
t.set('search', () => console.log('Slower search due to spamming'), 100);
|
|
179
|
+
t.set('search', () => console.log('Even slower!'), 100, 500);
|
|
180
|
+
|
|
181
|
+
await t.waitForTrue(() => myAsyncCondition === true);
|
|
182
|
+
|
|
183
|
+
t.destroy();
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## ๐ง Why use TinyTimeout?
|
|
189
|
+
|
|
190
|
+
Sometimes `setTimeout` isn't enough when you need backoff, throttling, or async condition checks. TinyTimeout handles usage frequency and time-based cooldown logic all in one place, and its polling function is perfect for complex reactive UIs.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-essentials",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "npm run test:mjs && npm run test:cjs && npm run test:js",
|
|
@@ -62,18 +62,41 @@
|
|
|
62
62
|
"@tinypudding/discord-oauth2",
|
|
63
63
|
"@tinypudding/mysql-connector",
|
|
64
64
|
"@tinypudding/puddy-lib",
|
|
65
|
+
"tiny-essentials",
|
|
66
|
+
"timeout",
|
|
67
|
+
"storage",
|
|
68
|
+
"text-editor",
|
|
69
|
+
"color-converter",
|
|
65
70
|
"clock",
|
|
71
|
+
"time",
|
|
72
|
+
"text",
|
|
73
|
+
"text-range",
|
|
74
|
+
"input-editor",
|
|
75
|
+
"string-utils",
|
|
76
|
+
"string-manipulation",
|
|
66
77
|
"obj-type",
|
|
78
|
+
"type-checker",
|
|
67
79
|
"simple-math",
|
|
68
|
-
"
|
|
69
|
-
"lib",
|
|
70
|
-
"time",
|
|
80
|
+
"math-utils",
|
|
71
81
|
"shuffle-array",
|
|
82
|
+
"array-utils",
|
|
83
|
+
"json",
|
|
84
|
+
"json-utils",
|
|
72
85
|
"json-color",
|
|
86
|
+
"json-highlight",
|
|
87
|
+
"json-viewer",
|
|
73
88
|
"terminal-color",
|
|
89
|
+
"cli-color",
|
|
74
90
|
"cli-output",
|
|
91
|
+
"pretty-print-json",
|
|
75
92
|
"colorize-json",
|
|
76
|
-
"
|
|
93
|
+
"lib",
|
|
94
|
+
"utility",
|
|
95
|
+
"utils",
|
|
96
|
+
"toolkit",
|
|
97
|
+
"frontend-utils",
|
|
98
|
+
"backend-utils",
|
|
99
|
+
"nodejs-utils"
|
|
77
100
|
],
|
|
78
101
|
"author": "Yasmin Seidel (Jasmin Dreasond)",
|
|
79
102
|
"license": "GPL-3.0-only",
|