@oscarpalmer/atoms 0.186.2 → 0.187.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 (229) hide show
  1. package/dist/array/filter.d.mts +4 -4
  2. package/dist/array/find.d.mts +4 -4
  3. package/dist/array/first.d.mts +4 -4
  4. package/dist/array/get.d.mts +27 -1
  5. package/dist/array/get.mjs +5 -3
  6. package/dist/array/group-by.d.mts +6 -6
  7. package/dist/array/last.d.mts +4 -4
  8. package/dist/array/match.d.mts +7 -6
  9. package/dist/array/move.d.mts +7 -7
  10. package/dist/array/move.mjs +1 -1
  11. package/dist/array/select.d.mts +1 -0
  12. package/dist/array/slice.d.mts +3 -3
  13. package/dist/array/sort.d.mts +10 -7
  14. package/dist/array/sort.mjs +4 -3
  15. package/dist/array/swap.d.mts +1 -1
  16. package/dist/array/swap.mjs +1 -1
  17. package/dist/array/to-map.d.mts +32 -32
  18. package/dist/array/to-record.d.mts +6 -6
  19. package/dist/array/to-set.d.mts +6 -6
  20. package/dist/beacon.d.mts +6 -0
  21. package/dist/beacon.mjs +3 -0
  22. package/dist/color/index.d.mts +6 -2
  23. package/dist/color/index.mjs +6 -2
  24. package/dist/color/instance.d.mts +78 -14
  25. package/dist/color/instance.mjs +78 -14
  26. package/dist/color/misc/get.d.mts +39 -11
  27. package/dist/color/misc/get.mjs +39 -11
  28. package/dist/color/misc/is.d.mts +26 -11
  29. package/dist/color/misc/is.mjs +26 -11
  30. package/dist/color/misc/state.mjs +1 -1
  31. package/dist/color/models.d.mts +7 -4
  32. package/dist/color/space/hex.d.mts +15 -6
  33. package/dist/color/space/hex.mjs +15 -6
  34. package/dist/color/space/hsl.d.mts +10 -4
  35. package/dist/color/space/hsl.mjs +10 -4
  36. package/dist/color/space/rgb.d.mts +21 -12
  37. package/dist/color/space/rgb.mjs +21 -12
  38. package/dist/function/assert.d.mts +20 -14
  39. package/dist/function/assert.mjs +19 -13
  40. package/dist/function/limit.d.mts +8 -6
  41. package/dist/function/limit.mjs +8 -6
  42. package/dist/function/memoize.d.mts +15 -4
  43. package/dist/function/memoize.mjs +18 -4
  44. package/dist/function/once.d.mts +5 -3
  45. package/dist/function/once.mjs +5 -3
  46. package/dist/function/retry.d.mts +5 -2
  47. package/dist/function/retry.mjs +3 -1
  48. package/dist/function/work.d.mts +146 -98
  49. package/dist/{kalas.d.mts → herald.d.mts} +17 -8
  50. package/dist/{kalas.mjs → herald.mjs} +22 -13
  51. package/dist/index.d.mts +1464 -708
  52. package/dist/index.mjs +677 -324
  53. package/dist/internal/array/index-of.d.mts +4 -4
  54. package/dist/internal/array/insert.mjs +1 -1
  55. package/dist/internal/array/shuffle.d.mts +1 -0
  56. package/dist/internal/array/shuffle.mjs +2 -1
  57. package/dist/internal/is.d.mts +26 -8
  58. package/dist/internal/is.mjs +26 -8
  59. package/dist/internal/math/aggregate.d.mts +9 -9
  60. package/dist/internal/number.d.mts +13 -2
  61. package/dist/internal/number.mjs +13 -2
  62. package/dist/internal/random.d.mts +4 -2
  63. package/dist/internal/random.mjs +7 -5
  64. package/dist/internal/result.d.mts +17 -11
  65. package/dist/internal/result.mjs +10 -14
  66. package/dist/internal/string.d.mts +16 -1
  67. package/dist/internal/string.mjs +24 -1
  68. package/dist/internal/value/compare.d.mts +5 -2
  69. package/dist/internal/value/compare.mjs +5 -2
  70. package/dist/internal/value/equal.d.mts +12 -3
  71. package/dist/internal/value/equal.mjs +7 -4
  72. package/dist/internal/value/get.d.mts +17 -17
  73. package/dist/internal/value/has.d.mts +55 -11
  74. package/dist/internal/value/set.d.mts +24 -0
  75. package/dist/is.d.mts +12 -0
  76. package/dist/is.mjs +16 -1
  77. package/dist/logger.d.mts +7 -6
  78. package/dist/logger.mjs +6 -5
  79. package/dist/math.d.mts +36 -18
  80. package/dist/math.mjs +6 -3
  81. package/dist/models.d.mts +3 -3
  82. package/dist/promise/delay.d.mts +2 -0
  83. package/dist/promise/helpers.d.mts +6 -4
  84. package/dist/promise/helpers.mjs +6 -4
  85. package/dist/promise/index.d.mts +49 -38
  86. package/dist/promise/misc.d.mts +10 -7
  87. package/dist/promise/misc.mjs +4 -3
  88. package/dist/promise/models.d.mts +18 -19
  89. package/dist/promise/models.mjs +4 -3
  90. package/dist/promise/timed.d.mts +8 -6
  91. package/dist/query.d.mts +2 -0
  92. package/dist/query.mjs +2 -0
  93. package/dist/queue.d.mts +15 -4
  94. package/dist/queue.mjs +10 -3
  95. package/dist/random.d.mts +9 -2
  96. package/dist/random.mjs +7 -2
  97. package/dist/result/index.d.mts +14 -8
  98. package/dist/result/match.d.mts +18 -10
  99. package/dist/result/misc.d.mts +14 -7
  100. package/dist/result/misc.mjs +4 -2
  101. package/dist/result/models.d.mts +2 -0
  102. package/dist/result/work/flow.d.mts +86 -62
  103. package/dist/result/work/pipe.d.mts +55 -33
  104. package/dist/sized/map.d.mts +19 -16
  105. package/dist/sized/map.mjs +4 -4
  106. package/dist/sized/set.d.mts +20 -16
  107. package/dist/sized/set.mjs +8 -7
  108. package/dist/string/case.d.mts +8 -0
  109. package/dist/string/case.mjs +8 -0
  110. package/dist/string/fuzzy.d.mts +19 -5
  111. package/dist/string/fuzzy.mjs +7 -0
  112. package/dist/string/index.d.mts +17 -2
  113. package/dist/string/index.mjs +7 -9
  114. package/dist/string/match.d.mts +3 -0
  115. package/dist/string/match.mjs +3 -0
  116. package/dist/string/normalize.d.mts +6 -2
  117. package/dist/string/normalize.mjs +5 -2
  118. package/dist/string/template.d.mts +38 -9
  119. package/dist/string/template.mjs +19 -19
  120. package/dist/value/clone.d.mts +25 -4
  121. package/dist/value/clone.mjs +36 -22
  122. package/dist/value/collection.d.mts +9 -6
  123. package/dist/value/collection.mjs +3 -2
  124. package/dist/value/diff.d.mts +3 -1
  125. package/dist/value/diff.mjs +1 -0
  126. package/dist/value/freeze.d.mts +118 -9
  127. package/dist/value/freeze.mjs +56 -14
  128. package/dist/value/index.d.mts +1 -2
  129. package/dist/value/index.mjs +1 -2
  130. package/dist/value/merge.d.mts +11 -5
  131. package/dist/value/merge.mjs +2 -2
  132. package/dist/value/omit.d.mts +1 -0
  133. package/dist/value/omit.mjs +1 -0
  134. package/dist/value/pick.d.mts +1 -0
  135. package/dist/value/pick.mjs +1 -0
  136. package/dist/value/shake.d.mts +1 -0
  137. package/dist/value/shake.mjs +1 -0
  138. package/dist/value/smush.d.mts +1 -0
  139. package/dist/value/smush.mjs +1 -0
  140. package/dist/value/transform.d.mts +7 -3
  141. package/dist/value/unsmush.d.mts +1 -0
  142. package/dist/value/unsmush.mjs +1 -0
  143. package/package.json +11 -7
  144. package/src/array/filter.ts +4 -4
  145. package/src/array/find.ts +4 -4
  146. package/src/array/first.ts +4 -4
  147. package/src/array/get.ts +40 -5
  148. package/src/array/group-by.ts +6 -6
  149. package/src/array/last.ts +4 -4
  150. package/src/array/match.ts +7 -6
  151. package/src/array/move.ts +7 -7
  152. package/src/array/select.ts +1 -0
  153. package/src/array/slice.ts +3 -3
  154. package/src/array/sort.ts +15 -10
  155. package/src/array/swap.ts +1 -1
  156. package/src/array/to-map.ts +32 -32
  157. package/src/array/to-record.ts +6 -6
  158. package/src/array/to-set.ts +6 -6
  159. package/src/beacon.ts +6 -0
  160. package/src/color/index.ts +6 -2
  161. package/src/color/instance.ts +78 -14
  162. package/src/color/misc/get.ts +39 -11
  163. package/src/color/misc/is.ts +26 -11
  164. package/src/color/misc/state.ts +1 -1
  165. package/src/color/models.ts +7 -4
  166. package/src/color/space/hex.ts +15 -6
  167. package/src/color/space/hsl.ts +10 -4
  168. package/src/color/space/rgb.ts +21 -12
  169. package/src/function/assert.ts +20 -14
  170. package/src/function/limit.ts +8 -6
  171. package/src/function/memoize.ts +24 -5
  172. package/src/function/once.ts +5 -3
  173. package/src/function/retry.ts +7 -3
  174. package/src/function/work.ts +146 -98
  175. package/src/{kalas.ts → herald.ts} +23 -14
  176. package/src/index.ts +3 -2
  177. package/src/internal/array/index-of.ts +4 -4
  178. package/src/internal/array/insert.ts +1 -1
  179. package/src/internal/array/shuffle.ts +2 -1
  180. package/src/internal/is.ts +26 -8
  181. package/src/internal/math/aggregate.ts +9 -9
  182. package/src/internal/number.ts +13 -2
  183. package/src/internal/random.ts +10 -4
  184. package/src/internal/result.ts +30 -29
  185. package/src/internal/string.ts +28 -0
  186. package/src/internal/value/compare.ts +5 -2
  187. package/src/internal/value/equal.ts +13 -4
  188. package/src/internal/value/get.ts +17 -17
  189. package/src/internal/value/has.ts +54 -11
  190. package/src/internal/value/set.ts +24 -0
  191. package/src/is.ts +15 -1
  192. package/src/logger.ts +8 -7
  193. package/src/math.ts +36 -18
  194. package/src/models.ts +3 -3
  195. package/src/promise/delay.ts +2 -0
  196. package/src/promise/helpers.ts +6 -4
  197. package/src/promise/index.ts +49 -38
  198. package/src/promise/misc.ts +10 -7
  199. package/src/promise/models.ts +18 -19
  200. package/src/promise/timed.ts +8 -6
  201. package/src/query.ts +2 -0
  202. package/src/queue.ts +15 -4
  203. package/src/random.ts +8 -1
  204. package/src/result/index.ts +14 -8
  205. package/src/result/match.ts +18 -10
  206. package/src/result/misc.ts +17 -9
  207. package/src/result/models.ts +2 -0
  208. package/src/result/work/flow.ts +86 -62
  209. package/src/result/work/pipe.ts +55 -33
  210. package/src/sized/map.ts +20 -17
  211. package/src/sized/set.ts +21 -17
  212. package/src/string/case.ts +8 -0
  213. package/src/string/fuzzy.ts +19 -5
  214. package/src/string/index.ts +18 -15
  215. package/src/string/match.ts +3 -0
  216. package/src/string/normalize.ts +6 -2
  217. package/src/string/template.ts +69 -18
  218. package/src/value/clone.ts +51 -26
  219. package/src/value/collection.ts +9 -6
  220. package/src/value/diff.ts +3 -1
  221. package/src/value/freeze.ts +239 -25
  222. package/src/value/index.ts +0 -1
  223. package/src/value/merge.ts +11 -5
  224. package/src/value/omit.ts +1 -0
  225. package/src/value/pick.ts +1 -0
  226. package/src/value/shake.ts +1 -0
  227. package/src/value/smush.ts +1 -0
  228. package/src/value/transform.ts +7 -3
  229. package/src/value/unsmush.ts +1 -0
