@library/color 0.0.2 → 0.0.3

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.
@@ -0,0 +1,2 @@
1
+
2
+ 
@@ -1,20 +1,247 @@
1
- PASS src/hex-to-rgb.test.ts
2
- hexToRgb
3
- ✓ hexToRgba("000") (2 ms)
4
- ✓ hexToRgba("#000")
5
- ✓ hexToRgba("#0000") (1 ms)
6
- ✓ hexToRgba("#000000")
7
- ✓ hexToRgba("#00000000") (1 ms)
8
- ✓ hexToRgba("#fff")
9
- ✓ hexToRgba("#ffff")
10
- ✓ hexToRgba("#ffffff")
11
- ✓ hexToRgba("#ffffffff")
12
- ✓ hexToRgba("#f00") (1 ms)
13
- ✓ hexToRgba("#7f11e0")
14
- ✓ hexToRgba("#11223344") (1 ms)
15
-
16
- Test Suites: 1 passed, 1 total
17
- Tests: 12 passed, 12 total
18
- Snapshots: 0 total
19
- Time: 0.752 s, estimated 1 s
20
- Ran all test suites.
1
+
2
+ Determining test suites to run...
3
+
4
+ Test Suites: 0 of 2 total
5
+ Tests: 0 total
6
+ Snapshots: 0 total
7
+ Time: 0 s
8
+
9
+ Test Suites: 0 of 2 total
10
+ Tests: 0 total
11
+ Snapshots: 0 total
12
+ Time: 0 s
13
+  RUNS  src/hexToRgb.spec.ts
14
+  RUNS  src/rgbToHex.spec.ts
15
+
16
+ Test Suites: 0 of 2 total
17
+ Tests: 0 total
18
+ Snapshots: 0 total
19
+ Time: 0 s
20
+
21
+  RUNS  src/hexToRgb.spec.ts
22
+  RUNS  src/rgbToHex.spec.ts
23
+
24
+ Test Suites: 0 of 2 total
25
+ Tests: 0 total
26
+ Snapshots: 0 total
27
+ Time: 0 s
28
+
29
+  RUNS  src/hexToRgb.spec.ts
30
+  RUNS  src/rgbToHex.spec.ts
31
+
32
+ Test Suites: 0 of 2 total
33
+ Tests: 0 total
34
+ Snapshots: 0 total
35
+ Time: 0 s
36
+
37
+  RUNS  src/hexToRgb.spec.ts
38
+  RUNS  src/rgbToHex.spec.ts
39
+
40
+ Test Suites: 0 of 2 total
41
+ Tests: 0 total
42
+ Snapshots: 0 total
43
+ Time: 0 s
44
+
45
+  RUNS  src/hexToRgb.spec.ts
46
+  RUNS  src/rgbToHex.spec.ts
47
+
48
+ Test Suites: 0 of 2 total
49
+ Tests: 0 total
50
+ Snapshots: 0 total
51
+ Time: 0 s
52
+
53
+  RUNS  src/hexToRgb.spec.ts
54
+  RUNS  src/rgbToHex.spec.ts
55
+
56
+ Test Suites: 0 of 2 total
57
+ Tests: 0 total
58
+ Snapshots: 0 total
59
+ Time: 0 s
60
+
61
+  RUNS  src/hexToRgb.spec.ts
62
+  RUNS  src/rgbToHex.spec.ts
63
+
64
+ Test Suites: 0 of 2 total
65
+ Tests: 0 total
66
+ Snapshots: 0 total
67
+ Time: 0 s
68
+
69
+  RUNS  src/hexToRgb.spec.ts
70
+  RUNS  src/rgbToHex.spec.ts
71
+
72
+ Test Suites: 0 of 2 total
73
+ Tests: 0 total
74
+ Snapshots: 0 total
75
+ Time: 0 s
76
+
77
+  RUNS  src/hexToRgb.spec.ts
78
+  RUNS  src/rgbToHex.spec.ts
79
+
80
+ Test Suites: 0 of 2 total
81
+ Tests: 0 total
82
+ Snapshots: 0 total
83
+ Time: 0 s
84
+
85
+  RUNS  src/hexToRgb.spec.ts
86
+  RUNS  src/rgbToHex.spec.ts
87
+
88
+ Test Suites: 0 of 2 total
89
+ Tests: 0 total
90
+ Snapshots: 0 total
91
+ Time: 0 s
92
+
93
+  RUNS  src/hexToRgb.spec.ts
94
+  RUNS  src/rgbToHex.spec.ts
95
+
96
+ Test Suites: 0 of 2 total
97
+ Tests: 0 total
98
+ Snapshots: 0 total
99
+ Time: 0 s
100
+
101
+  RUNS  src/hexToRgb.spec.ts
102
+  RUNS  src/rgbToHex.spec.ts
103
+
104
+ Test Suites: 0 of 2 total
105
+ Tests: 0 total
106
+ Snapshots: 0 total
107
+ Time: 0 s
108
+
109
+  RUNS  src/hexToRgb.spec.ts
110
+  RUNS  src/rgbToHex.spec.ts
111
+
112
+ Test Suites: 0 of 2 total
113
+ Tests: 0 total
114
+ Snapshots: 0 total
115
+ Time: 0 s
116
+
117
+  RUNS  src/hexToRgb.spec.ts
118
+  RUNS  src/rgbToHex.spec.ts
119
+
120
+ Test Suites: 0 of 2 total
121
+ Tests: 0 total
122
+ Snapshots: 0 total
123
+ Time: 0 s
124
+
125
+  RUNS  src/hexToRgb.spec.ts
126
+  RUNS  src/rgbToHex.spec.ts
127
+
128
+ Test Suites: 0 of 2 total
129
+ Tests: 0 total
130
+ Snapshots: 0 total
131
+ Time: 0 s
132
+
133
+  RUNS  src/hexToRgb.spec.ts
134
+  RUNS  src/rgbToHex.spec.ts
135
+
136
+ Test Suites: 0 of 2 total
137
+ Tests: 0 total
138
+ Snapshots: 0 total
139
+ Time: 0 s
140
+
141
+  RUNS  src/hexToRgb.spec.ts
142
+  RUNS  src/rgbToHex.spec.ts
143
+
144
+ Test Suites: 0 of 2 total
145
+ Tests: 0 total
146
+ Snapshots: 0 total
147
+ Time: 0 s
148
+
149
+  RUNS  src/hexToRgb.spec.ts
150
+  RUNS  src/rgbToHex.spec.ts
151
+
152
+ Test Suites: 0 of 2 total
153
+ Tests: 0 total
154
+ Snapshots: 0 total
155
+ Time: 0 s
156
+
157
+  RUNS  src/hexToRgb.spec.ts
158
+  RUNS  src/rgbToHex.spec.ts
159
+
160
+ Test Suites: 0 of 2 total
161
+ Tests: 0 total
162
+ Snapshots: 0 total
163
+ Time: 0 s
164
+
165
+  RUNS  src/hexToRgb.spec.ts
166
+  RUNS  src/rgbToHex.spec.ts
167
+
168
+ Test Suites: 0 of 2 total
169
+ Tests: 0 total
170
+ Snapshots: 0 total
171
+ Time: 0 s
172
+
173
+  RUNS  src/hexToRgb.spec.ts
174
+  RUNS  src/rgbToHex.spec.ts
175
+
176
+ Test Suites: 0 of 2 total
177
+ Tests: 0 total
178
+ Snapshots: 0 total
179
+ Time: 0 s
180
+
181
+  RUNS  src/hexToRgb.spec.ts
182
+  RUNS  src/rgbToHex.spec.ts
183
+
184
+ Test Suites: 0 of 2 total
185
+ Tests: 0 total
186
+ Snapshots: 0 total
187
+ Time: 0 s
188
+
189
+  RUNS  src/hexToRgb.spec.ts
190
+  RUNS  src/rgbToHex.spec.ts
191
+
192
+ Test Suites: 0 of 2 total
193
+ Tests: 0 total
194
+ Snapshots: 0 total
195
+ Time: 0 s
196
+
197
+  RUNS  src/hexToRgb.spec.ts
198
+  RUNS  src/rgbToHex.spec.ts
199
+
200
+ Test Suites: 0 of 2 total
201
+ Tests: 0 total
202
+ Snapshots: 0 total
203
+ Time: 0 s
204
+
205
+  RUNS  src/hexToRgb.spec.ts
206
+  RUNS  src/rgbToHex.spec.ts
207
+
208
+ Test Suites: 0 of 2 total
209
+ Tests: 0 total
210
+ Snapshots: 0 total
211
+ Time: 0 s
212
+
213
+  RUNS  src/hexToRgb.spec.ts
214
+  RUNS  src/rgbToHex.spec.ts
215
+
216
+ Test Suites: 0 of 2 total
217
+ Tests: 0 total
218
+ Snapshots: 0 total
219
+ Time: 0 s
220
+
221
+  RUNS  src/hexToRgb.spec.ts
222
+  RUNS  src/rgbToHex.spec.ts
223
+
224
+ Test Suites: 0 of 2 total
225
+ Tests: 0 total
226
+ Snapshots: 0 total
227
+ Time: 0 s
228
+
229
+  RUNS  src/hexToRgb.spec.ts
230
+  RUNS  src/rgbToHex.spec.ts
231
+
232
+ Test Suites: 0 of 2 total
233
+ Tests: 0 total
234
+ Snapshots: 0 total
235
+ Time: 0 s
236
+
237
+  RUNS  src/hexToRgb.spec.ts
238
+  RUNS  src/rgbToHex.spec.ts
239
+
240
+ Test Suites: 0 of 2 total
241
+ Tests: 0 total
242
+ Snapshots: 0 total
243
+ Time: 0 s
244
+ Tests: 22 passed, 22 total
245
+ Snapshots: 0 total
246
+ Time: 0.537 s
247
+ Ran all test suites.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # @library/color
2
+
3
+ ## Installation
4
+
5
+ **npm**
6
+
7
+ ```console
8
+ npm install @library/color
9
+ ```
10
+
11
+ **yarn**
12
+
13
+ ```console
14
+ yarn add @library/color
15
+ ```
16
+
17
+ ## API
18
+
19
+ - [hexToRgb](#hextorgb)
20
+
21
+ ### hexToRgb
22
+
23
+ Convert a hexadecimal color code to its corresponding RGBA representation.
24
+
25
+ ```ts
26
+ import { hexToRgb } from "@library/color";
27
+
28
+ hexToRgb("#f00"); // { r: 255, g: 0, b: 0, a: 1 }
29
+ hexToRgb("#f000"); // { r: 255, g: 0, b: 0, a: 0 }
30
+ hexToRgb("#7f11e0"); // { r: 127, g: 17, b: 224, a: 1 }
31
+ hexToRgb("#11223344"); // { r: 17, g: 34, b: 51, a: 0.27 }
32
+ ```
@@ -3,7 +3,7 @@
3
3
  <html lang="en">
4
4
 
5
5
  <head>
6
- <title>Code coverage report for hex-to-rgb.ts</title>
6
+ <title>Code coverage report for hexToRgb.ts</title>
7
7
  <meta charset="utf-8" />
8
8
  <link rel="stylesheet" href="prettify.css" />
9
9
  <link rel="stylesheet" href="base.css" />
@@ -19,7 +19,7 @@
19
19
  <body>
20
20
  <div class='wrapper'>
21
21
  <div class='pad1'>
22
- <h1><a href="index.html">All files</a> hex-to-rgb.ts</h1>
22
+ <h1><a href="index.html">All files</a> hexToRgb.ts</h1>
23
23
  <div class='clearfix'>
24
24
 
25
25
  <div class='fl pad1y space-right2'>
@@ -100,7 +100,13 @@
100
100
  <a name='L35'></a><a href='#L35'>35</a>
101
101
  <a name='L36'></a><a href='#L36'>36</a>
102
102
  <a name='L37'></a><a href='#L37'>37</a>
103
- <a name='L38'></a><a href='#L38'>38</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
103
+ <a name='L38'></a><a href='#L38'>38</a>
104
+ <a name='L39'></a><a href='#L39'>39</a>
105
+ <a name='L40'></a><a href='#L40'>40</a>
106
+ <a name='L41'></a><a href='#L41'>41</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
107
+ <span class="cline-any cline-neutral">&nbsp;</span>
108
+ <span class="cline-any cline-neutral">&nbsp;</span>
109
+ <span class="cline-any cline-neutral">&nbsp;</span>
104
110
  <span class="cline-any cline-neutral">&nbsp;</span>
105
111
  <span class="cline-any cline-neutral">&nbsp;</span>
106
112
  <span class="cline-any cline-neutral">&nbsp;</span>
@@ -137,20 +143,23 @@
137
143
  <span class="cline-any cline-neutral">&nbsp;</span>
138
144
  <span class="cline-any cline-neutral">&nbsp;</span>
139
145
  <span class="cline-any cline-neutral">&nbsp;</span>
140
- <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import { RGBA } from "./types";
146
+ <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import type { RGBColor } from "./types";
147
+ &nbsp;
141
148
  /**
142
- * Convert hex color value to rgba object.
143
- * @param {string} hex hex string
144
- * @returns {RGBA}
149
+ * Convert a hexadecimal color code to its corresponding RGBA representation.
150
+ * @param {string} hex - The hexadecimal color code to be converted.
151
+ * @returns {RGBA} - An object containing the RGBA values.
145
152
  * @example
146
153
  * ```
154
+ * import { hexToRgb } from "@library/color";
155
+ *
147
156
  * hexToRgb("#f00"); // { r: 255, g: 0, b: 0, a: 1 }
148
157
  * hexToRgb("#f000"); // { r: 255, g: 0, b: 0, a: 0 }
149
158
  * hexToRgb("#7f11e0"); // { r: 127, g: 17, b: 224, a: 1 }
150
159
  * hexToRgb("#11223344"); // { r: 17, g: 34, b: 51, a: 0.27 }
151
160
  * ```
152
161
  */
153
- export function hexToRgb(hex: string): RGBA {
162
+ export function hexToRgb(hex: string): RGBColor {
154
163
  hex = hex[0] === "#" ? hex.slice(1) : hex;
155
164
  if (hex.length === 3 || hex.length === 4) {
156
165
  hex =
@@ -181,7 +190,7 @@ export function hexToRgb(hex: string): RGBA {
181
190
  <div class='footer quiet pad2 space-top1 center small'>
182
191
  Code coverage generated by
183
192
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
184
- at 2023-06-19T16:43:56.752Z
193
+ at 2025-03-26T13:56:54.131Z
185
194
  </div>
186
195
  <script src="prettify.js"></script>
187
196
  <script>
@@ -25,28 +25,28 @@
25
25
  <div class='fl pad1y space-right2'>
26
26
  <span class="strong">100% </span>
27
27
  <span class="quiet">Statements</span>
28
- <span class='fraction'>9/9</span>
28
+ <span class='fraction'>17/17</span>
29
29
  </div>
30
30
 
31
31
 
32
32
  <div class='fl pad1y space-right2'>
33
33
  <span class="strong">100% </span>
34
34
  <span class="quiet">Branches</span>
35
- <span class='fraction'>11/11</span>
35
+ <span class='fraction'>17/17</span>
36
36
  </div>
37
37
 
38
38
 
39
39
  <div class='fl pad1y space-right2'>
40
40
  <span class="strong">100% </span>
41
41
  <span class="quiet">Functions</span>
42
- <span class='fraction'>1/1</span>
42
+ <span class='fraction'>3/3</span>
43
43
  </div>
44
44
 
45
45
 
46
46
  <div class='fl pad1y space-right2'>
47
47
  <span class="strong">100% </span>
48
48
  <span class="quiet">Lines</span>
49
- <span class='fraction'>9/9</span>
49
+ <span class='fraction'>17/17</span>
50
50
  </div>
51
51
 
52
52
 
@@ -79,7 +79,7 @@
79
79
  </tr>
80
80
  </thead>
81
81
  <tbody><tr>
82
- <td class="file high" data-value="hex-to-rgb.ts"><a href="hex-to-rgb.ts.html">hex-to-rgb.ts</a></td>
82
+ <td class="file high" data-value="hexToRgb.ts"><a href="hexToRgb.ts.html">hexToRgb.ts</a></td>
83
83
  <td data-value="100" class="pic high">
84
84
  <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
85
85
  </td>
@@ -93,6 +93,21 @@
93
93
  <td data-value="9" class="abs high">9/9</td>
94
94
  </tr>
95
95
 
96
+ <tr>
97
+ <td class="file high" data-value="rgbToHex.ts"><a href="rgbToHex.ts.html">rgbToHex.ts</a></td>
98
+ <td data-value="100" class="pic high">
99
+ <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
100
+ </td>
101
+ <td data-value="100" class="pct high">100%</td>
102
+ <td data-value="8" class="abs high">8/8</td>
103
+ <td data-value="100" class="pct high">100%</td>
104
+ <td data-value="6" class="abs high">6/6</td>
105
+ <td data-value="100" class="pct high">100%</td>
106
+ <td data-value="2" class="abs high">2/2</td>
107
+ <td data-value="100" class="pct high">100%</td>
108
+ <td data-value="8" class="abs high">8/8</td>
109
+ </tr>
110
+
96
111
  </tbody>
97
112
  </table>
98
113
  </div>
@@ -101,7 +116,7 @@
101
116
  <div class='footer quiet pad2 space-top1 center small'>
102
117
  Code coverage generated by
103
118
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
104
- at 2023-06-19T16:43:56.752Z
119
+ at 2025-03-26T13:56:54.131Z
105
120
  </div>
106
121
  <script src="prettify.js"></script>
107
122
  <script>
@@ -3,7 +3,7 @@
3
3
  <html lang="en">
4
4
 
5
5
  <head>
6
- <title>Code coverage report for to-hex.ts</title>
6
+ <title>Code coverage report for rgbToHex.ts</title>
7
7
  <meta charset="utf-8" />
8
8
  <link rel="stylesheet" href="prettify.css" />
9
9
  <link rel="stylesheet" href="base.css" />
@@ -19,34 +19,34 @@
19
19
  <body>
20
20
  <div class='wrapper'>
21
21
  <div class='pad1'>
22
- <h1><a href="index.html">All files</a> to-hex.ts</h1>
22
+ <h1><a href="index.html">All files</a> rgbToHex.ts</h1>
23
23
  <div class='clearfix'>
24
24
 
25
25
  <div class='fl pad1y space-right2'>
26
26
  <span class="strong">100% </span>
27
27
  <span class="quiet">Statements</span>
28
- <span class='fraction'>2/2</span>
28
+ <span class='fraction'>8/8</span>
29
29
  </div>
30
30
 
31
31
 
32
32
  <div class='fl pad1y space-right2'>
33
33
  <span class="strong">100% </span>
34
34
  <span class="quiet">Branches</span>
35
- <span class='fraction'>0/0</span>
35
+ <span class='fraction'>6/6</span>
36
36
  </div>
37
37
 
38
38
 
39
39
  <div class='fl pad1y space-right2'>
40
40
  <span class="strong">100% </span>
41
41
  <span class="quiet">Functions</span>
42
- <span class='fraction'>1/1</span>
42
+ <span class='fraction'>2/2</span>
43
43
  </div>
44
44
 
45
45
 
46
46
  <div class='fl pad1y space-right2'>
47
47
  <span class="strong">100% </span>
48
48
  <span class="quiet">Lines</span>
49
- <span class='fraction'>2/2</span>
49
+ <span class='fraction'>8/8</span>
50
50
  </div>
51
51
 
52
52
 
@@ -66,11 +66,44 @@
66
66
  <tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
67
67
  <a name='L2'></a><a href='#L2'>2</a>
68
68
  <a name='L3'></a><a href='#L3'>3</a>
69
- <a name='L4'></a><a href='#L4'>4</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
69
+ <a name='L4'></a><a href='#L4'>4</a>
70
+ <a name='L5'></a><a href='#L5'>5</a>
71
+ <a name='L6'></a><a href='#L6'>6</a>
72
+ <a name='L7'></a><a href='#L7'>7</a>
73
+ <a name='L8'></a><a href='#L8'>8</a>
74
+ <a name='L9'></a><a href='#L9'>9</a>
75
+ <a name='L10'></a><a href='#L10'>10</a>
76
+ <a name='L11'></a><a href='#L11'>11</a>
77
+ <a name='L12'></a><a href='#L12'>12</a>
78
+ <a name='L13'></a><a href='#L13'>13</a>
79
+ <a name='L14'></a><a href='#L14'>14</a>
80
+ <a name='L15'></a><a href='#L15'>15</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
81
+ <span class="cline-any cline-neutral">&nbsp;</span>
70
82
  <span class="cline-any cline-yes">1x</span>
83
+ <span class="cline-any cline-yes">34x</span>
84
+ <span class="cline-any cline-yes">34x</span>
85
+ <span class="cline-any cline-neutral">&nbsp;</span>
86
+ <span class="cline-any cline-neutral">&nbsp;</span>
87
+ <span class="cline-any cline-yes">10x</span>
88
+ <span class="cline-any cline-yes">10x</span>
89
+ <span class="cline-any cline-yes">10x</span>
90
+ <span class="cline-any cline-yes">4x</span>
91
+ <span class="cline-any cline-neutral">&nbsp;</span>
92
+ <span class="cline-any cline-yes">10x</span>
71
93
  <span class="cline-any cline-neutral">&nbsp;</span>
72
- <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">export function toHex() {
73
- return 0;
94
+ <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import { RGBColor } from "./types";
95
+ &nbsp;
96
+ const hex = (num: number) =&gt; {
97
+ const hex = num.toString(16);
98
+ return hex.length === 1 ? `0${hex}` : hex;
99
+ };
100
+ &nbsp;
101
+ export function rgbToHex({ r, g, b, a }: RGBColor): string {
102
+ let ret = `#${hex(r)}${hex(g)}${hex(b)}`;
103
+ if (typeof a === "number" &amp;&amp; a &gt;= 0 &amp;&amp; a &lt;= 1) {
104
+ ret += hex(parseInt((255 * a).toFixed(0)));
105
+ }
106
+ return ret;
74
107
  }
75
108
  &nbsp;</pre></td></tr></table></pre>
76
109
 
@@ -79,7 +112,7 @@
79
112
  <div class='footer quiet pad2 space-top1 center small'>
80
113
  Code coverage generated by
81
114
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
82
- at 2023-06-14T15:25:51.260Z
115
+ at 2025-03-26T13:56:54.131Z
83
116
  </div>
84
117
  <script src="prettify.js"></script>
85
118
  <script>
@@ -1,31 +1,58 @@
1
1
  TN:
2
- SF:src/hex-to-rgb.ts
3
- FN:14,hexToRgb
2
+ SF:src/hexToRgb.ts
3
+ FN:17,hexToRgb
4
4
  FNF:1
5
5
  FNH:1
6
6
  FNDA:12,hexToRgb
7
- DA:14,12
8
- DA:15,12
9
- DA:16,12
10
- DA:17,6
11
- DA:27,12
12
- DA:28,12
13
- DA:29,12
7
+ DA:17,12
8
+ DA:18,12
9
+ DA:19,12
10
+ DA:20,6
14
11
  DA:30,12
15
12
  DA:31,12
13
+ DA:32,12
14
+ DA:33,12
15
+ DA:34,12
16
16
  LF:9
17
17
  LH:9
18
- BRDA:15,0,0,11
19
- BRDA:15,0,1,1
20
- BRDA:16,1,0,6
21
- BRDA:16,2,0,12
22
- BRDA:16,2,1,8
23
- BRDA:24,3,0,6
24
- BRDA:24,3,1,4
25
- BRDA:25,4,0,6
26
- BRDA:25,4,1,4
27
- BRDA:30,5,0,12
28
- BRDA:30,5,1,7
18
+ BRDA:18,0,0,11
19
+ BRDA:18,0,1,1
20
+ BRDA:19,1,0,6
21
+ BRDA:19,2,0,12
22
+ BRDA:19,2,1,8
23
+ BRDA:27,3,0,6
24
+ BRDA:27,3,1,4
25
+ BRDA:28,4,0,6
26
+ BRDA:28,4,1,4
27
+ BRDA:33,5,0,12
28
+ BRDA:33,5,1,7
29
29
  BRF:11
30
30
  BRH:11
31
31
  end_of_record
32
+ TN:
33
+ SF:src/rgbToHex.ts
34
+ FN:3,(anonymous_1)
35
+ FN:8,rgbToHex
36
+ FNF:2
37
+ FNH:2
38
+ FNDA:34,(anonymous_1)
39
+ FNDA:10,rgbToHex
40
+ DA:3,1
41
+ DA:4,34
42
+ DA:5,34
43
+ DA:8,10
44
+ DA:9,10
45
+ DA:10,10
46
+ DA:11,4
47
+ DA:13,10
48
+ LF:8
49
+ LH:8
50
+ BRDA:5,0,0,19
51
+ BRDA:5,0,1,15
52
+ BRDA:10,1,0,4
53
+ BRDA:10,2,0,10
54
+ BRDA:10,2,1,4
55
+ BRDA:10,2,2,4
56
+ BRF:6
57
+ BRH:6
58
+ end_of_record
@@ -1,6 +1,6 @@
1
- import type { RGBA } from "./types";
1
+ import type { RGBColor } from "./types";
2
2
  /**
3
- * Converts a hexadecimal color code to its corresponding RGBA representation.
3
+ * Convert a hexadecimal color code to its corresponding RGBA representation.
4
4
  * @param {string} hex - The hexadecimal color code to be converted.
5
5
  * @returns {RGBA} - An object containing the RGBA values.
6
6
  * @example
@@ -13,5 +13,5 @@ import type { RGBA } from "./types";
13
13
  * hexToRgb("#11223344"); // { r: 17, g: 34, b: 51, a: 0.27 }
14
14
  * ```
15
15
  */
16
- export declare function hexToRgb(hex: string): RGBA;
17
- //# sourceMappingURL=hex-to-rgb.d.ts.map
16
+ export declare function hexToRgb(hex: string): RGBColor;
17
+ //# sourceMappingURL=hexToRgb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hexToRgb.d.ts","sourceRoot":"","sources":["../src/hexToRgb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAuB9C"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Converts a hexadecimal color code to its corresponding RGBA representation.
2
+ * Convert a hexadecimal color code to its corresponding RGBA representation.
3
3
  * @param {string} hex - The hexadecimal color code to be converted.
4
4
  * @returns {RGBA} - An object containing the RGBA values.
5
5
  * @example
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export { hexToRgb } from "./hex-to-rgb.js";
1
+ export { hexToRgb } from "./hexToRgb.js";
2
+ export { rgbToHex } from "./rgbToHex.js";
2
3
  export type * from "./types";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,mBAAmB,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,mBAAmB,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- export { hexToRgb } from "./hex-to-rgb.js";
1
+ export { hexToRgb } from "./hexToRgb.js";
2
+ export { rgbToHex } from "./rgbToHex.js";
@@ -0,0 +1,3 @@
1
+ import { RGBColor } from "./types";
2
+ export declare function rgbToHex({ r, g, b, a }: RGBColor): string;
3
+ //# sourceMappingURL=rgbToHex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rgbToHex.d.ts","sourceRoot":"","sources":["../src/rgbToHex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAOnC,wBAAgB,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAMzD"}
@@ -0,0 +1,11 @@
1
+ const hex = (num) => {
2
+ const hex = num.toString(16);
3
+ return hex.length === 1 ? `0${hex}` : hex;
4
+ };
5
+ export function rgbToHex({ r, g, b, a }) {
6
+ let ret = `#${hex(r)}${hex(g)}${hex(b)}`;
7
+ if (typeof a === "number" && a >= 0 && a <= 1) {
8
+ ret += hex(parseInt((255 * a).toFixed(0)));
9
+ }
10
+ return ret;
11
+ }
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export type RGBA = {
1
+ export type RGBColor = {
2
2
  r: number;
3
3
  g: number;
4
4
  b: number;
5
- a: number;
5
+ a?: number;
6
6
  };
7
7
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ,CAAC"}
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@library/color",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "main": "./dist/index.js",
5
- "type": "module",
6
5
  "exports": "./dist/index.js",
7
6
  "types": "./dist/index.d.ts",
8
7
  "license": "MIT",
9
8
  "scripts": {
10
- "build": "tsc -p tsconfig.build.json",
9
+ "build": "rimraf dist && tsc -p tsconfig.build.json ",
11
10
  "test": "jest --verbose"
12
11
  },
13
12
  "publishConfig": {
14
13
  "access": "public"
15
14
  },
16
- "gitHead": "d7225df96380c60c3ae8638aba07a51af842e8e0"
15
+ "gitHead": "ecc6c3eabd95b3fd7c0d2c5220ce3856195fb6b9"
17
16
  }
@@ -1,4 +1,4 @@
1
- import { hexToRgb } from "./hex-to-rgb";
1
+ import { hexToRgb } from "./hexToRgb";
2
2
 
3
3
  describe("hexToRgb", () => {
4
4
  test.each([
@@ -1,6 +1,7 @@
1
- import type { RGBA } from "./types";
1
+ import type { RGBColor } from "./types";
2
+
2
3
  /**
3
- * Converts a hexadecimal color code to its corresponding RGBA representation.
4
+ * Convert a hexadecimal color code to its corresponding RGBA representation.
4
5
  * @param {string} hex - The hexadecimal color code to be converted.
5
6
  * @returns {RGBA} - An object containing the RGBA values.
6
7
  * @example
@@ -13,7 +14,7 @@ import type { RGBA } from "./types";
13
14
  * hexToRgb("#11223344"); // { r: 17, g: 34, b: 51, a: 0.27 }
14
15
  * ```
15
16
  */
16
- export function hexToRgb(hex: string): RGBA {
17
+ export function hexToRgb(hex: string): RGBColor {
17
18
  hex = hex[0] === "#" ? hex.slice(1) : hex;
18
19
  if (hex.length === 3 || hex.length === 4) {
19
20
  hex =
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
- export { hexToRgb } from "./hex-to-rgb.js";
1
+ export { hexToRgb } from "./hexToRgb.js";
2
+ export { rgbToHex } from "./rgbToHex.js";
2
3
  export type * from "./types";
@@ -0,0 +1,19 @@
1
+ import type { RGBColor } from "../dist";
2
+ import { rgbToHex } from "./rgbToHex";
3
+
4
+ describe("rgbToHex", () => {
5
+ test.each([
6
+ [{ r: 255, g: 0, b: 0 }, "#ff0000"],
7
+ [{ r: 0, g: 255, b: 0 }, "#00ff00"],
8
+ [{ r: 0, g: 0, b: 255 }, "#0000ff"],
9
+ [{ r: 255, g: 255, b: 255 }, "#ffffff"],
10
+ [{ r: 0, g: 0, b: 0 }, "#000000"],
11
+ [{ r: 255, g: 165, b: 0 }, "#ffa500"],
12
+ [{ r: 255, g: 0, b: 0, a: 1 }, "#ff0000ff"],
13
+ [{ r: 255, g: 0, b: 0, a: 0.5 }, "#ff000080"],
14
+ [{ r: 255, g: 0, b: 0, a: 0 }, "#ff000000"],
15
+ [{ r: 255, g: 0, b: 0, a: 0.123 }, "#ff00001f"],
16
+ ])("converts %o to %s", (input: RGBColor, expected: string) => {
17
+ expect(rgbToHex(input)).toBe(expected);
18
+ });
19
+ });
@@ -0,0 +1,14 @@
1
+ import { RGBColor } from "./types";
2
+
3
+ const hex = (num: number) => {
4
+ const hex = num.toString(16);
5
+ return hex.length === 1 ? `0${hex}` : hex;
6
+ };
7
+
8
+ export function rgbToHex({ r, g, b, a }: RGBColor): string {
9
+ let ret = `#${hex(r)}${hex(g)}${hex(b)}`;
10
+ if (typeof a === "number" && a >= 0 && a <= 1) {
11
+ ret += hex(parseInt((255 * a).toFixed(0)));
12
+ }
13
+ return ret;
14
+ }
package/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
- export type RGBA = {
1
+ export type RGBColor = {
2
2
  r: number;
3
3
  g: number;
4
4
  b: number;
5
- a: number;
5
+ a?: number;
6
6
  };
@@ -1 +0,0 @@
1
- {"version":3,"file":"hex-to-rgb.d.ts","sourceRoot":"","sources":["../src/hex-to-rgb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AACpC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAuB1C"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=hex-to-rgb.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hex-to-rgb.test.d.ts","sourceRoot":"","sources":["../src/hex-to-rgb.test.ts"],"names":[],"mappings":""}
@@ -1,19 +0,0 @@
1
- import { hexToRgb } from "./hex-to-rgb";
2
- describe("hexToRgb", () => {
3
- test.each([
4
- ["000", { r: 0, g: 0, b: 0, a: 1 }],
5
- ["#000", { r: 0, g: 0, b: 0, a: 1 }],
6
- ["#0000", { r: 0, g: 0, b: 0, a: 0 }],
7
- ["#000000", { r: 0, g: 0, b: 0, a: 1 }],
8
- ["#00000000", { r: 0, g: 0, b: 0, a: 0 }],
9
- ["#fff", { r: 255, g: 255, b: 255, a: 1 }],
10
- ["#ffff", { r: 255, g: 255, b: 255, a: 1 }],
11
- ["#ffffff", { r: 255, g: 255, b: 255, a: 1 }],
12
- ["#ffffffff", { r: 255, g: 255, b: 255, a: 1 }],
13
- ["#f00", { r: 255, g: 0, b: 0, a: 1 }],
14
- ["#7f11e0", { r: 127, g: 17, b: 224, a: 1 }],
15
- ["#11223344", { r: 17, g: 34, b: 51, a: 0.27 }],
16
- ])('hexToRgba("%s")', (hex, rgba) => {
17
- expect(hexToRgb(hex)).toMatchObject(rgba);
18
- });
19
- });
package/dist/to-hex.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHex = void 0;
4
- function toHex() {
5
- return 0;
6
- }
7
- exports.toHex = toHex;
package/typedoc.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "extends": ["../../typedoc.base.json"],
3
- "entryPoints": ["src/index.ts"]
4
- }