tiny-essentials 1.10.1 → 1.11.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 (59) hide show
  1. package/README.md +1 -1
  2. package/dist/{TinyBasicsEs.js → v1/TinyBasicsEs.js} +2 -2
  3. package/dist/{TinyEssentials.js → v1/TinyEssentials.js} +806 -2
  4. package/dist/v1/TinyEssentials.min.js +2 -0
  5. package/dist/v1/TinyNotifyCenter.js +461 -0
  6. package/dist/v1/TinyNotifyCenter.min.js +1 -0
  7. package/dist/v1/TinyToastNotify.js +417 -0
  8. package/dist/v1/TinyToastNotify.min.js +1 -0
  9. package/dist/v1/basics/objFilter.cjs +2 -2
  10. package/dist/v1/basics/objFilter.d.mts +2 -2
  11. package/dist/v1/basics/objFilter.mjs +2 -2
  12. package/dist/v1/build/TinyNotifyCenter.cjs +7 -0
  13. package/dist/v1/build/TinyNotifyCenter.d.mts +3 -0
  14. package/dist/v1/build/TinyNotifyCenter.mjs +2 -0
  15. package/dist/v1/build/TinyToastNotify.cjs +7 -0
  16. package/dist/v1/build/TinyToastNotify.d.mts +3 -0
  17. package/dist/v1/build/TinyToastNotify.mjs +2 -0
  18. package/dist/v1/css/TinyNotify.css +350 -0
  19. package/dist/v1/css/TinyNotify.min.css +1 -0
  20. package/dist/v1/index.cjs +4 -0
  21. package/dist/v1/index.d.mts +3 -1
  22. package/dist/v1/index.mjs +3 -1
  23. package/dist/v1/libs/TinyNotifyCenter.cjs +422 -0
  24. package/dist/v1/libs/TinyNotifyCenter.d.mts +166 -0
  25. package/dist/v1/libs/TinyNotifyCenter.mjs +385 -0
  26. package/dist/v1/libs/TinyToastNotify.cjs +378 -0
  27. package/dist/v1/libs/TinyToastNotify.d.mts +157 -0
  28. package/dist/v1/libs/TinyToastNotify.mjs +332 -0
  29. package/docs/{README.md → v1/README.md} +2 -0
  30. package/docs/{basics → v1/basics}/text.md +2 -2
  31. package/docs/v1/libs/TinyNotifyCenter.md +291 -0
  32. package/docs/v1/libs/TinyToastNotify.md +290 -0
  33. package/package.json +4 -2
  34. package/dist/TinyEssentials.min.js +0 -2
  35. package/dist/v1/libs/TinyRateLimit.cjs +0 -196
  36. package/dist/v1/libs/TinyRateLimit.d.mts +0 -86
  37. package/dist/v1/libs/TinyRateLimit.mjs +0 -171
  38. /package/dist/{ColorSafeStringify.js → v1/ColorSafeStringify.js} +0 -0
  39. /package/dist/{ColorSafeStringify.min.js → v1/ColorSafeStringify.min.js} +0 -0
  40. /package/dist/{TinyBasicsEs.min.js → v1/TinyBasicsEs.min.js} +0 -0
  41. /package/dist/{TinyBasicsEs.min.js.LICENSE.txt → v1/TinyBasicsEs.min.js.LICENSE.txt} +0 -0
  42. /package/dist/{TinyEssentials.min.js.LICENSE.txt → v1/TinyEssentials.min.js.LICENSE.txt} +0 -0
  43. /package/dist/{TinyLevelUp.js → v1/TinyLevelUp.js} +0 -0
  44. /package/dist/{TinyLevelUp.min.js → v1/TinyLevelUp.min.js} +0 -0
  45. /package/dist/{TinyPromiseQueue.js → v1/TinyPromiseQueue.js} +0 -0
  46. /package/dist/{TinyPromiseQueue.min.js → v1/TinyPromiseQueue.min.js} +0 -0
  47. /package/dist/{TinyRateLimiter.js → v1/TinyRateLimiter.js} +0 -0
  48. /package/dist/{TinyRateLimiter.min.js → v1/TinyRateLimiter.min.js} +0 -0
  49. /package/dist/{aiMarker.css → v1/css/aiMarker.css} +0 -0
  50. /package/dist/{aiMarker.min.css → v1/css/aiMarker.min.css} +0 -0
  51. /package/docs/{basics → v1/basics}/array.md +0 -0
  52. /package/docs/{basics → v1/basics}/asyncReplace.md +0 -0
  53. /package/docs/{basics → v1/basics}/clock.md +0 -0
  54. /package/docs/{basics → v1/basics}/objFilter.md +0 -0
  55. /package/docs/{basics → v1/basics}/simpleMath.md +0 -0
  56. /package/docs/{libs → v1/libs}/ColorSafeStringify.md +0 -0
  57. /package/docs/{libs → v1/libs}/TinyLevelUp.md +0 -0
  58. /package/docs/{libs → v1/libs}/TinyPromiseQueue.md +0 -0
  59. /package/docs/{libs → v1/libs}/TinyRateLimiter.md +0 -0
