tiny-essentials 1.18.0 โ†’ 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 (93) hide show
  1. package/README.md +17 -3
  2. package/dist/legacy/get/countObj.cjs +2 -2
  3. package/dist/legacy/get/countObj.d.mts +1 -1
  4. package/dist/legacy/get/countObj.mjs +1 -1
  5. package/dist/legacy/index.cjs +2 -1
  6. package/dist/node_modules/firebase-functions/lib/common/trace.cjs +0 -1
  7. package/dist/node_modules/firebase-functions/lib/logger/index.cjs +1 -0
  8. package/dist/v1/ColorSafeStringify.min.js +1 -1
  9. package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
  10. package/dist/v1/TinyBasicsEs.js +402 -390
  11. package/dist/v1/TinyBasicsEs.min.js +1 -1
  12. package/dist/v1/TinyClipboard.min.js +1 -1
  13. package/dist/v1/TinyColorConverter.js +617 -0
  14. package/dist/v1/TinyColorConverter.min.js +1 -0
  15. package/dist/v1/TinyDomReadyManager.min.js +1 -1
  16. package/dist/v1/TinyDragger.js +6 -2433
  17. package/dist/v1/TinyDragger.min.js +1 -2
  18. package/dist/v1/TinyEssentials.js +3546 -1388
  19. package/dist/v1/TinyEssentials.min.js +1 -1
  20. package/dist/v1/TinyEvents.js +402 -0
  21. package/dist/v1/TinyEvents.min.js +1 -0
  22. package/dist/v1/TinyHtml.min.js +1 -1
  23. package/dist/v1/TinyLocalStorage.js +1292 -0
  24. package/dist/v1/TinyLocalStorage.min.js +1 -0
  25. package/dist/v1/TinyNotifications.min.js +1 -1
  26. package/dist/v1/TinyNotifyCenter.min.js +1 -1
  27. package/dist/v1/TinyPromiseQueue.min.js +1 -1
  28. package/dist/v1/TinyRateLimiter.js +2 -1
  29. package/dist/v1/TinyRateLimiter.min.js +1 -1
  30. package/dist/v1/TinySmartScroller.js +570 -52
  31. package/dist/v1/TinySmartScroller.min.js +1 -1
  32. package/dist/v1/TinyTextRangeEditor.min.js +1 -1
  33. package/dist/v1/TinyTimeout.js +233 -0
  34. package/dist/v1/TinyTimeout.min.js +1 -0
  35. package/dist/v1/TinyToastNotify.min.js +1 -1
  36. package/dist/v1/TinyUploadClicker.js +2087 -1129
  37. package/dist/v1/TinyUploadClicker.min.js +1 -1
  38. package/dist/v1/UltraRandomMsgGen.min.js +1 -1
  39. package/dist/v1/basics/html.cjs +16 -9
  40. package/dist/v1/basics/html.d.mts +12 -4
  41. package/dist/v1/basics/html.mjs +14 -7
  42. package/dist/v1/basics/index.cjs +3 -2
  43. package/dist/v1/basics/index.d.mts +2 -2
  44. package/dist/v1/basics/index.mjs +2 -1
  45. package/dist/v1/basics/objChecker.cjs +46 -0
  46. package/dist/v1/basics/objChecker.d.mts +29 -0
  47. package/dist/v1/basics/objChecker.mjs +45 -0
  48. package/dist/v1/basics/objFilter.cjs +4 -45
  49. package/dist/v1/basics/objFilter.d.mts +3 -28
  50. package/dist/v1/basics/objFilter.mjs +2 -45
  51. package/dist/v1/build/TinyColorConverter.cjs +7 -0
  52. package/dist/v1/build/TinyColorConverter.d.mts +3 -0
  53. package/dist/v1/build/TinyColorConverter.mjs +2 -0
  54. package/dist/v1/build/TinyEvents.cjs +7 -0
  55. package/dist/v1/build/TinyEvents.d.mts +3 -0
  56. package/dist/v1/build/TinyEvents.mjs +2 -0
  57. package/dist/v1/build/TinyLocalStorage.cjs +7 -0
  58. package/dist/v1/build/TinyLocalStorage.d.mts +3 -0
  59. package/dist/v1/build/TinyLocalStorage.mjs +2 -0
  60. package/dist/v1/build/TinyTimeout.cjs +7 -0
  61. package/dist/v1/build/TinyTimeout.d.mts +3 -0
  62. package/dist/v1/build/TinyTimeout.mjs +2 -0
  63. package/dist/v1/index.cjs +11 -2
  64. package/dist/v1/index.d.mts +7 -3
  65. package/dist/v1/index.mjs +7 -2
  66. package/dist/v1/libs/TinyColorConverter.cjs +578 -0
  67. package/dist/v1/libs/TinyColorConverter.d.mts +396 -0
  68. package/dist/v1/libs/TinyColorConverter.mjs +520 -0
  69. package/dist/v1/libs/TinyDragger.cjs +3 -3
  70. package/dist/v1/libs/TinyDragger.mjs +1 -1
  71. package/dist/v1/libs/TinyEvents.cjs +363 -0
  72. package/dist/v1/libs/TinyEvents.d.mts +160 -0
  73. package/dist/v1/libs/TinyEvents.mjs +328 -0
  74. package/dist/v1/libs/TinyLocalStorage.cjs +847 -0
  75. package/dist/v1/libs/TinyLocalStorage.d.mts +407 -0
  76. package/dist/v1/libs/TinyLocalStorage.mjs +740 -0
  77. package/dist/v1/libs/TinySmartScroller.cjs +207 -52
  78. package/dist/v1/libs/TinySmartScroller.d.mts +164 -16
  79. package/dist/v1/libs/TinySmartScroller.mjs +181 -52
  80. package/dist/v1/libs/TinyTimeout.cjs +194 -0
  81. package/dist/v1/libs/TinyTimeout.d.mts +89 -0
  82. package/dist/v1/libs/TinyTimeout.mjs +179 -0
  83. package/dist/v1/libs/TinyUploadClicker.cjs +6 -4
  84. package/docs/v1/README.md +5 -0
  85. package/docs/v1/basics/objChecker.md +47 -0
  86. package/docs/v1/basics/objFilter.md +0 -40
  87. package/docs/v1/libs/TinyColorConverter.md +220 -0
  88. package/docs/v1/libs/TinyEvents.md +199 -0
  89. package/docs/v1/libs/TinyLocalStorage.md +350 -0
  90. package/docs/v1/libs/TinyRateLimiter.md +0 -3
  91. package/docs/v1/libs/TinyTimeout.md +190 -0
  92. package/package.json +28 -5
  93. package/dist/v1/TinyDragger.min.js.LICENSE.txt +0 -8
@@ -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;
@@ -1,10 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var objFilter = require('../basics/objFilter.cjs');
3
+ require('../basics/objFilter.cjs');
4
+ var objChecker = require('../basics/objChecker.cjs');
4
5
  require('./TinyHtml.cjs');
5
6
  require('fs');
6
7
  require('path');
7
8
  require('fs/promises');
9
+ require('./TinyLocalStorage.cjs');
8
10
 
9
11
  /**
10
12
  * @typedef {Object} UploaderConfig
@@ -79,7 +81,7 @@ class TinyUploadClicker {
79
81
  * @throws {TypeError} If the config is invalid or required options are missing.
80
82
  */
81
83
  constructor(options) {
82
- if (!objFilter.isJsonObject(options))
84
+ if (!objChecker.isJsonObject(options))
83
85
  throw new TypeError('TinyUploadClicker: "options" must be a valid object.');
84
86
 
85
87
  this.#config = {
@@ -145,10 +147,10 @@ class TinyUploadClicker {
145
147
  )
146
148
  throw new TypeError('TinyUploadClicker: "onFileLoad" must be a function or null.');
147
149
 
148
- if (options.inputAttributes !== undefined && !objFilter.isJsonObject(options.inputAttributes))
150
+ if (options.inputAttributes !== undefined && !objChecker.isJsonObject(options.inputAttributes))
149
151
  throw new TypeError('TinyUploadClicker: "inputAttributes" must be an object.');
150
152
 
151
- if (options.inputStyles !== undefined && !objFilter.isJsonObject(options.inputStyles))
153
+ if (options.inputStyles !== undefined && !objChecker.isJsonObject(options.inputStyles))
152
154
  throw new TypeError('TinyUploadClicker: "inputStyles" must be an object.');
153
155
 
154
156
  this.#boundClick = this.#handleClick.bind(this);
package/docs/v1/README.md CHANGED
@@ -15,6 +15,7 @@ This folder contains the core scripts we have worked on so far. Each file is a m
15
15
  - ๐Ÿ“ฆ **[Array](./basics/array.md)** โ€” A tiny utility for shuffling arrays using the Fisherโ€“Yates algorithm.
16
16
  - โฐ **[Clock](./basics/clock.md)** โ€” A versatile time utility module for calculating and formatting time durations.
17
17
  - ๐Ÿง  **[ObjFilter](./basics/objFilter.md)** โ€” Type detection, extension, and analysis made easy with simple and extensible type validation.
18
+ * ๐Ÿงฎ **[objChecker](./basics/objChecker.md)** โ€” Utilities for counting keys in objects or arrays and for safely detecting plain JSON-compatible objects.
18
19
  - ๐Ÿ”ข **[SimpleMath](./basics/simpleMath.md)** โ€” A collection of simple math utilities for calculations like the Rule of Three and percentages.
19
20
  - โœ๏ธ **[Text](./basics/text.md)** โ€” A utility for transforming text into title case formats, with multiple options for capitalization.
20
21
  - ๐Ÿ”„ **[AsyncReplace](./basics/asyncReplace.md)** โ€” Asynchronously replaces matches in a string using a regex and an async function.
@@ -39,6 +40,10 @@ This folder contains the core scripts we have worked on so far. Each file is a m
39
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.
40
41
  - ๐Ÿฎ **[UltraRandomMsgGen](./libs/UltraRandomMsgGen.md)** โ€” A whimsical random message generator using grammar templates, word sets, emojis, and chaotic modes to craft playful text outputs.
41
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.
42
47
 
43
48
  ### 3. **`fileManager/`**
44
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,47 @@
1
+ # ๐Ÿง  objChecker.mjs
2
+
3
+ ## ๐Ÿ“˜ Object & Type Utilities
4
+
5
+ This document introduces utility functions designed to help you safely and efficiently work with JavaScript objects and types. These helpers are particularly useful when dealing with dynamic values โ€” especially in situations where data might be coming from APIs, user input, or JSON files.
6
+
7
+ These tools are built to reduce boilerplate code and prevent common mistakes when handling unknown or loosely-typed values in JavaScript.
8
+
9
+ ---
10
+
11
+ ### ๐Ÿงฎ `countObj(obj)`
12
+
13
+ Returns the number of elements in an array or the number of keys in an object.
14
+
15
+ ```js
16
+ countObj([1, 2, 3]); // 3
17
+ countObj({ a: 1, b: 2 }); // 2
18
+ countObj('hi'); // 0
19
+ ```
20
+
21
+ ---
22
+
23
+ ### ๐Ÿงผ `isJsonObject(value)`
24
+
25
+ Check if a value is a **plain JSON-compatible object** โ€” meaning it's created via `{}` or `new Object()`, with a prototype of `Object.prototype`, and **not** a special object like `Date`, `Map`, `Array`, etc.
26
+
27
+ ```js
28
+ isJsonObject({}); // true
29
+ isJsonObject(Object.create({})); // true
30
+ isJsonObject(Object.create(Object.prototype)); // true
31
+ isJsonObject(Object.assign({}, { a: 1 })); // true
32
+ ```
33
+
34
+ ```js
35
+ isJsonObject([]); // false
36
+ isJsonObject(new Date()); // false
37
+ isJsonObject(new Map()); // false
38
+ isJsonObject(Object.create(null)); // false
39
+ ```
40
+
41
+ ๐Ÿ”’ This function ensures the object:
42
+
43
+ * is not `null`
44
+ * has `typeof === 'object'`
45
+ * is **directly** inherited from `Object.prototype`
46
+
47
+ Use this when you need to strictly validate a raw JSON object (like the output of `JSON.parse()` or manual object literals).
@@ -121,18 +121,6 @@ const currentOrder = cloneObjTypeOrder();
121
121
 
122
122
  ---
123
123
 
124
- ### ๐Ÿงฎ `countObj(obj)`
125
-
126
- Returns the number of elements in an array or the number of keys in an object.
127
-
128
- ```js
129
- countObj([1, 2, 3]); // 3
130
- countObj({ a: 1, b: 2 }); // 2
131
- countObj('hi'); // 0
132
- ```
133
-
134
- ---
135
-
136
124
  ## Supported Types
137
125
 
138
126
  Hereโ€™s a full list of supported type names (in their default order):
@@ -164,31 +152,3 @@ You can change this order or insert your own types with `extendObjType`.
164
152
  ### ๐Ÿ› ๏ธ `getCheckObj()`
165
153
 
166
154
  This function creates a clone of the functions from the `typeValidator` object. It returns a new object where the keys are the same and the values are the cloned functions.
167
-
168
- ---
169
-
170
- ### ๐Ÿงผ `isJsonObject(value)`
171
-
172
- Check if a value is a **plain JSON-compatible object** โ€” meaning it's created via `{}` or `new Object()`, with a prototype of `Object.prototype`, and **not** a special object like `Date`, `Map`, `Array`, etc.
173
-
174
- ```js
175
- isJsonObject({}); // true
176
- isJsonObject(Object.create({})); // true
177
- isJsonObject(Object.create(Object.prototype)); // true
178
- isJsonObject(Object.assign({}, { a: 1 })); // true
179
- ```
180
-
181
- ```js
182
- isJsonObject([]); // false
183
- isJsonObject(new Date()); // false
184
- isJsonObject(new Map()); // false
185
- isJsonObject(Object.create(null)); // false
186
- ```
187
-
188
- ๐Ÿ”’ This function ensures the object:
189
-
190
- * is not `null`
191
- * has `typeof === 'object'`
192
- * is **directly** inherited from `Object.prototype`
193
-
194
- Use this when you need to strictly validate a raw JSON object (like the output of `JSON.parse()` or manual object literals).
@@ -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