@@ -9,55 +9,86 @@ import { getColorState, setHSLColor, setHexColor, setRGBColor } from "./misc/sta
9
9
  var Color = class {
10
10
  #state;
11
11
  /**
12
- * Get the alpha channel
12
+ * Get the alpha channel _(opacity)_ of the color
13
+ *
14
+ * @returns Current alpha channel value between `0` and `1`
13
15
  */
14
16
  get alpha() {
15
17
  return this.#state.alpha.value;
16
18
  }
17
19
  /**
18
- * Set the alpha channel
20
+ * Set the alpha channel _(opacity)_ of the color, as:
21
+ *
22
+ * - A number between `0` and `1`, where `0` is fully transparent and `1` is fully opaque
23
+ * - A number between `0` and `100`, where `0` is fully transparent and `100` is fully opaque
24
+ *
25
+ * @param value New alpha channel value
19
26
  */
20
27
  set alpha(value) {
21
28
  if (typeof value === "number" && !Number.isNaN(value)) this.#state.alpha = getAlpha(value);
22
29
  }
23
30
  /**
24
- * Get the color as a hex color
31
+ * Get the color as a hex color string
32
+ *
33
+ * _Hex color string is returned with no `#`-prefix or alpha channel (opacity)_
34
+ *
35
+ * @returns Current color as a hex color string
25
36
  */
26
37
  get hex() {
27
38
  return this.#state.hex;
28
39
  }
29
40
  /**
30
- * Set colors from a hex color
41
+ * Set the color from a hex color string
42
+ *
43
+ * - `#`-prefix is optional
44
+ * - Alpha channel _(opacity)_ will be ignored
45
+ *
46
+ * @param value New hex color string
31
47
  */
32
48
  set hex(value) {
33
49
  setHexColor(this.#state, value, false);
34
50
  }
35
51
  /**
36
- * Get the color as a hex color with an alpha channel
52
+ * Get the color as a hex color with an alpha channel _(opacity)_
53
+ *
54
+ * _Hex color string is returned with alpha channel (opacity), but without `#`-prefix_
55
+ *
56
+ * @returns Current color as a hex color string
37
57
  */
38
58
  get hexa() {
39
59
  return `${this.#state.hex}${this.#state.alpha.hex}`;
40
60
  }
41
61
  /**
42
- * Set colors and alpha from a hex color with an alpha channel
62
+ * Set the color from a hex color string with an alpha channel _(opacity)_
63
+ *
64
+ * - `#`-prefix is optional
65
+ * - Alpha channel _(opacity)_ will be respected
66
+ *
67
+ * @param value New hex color string
43
68
  */
44
69
  set hexa(value) {
45
70
  setHexColor(this.#state, value, true);
46
71
  }
47
72
  /**
48
- * Get the color as an HSL color
73
+ * Get the color as an _HSL_ color
74
+ *
75
+ * @returns Current color as an _HSL_ color
49
76
  */
50
77
  get hsl() {
51
78
  return this.#state.hsl;
52
79
  }
53
80
  /**
54
- * Set colors from an HSL color
81
+ * Set colors from an _HSL_ color
82
+ *
83
+ * @param value New _HSL_ color
55
84
  */
56
85
  set hsl(value) {
57
86
  setHSLColor(this.#state, value, false);
58
87
  }
59
88
  /**
60
- * Get the color as an HSLA color
89
+ * Get the color as an _HSLA_ color
90
+ *
91
+ * @returns Current color as an _HSLA_ color
61
92
  */
62
93
  get hsla() {
63
94
  return {
@@ -66,25 +97,33 @@ var Color = class {
66
97
  };
67
98
  }
68
99
  /**
69
- * Set colors and alpha from an HSLA color
100
+ * Set colors and alpha from an _HSLA_ color
101
+ *
102
+ * @param value New _HSLA_ color
70
103
  */
71
104
  set hsla(value) {
72
105
  setHSLColor(this.#state, value, true);
73
106
  }
74
107
  /**
75
- * Get the color as an RGB color
108
+ * Get the color as an _RGB_ color
109
+ *
110
+ * @returns Current color as an _RGB_ color
76
111
  */
77
112
  get rgb() {
78
113
  return this.#state.rgb;
79
114
  }
80
115
  /**
81
- * Set colors from an RGB color
116
+ * Set colors from an _RGB_ color
117
+ *
118
+ * @param value New _RGB_ color
82
119
  */
83
120
  set rgb(value) {
84
121
  setRGBColor(this.#state, value, false);
85
122
  }
86
123
  /**
87
- * Get the color as an RGBA color
124
+ * Get the color as an _RGBA_ color
125
+ *
126
+ * @returns Current color as an _RGBA_ color
88
127
  */
89
128
  get rgba() {
90
129
  return {
@@ -93,7 +132,9 @@ var Color = class {
93
132
  };
94
133
  }
95
134
  /**
96
- * Set colors and alpha from an RGBA color
135
+ * Set colors and alpha from an _RGBA_ color
136
+ *
137
+ * @param value New _RGBA_ color
97
138
  */
98
139
  set rgba(value) {
99
140
  setRGBColor(this.#state, value, true);
@@ -102,15 +143,38 @@ var Color = class {
102
143
  this.#state = getColorState(value);
103
144
  Object.defineProperty(this, "$color", { value: true });
104
145
  }
146
+ /**
147
+ * Get the color as a hex string
148
+ *
149
+ * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
150
+ * @returns Hex color string
151
+ */
105
152
  toHexString(alpha) {
106
153
  return `#${alpha === true ? this.hexa : this.hex}`;
107
154
  }
155
+ /**
156
+ * Get the color as an _HSL(A)_ string
157
+ *
158
+ * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
159
+ * @returns _HSL(A)_ color string
160
+ */
108
161
  toHslString(alpha) {
109
162
  return formatColor("hsl", this, alpha === true);
110
163
  }
164
+ /**
165
+ * Get the color as an _RGB(A)_ string
166
+ *
167
+ * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
168
+ * @returns _RGB(A)_ color string
169
+ */
111
170
  toRgbString(alpha) {
112
171
  return formatColor("rgb", this, alpha === true);
113
172
  }
173
+ /**
174
+ * Get the color as a hex color string
175
+ *
176
+ * @returns Hex color string
177
+ */
114
178
  toString() {
115
179
  return this.toHexString();
116
180
  }
@@ -4,47 +4,75 @@ import { Color } from "../instance.mjs";
4
4
  //#region src/color/misc/get.d.ts
5
5
  /**
6
6
  * Get a foreground color _(usually text)_ based on a background color's luminance
7
+ *
8
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
9
+ * - If the value cannot be parsed, a white foreground color will be returned
10
+ *
7
11
  * @param value Original value
8
12
  * @returns Foreground color
9
13
  */
10
14
  declare function getForegroundColor(value: unknown): Color;
11
15
  /**
12
- * Get the hex color _(with alpha channel)_ from any kind of value
16
+ * Get the hex color _(with alpha channel, i.e., opacity)_ from any kind of value
17
+ *
18
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
19
+ * - If the value cannot be parsed, a black hex color with an alpha channel of `0` will be returned
20
+ *
13
21
  * @param value Original value
14
- * @returns Hex color
22
+ * @returns Hex color string
15
23
  */
16
24
  declare function getHexaColor(value: unknown): string;
17
25
  /**
18
26
  * Get the hex color from any kind of value
27
+ *
28
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
29
+ * - If the value cannot be parsed, a black hex color will be returned
30
+ *
19
31
  * @param value Original value
20
- * @returns Hex color
32
+ * @returns Hex color string
21
33
  */
22
34
  declare function getHexColor(value: unknown): string;
23
35
  declare function getHexValue(value: unknown): number;
24
36
  declare function getDegrees(value: unknown): number;
25
37
  /**
26
- * Get the HSLA color from any kind of value
38
+ * Get the _HSLA_ color from any kind of value
39
+ *
40
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
41
+ * - If the value cannot be parsed, a black _HSLA_ color with an alpha channel _(opacity)_ of `0` will be returned
42
+ *
27
43
  * @param value Original value
28
- * @returns HSLA color
44
+ * @returns _HSLA_ color
29
45
  */
30
46
  declare function getHslaColor(value: unknown): HSLAColor;
31
47
  /**
32
- * Get the HSL color from any kind of value
48
+ * Get the _HSL_ color from any kind of value
49
+ *
50
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
51
+ * - If the value cannot be parsed, a black _HSL_ color will be returned
52
+ *
33
53
  * @param value Original value
34
- * @returns HSL color
54
+ * @returns _HSL_ color
35
55
  */
36
56
  declare function getHslColor(value: unknown): HSLColor;
37
57
  declare function getPercentage(value: unknown): number;
38
58
  /**
39
- * Get the RGBA color from any kind of value
59
+ * Get the _RGBA_ color from any kind of value
60
+ *
61
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
62
+ * - If the value cannot be parsed, a black _RGBA_ color with an alpha channel _(opacity)_ of `0` will be returned
63
+ *
40
64
  * @param value Original value
41
- * @returns RGBA color
65
+ * @returns _RGBA_ color
42
66
  */
43
67
  declare function getRgbaColor(value: unknown): RGBAColor;
44
68
  /**
45
- * Get the RGB color from any kind of value
69
+ * Get the _RGB_ color from any kind of value
70
+ *
71
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
72
+ * - If the value cannot be parsed, a black _RGB_ color will be returned
73
+ *
46
74
  * @param value Original value
47
- * @returns RGB color
75
+ * @returns _RGB_ color
48
76
  */
49
77
  declare function getRgbColor(value: unknown): RGBColor;
50
78
  //#endregion
@@ -8,6 +8,10 @@ function getClampedValue(value, minimum, maximum) {
8
8
  }
9
9
  /**
10
10
  * Get a foreground color _(usually text)_ based on a background color's luminance
11
+ *
12
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
13
+ * - If the value cannot be parsed, a white foreground color will be returned
14
+ *
11
15
  * @param value Original value
12
16
  * @returns Foreground color
13
17
  */
@@ -27,9 +31,13 @@ function getForegroundColor(value) {
27
31
  return new Color(.2126 * values[2] + .7152 * values[1] + .0722 * values[0] > .625 ? HEX_BLACK : HEX_WHITE);
28
32
  }
29
33
  /**
30
- * Get the hex color _(with alpha channel)_ from any kind of value
34
+ * Get the hex color _(with alpha channel, i.e., opacity)_ from any kind of value
35
+ *
36
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
37
+ * - If the value cannot be parsed, a black hex color with an alpha channel of `0` will be returned
38
+ *
31
39
  * @param value Original value
32
- * @returns Hex color
40
+ * @returns Hex color string
33
41
  */
34
42
  function getHexaColor(value) {
35
43
  const { alpha, hex } = getColorState(value);
@@ -37,8 +45,12 @@ function getHexaColor(value) {
37
45
  }
38
46
  /**
39
47
  * Get the hex color from any kind of value
48
+ *
49
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
50
+ * - If the value cannot be parsed, a black hex color will be returned
51
+ *
40
52
  * @param value Original value
41
- * @returns Hex color
53
+ * @returns Hex color string
42
54
  */
43
55
  function getHexColor(value) {
44
56
  return getColorState(value).hex;
@@ -50,9 +62,13 @@ function getDegrees(value) {
50
62
  return getClampedValue(value, 0, 360);
51
63
  }
52
64
  /**
53
- * Get the HSLA color from any kind of value
65
+ * Get the _HSLA_ color from any kind of value
66
+ *
67
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
68
+ * - If the value cannot be parsed, a black _HSLA_ color with an alpha channel _(opacity)_ of `0` will be returned
69
+ *
54
70
  * @param value Original value
55
- * @returns HSLA color
71
+ * @returns _HSLA_ color
56
72
  */
57
73
  function getHslaColor(value) {
58
74
  const { alpha, hsl } = getColorState(value);
@@ -62,9 +78,13 @@ function getHslaColor(value) {
62
78
  };
63
79
  }
64
80
  /**
65
- * Get the HSL color from any kind of value
81
+ * Get the _HSL_ color from any kind of value
82
+ *
83
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
84
+ * - If the value cannot be parsed, a black _HSL_ color will be returned
85
+ *
66
86
  * @param value Original value
67
- * @returns HSL color
87
+ * @returns _HSL_ color
68
88
  */
69
89
  function getHslColor(value) {
70
90
  return getColorState(value).hsl;
@@ -73,9 +93,13 @@ function getPercentage(value) {
73
93
  return getClampedValue(value, 0, 100);
74
94
  }
75
95
  /**
76
- * Get the RGBA color from any kind of value
96
+ * Get the _RGBA_ color from any kind of value
97
+ *
98
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
99
+ * - If the value cannot be parsed, a black _RGBA_ color with an alpha channel _(opacity)_ of `0` will be returned
100
+ *
77
101
  * @param value Original value
78
- * @returns RGBA color
102
+ * @returns _RGBA_ color
79
103
  */
80
104
  function getRgbaColor(value) {
81
105
  const { alpha, rgb } = getColorState(value);
@@ -85,9 +109,13 @@ function getRgbaColor(value) {
85
109
  };
86
110
  }
87
111
  /**
88
- * Get the RGB color from any kind of value
112
+ * Get the _RGB_ color from any kind of value
113
+ *
114
+ * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
115
+ * - If the value cannot be parsed, a black _RGB_ color will be returned
116
+ *
89
117
  * @param value Original value
90
- * @returns RGB color
118
+ * @returns _RGB_ color
91
119
  */
92
120
  function getRgbColor(value) {
93
121
  return getColorState(value).rgb;
@@ -3,41 +3,56 @@ import { Color } from "../instance.mjs";
3
3
 
4
4
  //#region src/color/misc/is.d.ts
5
5
  /**
6
- * Is the value a Color?
6
+ * Is the value a _Color_?
7
+ *
7
8
  * @param value Value to check
8
- * @returns `true` if the value is a Color, otherwise `false`
9
+ * @returns `true` if the value is a _Color_, otherwise `false`
9
10
  */
10
11
  declare function isColor(value: unknown): value is Color;
11
12
  /**
12
13
  * Is the value a hex color?
14
+ *
13
15
  * @param value Value to check
14
- * @param alpha Allow alpha channel? _(defaults to `true`)_
16
+ * @param alpha Allow alpha channel _(opacity)_? _(defaults to `true`)_
15
17
  * @returns `true` if the value is a hex color, otherwise `false`
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * isHexColor('ff0000'); // => true
22
+ * isHexColor('#ff0000'); // => true
23
+ *
24
+ * isHexColor('#ff000050'); // => true
25
+ * isHexColor('#ff000050', false); // => false
26
+ * ```
16
27
  */
17
28
  declare function isHexColor(value: unknown, alpha?: boolean): value is string;
18
29
  /**
19
- * Is the value an HSLA color?
30
+ * Is the value an _HSLA_ color?
31
+ *
20
32
  * @param value Value to check
21
- * @returns `true` if the value is an HSLA color, otherwise `false`
33
+ * @returns `true` if the value is an _HSLA_ color, otherwise `false`
22
34
  */
23
35
  declare function isHslaColor(value: unknown): value is HSLAColor;
24
36
  /**
25
- * Is the value an HSL color?
37
+ * Is the value an _HSL_ color?
38
+ *
26
39
  * @param value Value to check
27
- * @returns `true` if the value is an HSL color, otherwise `false`
40
+ * @returns `true` if the value is an _HSL_ color, otherwise `false`
28
41
  */
29
42
  declare function isHslColor(value: unknown): value is HSLColor;
30
43
  declare function isHslLike(value: unknown): value is Record<keyof HSLColor, unknown>;
31
44
  /**
32
- * Is the value an RGBA color?
45
+ * Is the value an _RGBA_ color?
46
+ *
33
47
  * @param value Value to check
34
- * @returns `true` if the value is an RGBA color, otherwise `false`
48
+ * @returns `true` if the value is an _RGBA_ color, otherwise `false`
35
49
  */
36
50
  declare function isRgbaColor(value: unknown): value is RGBAColor;
37
51
  /**
38
- * Is the value an RGB color?
52
+ * Is the value an _RGB_ color?
53
+ *
39
54
  * @param value Value to check
40
- * @returns `true` if the value is an RGB color, otherwise `false`
55
+ * @returns `true` if the value is an _RGB_ color, otherwise `false`
41
56
  */
42
57
  declare function isRgbColor(value: unknown): value is RGBColor;
43
58
  declare function isRgbLike(value: unknown): value is Record<keyof RGBColor, unknown>;
@@ -11,9 +11,10 @@ function isBytey(value) {
11
11
  return typeof value === "number" && between(value, 0, 255);
12
12
  }
13
13
  /**
14
- * Is the value a Color?
14
+ * Is the value a _Color_?
15
+ *
15
16
  * @param value Value to check
16
- * @returns `true` if the value is a Color, otherwise `false`
17
+ * @returns `true` if the value is a _Color_, otherwise `false`
17
18
  */
18
19
  function isColor(value) {
19
20
  return typeof value === "object" && value !== null && "$color" in value && value.$color === true;
@@ -34,9 +35,19 @@ function isDegree(value) {
34
35
  }
35
36
  /**
36
37
  * Is the value a hex color?
38
+ *
37
39
  * @param value Value to check
38
- * @param alpha Allow alpha channel? _(defaults to `true`)_
40
+ * @param alpha Allow alpha channel _(opacity)_? _(defaults to `true`)_
39
41
  * @returns `true` if the value is a hex color, otherwise `false`
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * isHexColor('ff0000'); // => true
46
+ * isHexColor('#ff0000'); // => true
47
+ *
48
+ * isHexColor('#ff000050'); // => true
49
+ * isHexColor('#ff000050', false); // => false
50
+ * ```
40
51
  */
41
52
  function isHexColor(value, alpha) {
42
53
  if (typeof value !== "string") return false;
@@ -45,17 +56,19 @@ function isHexColor(value, alpha) {
45
56
  return true;
46
57
  }
47
58
  /**
48
- * Is the value an HSLA color?
59
+ * Is the value an _HSLA_ color?
60
+ *
49
61
  * @param value Value to check
50
- * @returns `true` if the value is an HSLA color, otherwise `false`
62
+ * @returns `true` if the value is an _HSLA_ color, otherwise `false`
51
63
  */
52
64
  function isHslaColor(value) {
53
65
  return isColorValue(value, KEYS_HSLA);
54
66
  }
55
67
  /**
56
- * Is the value an HSL color?
68
+ * Is the value an _HSL_ color?
69
+ *
57
70
  * @param value Value to check
58
- * @returns `true` if the value is an HSL color, otherwise `false`
71
+ * @returns `true` if the value is an _HSL_ color, otherwise `false`
59
72
  */
60
73
  function isHslColor(value) {
61
74
  return isColorValue(value, KEYS_HSLA) || isColorValue(value, KEYS_HSL);
@@ -64,17 +77,19 @@ function isHslLike(value) {
64
77
  return hasKeys(value, KEYS_HSL);
65
78
  }
66
79
  /**
67
- * Is the value an RGBA color?
80
+ * Is the value an _RGBA_ color?
81
+ *
68
82
  * @param value Value to check
69
- * @returns `true` if the value is an RGBA color, otherwise `false`
83
+ * @returns `true` if the value is an _RGBA_ color, otherwise `false`
70
84
  */
71
85
  function isRgbaColor(value) {
72
86
  return isColorValue(value, KEYS_RGBA);
73
87
  }
74
88
  /**
75
- * Is the value an RGB color?
89
+ * Is the value an _RGB_ color?
90
+ *
76
91
  * @param value Value to check
77
- * @returns `true` if the value is an RGB color, otherwise `false`
92
+ * @returns `true` if the value is an _RGB_ color, otherwise `false`
78
93
  */
79
94
  function isRgbColor(value) {
80
95
  return isColorValue(value, KEYS_RGBA) || isColorValue(value, KEYS_RGB);
@@ -41,7 +41,7 @@ function getColorState(value) {
41
41
  }
42
42
  }
43
43
  state.alpha ??= getAlpha(1);
44
- state.hex ??= String(HEX_BLACK);
44
+ state.hex ??= HEX_BLACK;
45
45
  state.hsl ??= { ...DEFAULT_HSL };
46
46
  state.rgb ??= { ...DEFAULT_RGB };
47
47
  return state;
@@ -4,14 +4,17 @@ type Alpha = {
4
4
  value: number;
5
5
  };
6
6
  type ColorWithAlpha = {
7
+ /**
8
+ * Alpha channel _(opacity)_ of the color _(in percentage; 0-100)_
9
+ */
7
10
  alpha: number;
8
11
  };
9
12
  /**
10
- * An _HSL_-color with an alpha channel
13
+ * An _HSL_ color with an alpha channel _(opacity)_
11
14
  */
12
15
  type HSLAColor = HSLColor & ColorWithAlpha;
13
16
  /**
14
- * An _HSL_-color
17
+ * An _HSL_ color
15
18
  */
16
19
  type HSLColor = {
17
20
  /**
@@ -28,11 +31,11 @@ type HSLColor = {
28
31
  saturation: number;
29
32
  };
30
33
  /**
31
- * An _RGB_-color with an alpha channel
34
+ * An _RGB_ color with an alpha channel _(opacity)_
32
35
  */
33
36
  type RGBAColor = RGBColor & ColorWithAlpha;
34
37
  /**
35
- * An _RGB_-color
38
+ * An _RGB_ color
36
39
  */
37
40
  type RGBColor = {
38
41
  /**
@@ -3,23 +3,32 @@ import { HSLAColor, HSLColor, RGBAColor, RGBColor } from "../models.mjs";
3
3
  //#region src/color/space/hex.d.ts
4
4
  /**
5
5
  * Get the normalized hex color from a value
6
+ *
7
+ * _If the value is unable to be parsed or normalized, a hex color of `000000` will be returned, with the alpha channel _(opacity)_ value `0` included, if specified_
8
+ *
6
9
  * @param value Value to normalize
7
- * @param alpha Include alpha channel? _(defaults to `false`)_
8
- * @returns Normalized hex color, or `000000` if the value is unable to be normalized
10
+ * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
11
+ * @returns Normalized hex color
9
12
  */
10
13
  declare function getNormalizedHex(value: unknown, alpha?: boolean): string;
11
14
  declare function hexToHsl(value: string): HSLColor;
12
15
  declare function hexToHsla(value: string): HSLAColor;
13
16
  /**
14
- * Convert a hex color to an RGB color
17
+ * Convert a hex color to an _RGB_ color
18
+ *
19
+ * _If the value is unable to be converted, a black RGB color will be returned_
20
+ *
15
21
  * @param value Original value
16
- * @returns RGB color
22
+ * @returns _RGB_ color
17
23
  */
18
24
  declare function hexToRgb(value: string): RGBColor;
19
25
  /**
20
- * Convert a hex color to an RGBA color
26
+ * Convert a hex color to an _RGBA_ color
27
+ *
28
+ * _If the value is unable to be converted, a black RGBA color with an alpha channel (opacity) of `0` will be returned_
29
+ *
21
30
  * @param value Original value
22
- * @returns RGBA color
31
+ * @returns _RGBA_ color
23
32
  */
24
33
  declare function hexToRgba(value: string): RGBAColor;
25
34
  //#endregion
@@ -18,9 +18,12 @@ function convertHexToRgba(value) {
18
18
  }
19
19
  /**
20
20
  * Get the normalized hex color from a value
21
+ *
22
+ * _If the value is unable to be parsed or normalized, a hex color of `000000` will be returned, with the alpha channel _(opacity)_ value `0` included, if specified_
23
+ *
21
24
  * @param value Value to normalize
22
- * @param alpha Include alpha channel? _(defaults to `false`)_
23
- * @returns Normalized hex color, or `000000` if the value is unable to be normalized
25
+ * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
26
+ * @returns Normalized hex color
24
27
  */
25
28
  function getNormalizedHex(value, alpha) {
26
29
  const includeAlpha = alpha ?? false;
@@ -41,9 +44,12 @@ function hexToHsla(value) {
41
44
  return convertRgbToHsla(convertHexToRgba(value));
42
45
  }
43
46
  /**
44
- * Convert a hex color to an RGB color
47
+ * Convert a hex color to an _RGB_ color
48
+ *
49
+ * _If the value is unable to be converted, a black RGB color will be returned_
50
+ *
45
51
  * @param value Original value
46
- * @returns RGB color
52
+ * @returns _RGB_ color
47
53
  */
48
54
  function hexToRgb(value) {
49
55
  const { blue, green, red } = convertHexToRgba(value);
@@ -54,9 +60,12 @@ function hexToRgb(value) {
54
60
  };
55
61
  }
56
62
  /**
57
- * Convert a hex color to an RGBA color
63
+ * Convert a hex color to an _RGBA_ color
64
+ *
65
+ * _If the value is unable to be converted, a black RGBA color with an alpha channel (opacity) of `0` will be returned_
66
+ *
58
67
  * @param value Original value
59
- * @returns RGBA color
68
+ * @returns _RGBA_ color
60
69
  */
61
70
  function hexToRgba(value) {
62
71
  return convertHexToRgba(value);
@@ -4,17 +4,23 @@ import { HSLAColor, HSLColor, RGBAColor, RGBColor } from "../models.mjs";
4
4
  declare function getHslValue(value: Record<keyof HSLColor, unknown>): HSLColor;
5
5
  declare function hslToHex(hsl: HSLAColor | HSLColor, alpha?: boolean): string;
6
6
  /**
7
- * Convert an HSL(A) color to an RGB color
7
+ * Convert an _HSL(A)_ color to an _RGB_ color
8
+ *
9
+ * _If the value is unable to be converted, a black RGB color will be returned_
10
+ *
11
+ * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
8
12
  *
9
- * Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61
10
13
  * @param hsl HSL(A) color
11
14
  * @returns RGB color
12
15
  */
13
16
  declare function hslToRgb(hsl: HSLAColor | HSLColor): RGBColor;
14
17
  /**
15
- * Convert an HSL(A) color to an RGBA color
18
+ * Convert an _HSL(A)_ color to an _RGBA_ color
19
+ *
20
+ * _If the value is unable to be converted, a black RGBA color with an alpha channel (opactiy) of `0` will be returned_
21
+ *
22
+ * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
16
23
  *
17
- * Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61
18
24
  * @param hsl HSL(A) color
19
25
  * @returns RGBA color
20
26
  */