@@ -1,86 +0,0 @@
1
- export default TinyRateLimiter;
2
- /**
3
- * Class representing a flexible rate limiter per user.
4
- *
5
- * This rate limiter can be configured by maximum number of hits,
6
- * time interval, or a combination of both. It supports automatic
7
- * cleanup of inactive users to optimize memory usage.
8
- *
9
- * @class
10
- */
11
- declare class TinyRateLimiter {
12
- /**
13
- * @param {Object} options
14
- * @param {number} [options.maxHits] - Max interactions allowed
15
- * @param {number} [options.interval] - Time window in milliseconds
16
- * @param {number} [options.cleanupInterval=60000] - Interval for automatic cleanup (ms)
17
- * @param {number} [options.maxIdle=300000] - Max idle time for a user before being cleaned (ms)
18
- */
19
- constructor({ maxHits, interval, cleanupInterval, maxIdle }: {
20
- maxHits?: number | undefined;
21
- interval?: number | undefined;
22
- cleanupInterval?: number | undefined;
23
- maxIdle?: number | undefined;
24
- });
25
- maxHits: number | null | undefined;
26
- interval: number | null | undefined;
27
- cleanupInterval: number;
28
- maxIdle: number;
29
- /** @type {Map<string, number[]>} */
30
- userData: Map<string, number[]>;
31
- /** @type {Map<string, number>} */
32
- lastSeen: Map<string, number>;
33
- _cleanupTimer: NodeJS.Timeout;
34
- /**
35
- * Get the interval window in milliseconds.
36
- *
37
- * @returns {number} The interval value.
38
- * @throws {Error} If interval is not a valid finite number.
39
- */
40
- getInterval(): number;
41
- /**
42
- * Get the maximum number of allowed hits.
43
- *
44
- * @returns {number} The maxHits value.
45
- * @throws {Error} If maxHits is not a valid finite number.
46
- */
47
- getMaxHits(): number;
48
- /**
49
- * Register a hit for a specific user
50
- * @param {string} userId
51
- */
52
- hit(userId: string): void;
53
- /**
54
- * Check if the user is currently rate limited
55
- * @param {string} userId
56
- * @returns {boolean}
57
- */
58
- isRateLimited(userId: string): boolean;
59
- /**
60
- * Manually reset user data
61
- * @param {string} userId
62
- */
63
- reset(userId: string): void;
64
- /**
65
- * Set hit timestamps for a user
66
- * @param {string} userId
67
- * @param {number[]} timestamps
68
- */
69
- setData(userId: string, timestamps: number[]): void;
70
- /**
71
- * Get timestamps from user
72
- * @param {string} userId
73
- * @returns {number[]}
74
- */
75
- getData(userId: string): number[];
76
- /**
77
- * Cleanup old/inactive users
78
- * @private
79
- */
80
- private _cleanup;
81
- /**
82
- * Destroy the rate limiter, stopping all intervals
83
- */
84
- destroy(): void;
85
- }
86
- //# sourceMappingURL=TinyRateLimit.d.mts.map
@@ -1,171 +0,0 @@
1
- /**
2
- * Class representing a flexible rate limiter per user.
3
- *
4
- * This rate limiter can be configured by maximum number of hits,
5
- * time interval, or a combination of both. It supports automatic
6
- * cleanup of inactive users to optimize memory usage.
7
- *
8
- * @class
9
- */
10
- class TinyRateLimiter {
11
- /**
12
- * @param {Object} options
13
- * @param {number} [options.maxHits] - Max interactions allowed
14
- * @param {number} [options.interval] - Time window in milliseconds
15
- * @param {number} [options.cleanupInterval=60000] - Interval for automatic cleanup (ms)
16
- * @param {number} [options.maxIdle=300000] - Max idle time for a user before being cleaned (ms)
17
- */
18
- constructor({ maxHits, interval, cleanupInterval = 60000, maxIdle = 300000 }) {
19
- /** @param {number|undefined} val */
20
- const isPositiveInteger = (val) => typeof val === 'number' && Number.isFinite(val) && val >= 1 && Number.isInteger(val);
21
- const isMaxHitsValid = isPositiveInteger(maxHits);
22
- const isIntervalValid = isPositiveInteger(interval);
23
- const isCleanupValid = isPositiveInteger(cleanupInterval);
24
- const isMaxIdleValid = isPositiveInteger(maxIdle);
25
- if (!isMaxHitsValid && !isIntervalValid)
26
- throw new Error("RateLimiter requires at least one valid option: 'maxHits' or 'interval'.");
27
- if (maxHits !== undefined && !isMaxHitsValid)
28
- throw new Error("'maxHits' must be a positive integer if defined.");
29
- if (interval !== undefined && !isIntervalValid)
30
- throw new Error("'interval' must be a positive integer in milliseconds if defined.");
31
- if (!isCleanupValid)
32
- throw new Error("'cleanupInterval' must be a positive integer in milliseconds.");
33
- if (!isMaxIdleValid)
34
- throw new Error("'maxIdle' must be a positive integer in milliseconds.");
35
- this.maxHits = isMaxHitsValid ? maxHits : null;
36
- this.interval = isIntervalValid ? interval : null;
37
- this.cleanupInterval = cleanupInterval;
38
- this.maxIdle = maxIdle;
39
- /** @type {Map<string, number[]>} */
40
- this.userData = new Map();
41
- /** @type {Map<string, number>} */
42
- this.lastSeen = new Map();
43
- // Start automatic cleanup
44
- this._cleanupTimer = setInterval(() => this._cleanup(), this.cleanupInterval);
45
- }
46
- /**
47
- * Get the interval window in milliseconds.
48
- *
49
- * @returns {number} The interval value.
50
- * @throws {Error} If interval is not a valid finite number.
51
- */
52
- getInterval() {
53
- if (typeof this.interval !== 'number' || !Number.isFinite(this.interval))
54
- throw new Error("'interval' is not a valid finite number.");
55
- return this.interval;
56
- }
57
- /**
58
- * Get the maximum number of allowed hits.
59
- *
60
- * @returns {number} The maxHits value.
61
- * @throws {Error} If maxHits is not a valid finite number.
62
- */
63
- getMaxHits() {
64
- if (typeof this.maxHits !== 'number' || !Number.isFinite(this.maxHits)) {
65
- throw new Error("'maxHits' is not a valid finite number.");
66
- }
67
- return this.maxHits;
68
- }
69
- /**
70
- * Register a hit for a specific user
71
- * @param {string} userId
72
- */
73
- hit(userId) {
74
- const now = Date.now();
75
- if (!this.userData.has(userId)) {
76
- this.userData.set(userId, []);
77
- }
78
- const history = this.userData.get(userId);
79
- if (!history)
80
- throw new Error(`No data found for userId: ${userId}`);
81
- history.push(now);
82
- this.lastSeen.set(userId, now);
83
- // Clean up old entries
84
- if (this.interval !== null) {
85
- const interval = this.getInterval();
86
- const cutoff = now - interval;
87
- while (history.length && history[0] < cutoff) {
88
- history.shift();
89
- }
90
- }
91
- // Optional: keep only the last N entries for memory optimization
92
- if (this.maxHits !== null) {
93
- const maxHits = this.getMaxHits();
94
- if (history.length > maxHits) {
95
- history.splice(0, history.length - maxHits);
96
- }
97
- }
98
- }
99
- /**
100
- * Check if the user is currently rate limited
101
- * @param {string} userId
102
- * @returns {boolean}
103
- */
104
- isRateLimited(userId) {
105
- const now = Date.now();
106
- if (!this.userData.has(userId))
107
- return false;
108
- const history = this.userData.get(userId);
109
- if (!history)
110
- throw new Error(`No data found for userId: ${userId}`);
111
- if (this.interval !== null) {
112
- const interval = this.getInterval();
113
- const recent = history.filter((t) => t > now - interval);
114
- if (this.maxHits !== null) {
115
- return recent.length >= this.getMaxHits();
116
- }
117
- return recent.length > 0;
118
- }
119
- if (this.maxHits !== null) {
120
- return history.length >= this.getMaxHits();
121
- }
122
- return false;
123
- }
124
- /**
125
- * Manually reset user data
126
- * @param {string} userId
127
- */
128
- reset(userId) {
129
- this.userData.delete(userId);
130
- this.lastSeen.delete(userId);
131
- }
132
- /**
133
- * Set hit timestamps for a user
134
- * @param {string} userId
135
- * @param {number[]} timestamps
136
- */
137
- setData(userId, timestamps) {
138
- this.userData.set(userId, timestamps);
139
- this.lastSeen.set(userId, Date.now());
140
- }
141
- /**
142
- * Get timestamps from user
143
- * @param {string} userId
144
- * @returns {number[]}
145
- */
146
- getData(userId) {
147
- return this.userData.get(userId) || [];
148
- }
149
- /**
150
- * Cleanup old/inactive users
151
- * @private
152
- */
153
- _cleanup() {
154
- const now = Date.now();
155
- for (const [userId, last] of this.lastSeen.entries()) {
156
- if (now - last > this.maxIdle) {
157
- this.userData.delete(userId);
158
- this.lastSeen.delete(userId);
159
- }
160
- }
161
- }
162
- /**
163
- * Destroy the rate limiter, stopping all intervals
164
- */
165
- destroy() {
166
- clearInterval(this._cleanupTimer);
167
- this.userData.clear();
168
- this.lastSeen.clear();
169
- }
170
- }
171
- export default TinyRateLimiter;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes