@library/color 0.0.3 → 0.0.4

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.
@@ -1,247 +1,173 @@
1
1
 
2
2
  Determining test suites to run...
3
+
4
+
5
+  RUNS  src/rgbToCssString.spec.ts
6
+
7
+  RUNS  src/rgbToCssString.spec.ts
8
+
9
+  RUNS  src/rgbToCssString.spec.ts
10
+
11
+  RUNS  src/rgbToCssString.spec.ts
12
+
13
+  RUNS  src/rgbToCssString.spec.ts
14
+
3
15
 
4
- Test Suites: 0 of 2 total
5
- Tests: 0 total
6
- Snapshots: 0 total
7
- Time: 0 s
16
+  RUNS  src/rgbToCssString.spec.ts
17
+
8
18
 
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
19
+  RUNS  src/rgbToCssString.spec.ts
20
+
15
21
 
16
- Test Suites: 0 of 2 total
17
- Tests: 0 total
18
- Snapshots: 0 total
19
- Time: 0 s
22
+  RUNS  src/rgbToCssString.spec.ts
23
+
20
24
 
21
-  RUNS  src/hexToRgb.spec.ts
22
-  RUNS  src/rgbToHex.spec.ts
25
+  RUNS  src/rgbToCssString.spec.ts
26
+
23
27
 
24
- Test Suites: 0 of 2 total
25
- Tests: 0 total
26
- Snapshots: 0 total
27
- Time: 0 s
28
+  RUNS  src/rgbToCssString.spec.ts
29
+
28
30
 
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
31
+  RUNS  src/rgbToCssString.spec.ts
32
+
36
33
 
37
-  RUNS  src/hexToRgb.spec.ts
34
+  RUNS  src/rgbToCssString.spec.ts
35
+
38
36
   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
37
+
46
38
   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
39
+
54
40
   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
41
+
62
42
   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
43
+
70
44
   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
45
+
78
46
   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
47
+
86
48
   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
49
+
94
50
   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
51
+
102
52
   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
53
+
110
54
   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
55
+
118
56
   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
57
+
126
58
   RUNS  src/rgbToHex.spec.ts
59
+
127
60
 
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
61
   RUNS  src/rgbToHex.spec.ts
62
+
135
63
 
136
- Test Suites: 0 of 2 total
137
- Tests: 0 total
138
- Snapshots: 0 total
139
- Time: 0 s
64
+  RUNS  src/rgbToHex.spec.ts
65
+
140
66
 
141
-  RUNS  src/hexToRgb.spec.ts
142
67
   RUNS  src/rgbToHex.spec.ts
68
+
143
69
 
144
- Test Suites: 0 of 2 total
145
- Tests: 0 total
146
- Snapshots: 0 total
147
- Time: 0 s
70
+  RUNS  src/rgbToHex.spec.ts
71
+
148
72
 
149
-  RUNS  src/hexToRgb.spec.ts
150
73
   RUNS  src/rgbToHex.spec.ts
74
+
151
75
 
152
- Test Suites: 0 of 2 total
153
- Tests: 0 total
154
- Snapshots: 0 total
155
- Time: 0 s
76
+  RUNS  src/rgbToHex.spec.ts
77
+
156
78
 
157
-  RUNS  src/hexToRgb.spec.ts
158
79
   RUNS  src/rgbToHex.spec.ts
80
+
159
81
 
160
- Test Suites: 0 of 2 total
161
- Tests: 0 total
162
- Snapshots: 0 total
163
- Time: 0 s
82
+  RUNS  src/rgbToHex.spec.ts
83
+
164
84
 
165
-  RUNS  src/hexToRgb.spec.ts
166
85
   RUNS  src/rgbToHex.spec.ts
86
+
167
87
 
168
- Test Suites: 0 of 2 total
169
- Tests: 0 total
170
- Snapshots: 0 total
171
- Time: 0 s
88
+  RUNS  src/rgbToHex.spec.ts
89
+
172
90
 
173
-  RUNS  src/hexToRgb.spec.ts
174
91
   RUNS  src/rgbToHex.spec.ts
92
+
175
93
 
176
- Test Suites: 0 of 2 total
177
- Tests: 0 total
178
- Snapshots: 0 total
179
- Time: 0 s
94
+  RUNS  src/rgbToHex.spec.ts
95
+
180
96
 
181
-  RUNS  src/hexToRgb.spec.ts
182
97
   RUNS  src/rgbToHex.spec.ts
98
+
99
+  RUNS  src/hexToRgb.spec.ts
100
+
101
+  RUNS  src/hexToRgb.spec.ts
102
+
103
+  RUNS  src/hexToRgb.spec.ts
104
+
105
+  RUNS  src/hexToRgb.spec.ts
106
+
107
+  RUNS  src/hexToRgb.spec.ts
108
+
109
+  RUNS  src/hexToRgb.spec.ts
110
+
111
+  RUNS  src/hexToRgb.spec.ts
112
+
113
+  RUNS  src/hexToRgb.spec.ts
114
+
115
+  RUNS  src/hexToRgb.spec.ts
116
+
117
+  RUNS  src/hexToRgb.spec.ts
118
+
119
+  RUNS  src/hexToRgb.spec.ts
120
+
121
+  RUNS  src/hexToRgb.spec.ts
122
+
123
+  RUNS  src/hexToRgb.spec.ts
124
+
183
125
 
184
- Test Suites: 0 of 2 total
185
- Tests: 0 total
186
- Snapshots: 0 total
187
- Time: 0 s
126
+  RUNS  src/hexToRgb.spec.ts
127
+
188
128
 
189
129
   RUNS  src/hexToRgb.spec.ts
190
-  RUNS  src/rgbToHex.spec.ts
130
+
191
131
 
192
- Test Suites: 0 of 2 total
193
- Tests: 0 total
194
- Snapshots: 0 total
195
- Time: 0 s
132
+  RUNS  src/hexToRgb.spec.ts
133
+
196
134
 
197
135
   RUNS  src/hexToRgb.spec.ts
198
-  RUNS  src/rgbToHex.spec.ts
136
+
199
137
 
200
- Test Suites: 0 of 2 total
201
- Tests: 0 total
202
- Snapshots: 0 total
203
- Time: 0 s
138
+  RUNS  src/hexToRgb.spec.ts
139
+
204
140
 
205
141
   RUNS  src/hexToRgb.spec.ts
206
-  RUNS  src/rgbToHex.spec.ts
142
+
207
143
 
208
- Test Suites: 0 of 2 total
209
- Tests: 0 total
210
- Snapshots: 0 total
211
- Time: 0 s
144
+  RUNS  src/hexToRgb.spec.ts
145
+
212
146
 
213
147
   RUNS  src/hexToRgb.spec.ts
214
-  RUNS  src/rgbToHex.spec.ts
148
+
215
149
 
216
- Test Suites: 0 of 2 total
217
- Tests: 0 total
218
- Snapshots: 0 total
219
- Time: 0 s
150
+  RUNS  src/hexToRgb.spec.ts
151
+
220
152
 
221
153
   RUNS  src/hexToRgb.spec.ts
222
-  RUNS  src/rgbToHex.spec.ts
154
+
223
155
 
224
- Test Suites: 0 of 2 total
225
- Tests: 0 total
226
- Snapshots: 0 total
227
- Time: 0 s
156
+  RUNS  src/hexToRgb.spec.ts
157
+
228
158
 
229
159
   RUNS  src/hexToRgb.spec.ts
230
-  RUNS  src/rgbToHex.spec.ts
160
+
231
161
 
232
- Test Suites: 0 of 2 total
233
- Tests: 0 total
234
- Snapshots: 0 total
235
- Time: 0 s
162
+  RUNS  src/hexToRgb.spec.ts
163
+
236
164
 
237
165
   RUNS  src/hexToRgb.spec.ts
238
-  RUNS  src/rgbToHex.spec.ts
166
+
239
167
 
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
168
+  RUNS  src/hexToRgb.spec.ts
169
+
170
+ Tests: 26 passed, 26 total
245
171
  Snapshots: 0 total
246
- Time: 0.537 s
172
+ Time: 0.33 s, estimated 1 s
247
173
  Ran all test suites.
@@ -148,7 +148,7 @@
148
148
  /**
149
149
  * Convert a hexadecimal color code to its corresponding RGBA representation.
150
150
  * @param {string} hex - The hexadecimal color code to be converted.
151
- * @returns {RGBA} - An object containing the RGBA values.
151
+ * @returns {RGBColor} - An object containing the RGBA values.
152
152
  * @example
153
153
  * ```
154
154
  * import { hexToRgb } from "@library/color";
@@ -190,7 +190,7 @@ export function hexToRgb(hex: string): RGBColor {
190
190
  <div class='footer quiet pad2 space-top1 center small'>
191
191
  Code coverage generated by
192
192
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
193
- at 2025-03-26T13:56:54.131Z
193
+ at 2025-03-26T14:08:05.118Z
194
194
  </div>
195
195
  <script src="prettify.js"></script>
196
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'>17/17</span>
28
+ <span class='fraction'>23/23</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'>17/17</span>
35
+ <span class='fraction'>18/18</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'>3/3</span>
42
+ <span class='fraction'>4/4</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'>17/17</span>
49
+ <span class='fraction'>23/23</span>
50
50
  </div>
51
51
 
52
52
 
@@ -93,19 +93,34 @@
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="rgbToCssString.ts"><a href="rgbToCssString.ts.html">rgbToCssString.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="5" class="abs high">5/5</td>
103
+ <td data-value="100" class="pct high">100%</td>
104
+ <td data-value="1" class="abs high">1/1</td>
105
+ <td data-value="100" class="pct high">100%</td>
106
+ <td data-value="1" class="abs high">1/1</td>
107
+ <td data-value="100" class="pct high">100%</td>
108
+ <td data-value="5" class="abs high">5/5</td>
109
+ </tr>
110
+
96
111
  <tr>
97
112
  <td class="file high" data-value="rgbToHex.ts"><a href="rgbToHex.ts.html">rgbToHex.ts</a></td>
98
113
  <td data-value="100" class="pic high">
99
114
  <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
100
115
  </td>
101
116
  <td data-value="100" class="pct high">100%</td>
102
- <td data-value="8" class="abs high">8/8</td>
117
+ <td data-value="9" class="abs high">9/9</td>
103
118
  <td data-value="100" class="pct high">100%</td>
104
119
  <td data-value="6" class="abs high">6/6</td>
105
120
  <td data-value="100" class="pct high">100%</td>
106
121
  <td data-value="2" class="abs high">2/2</td>
107
122
  <td data-value="100" class="pct high">100%</td>
108
- <td data-value="8" class="abs high">8/8</td>
123
+ <td data-value="9" class="abs high">9/9</td>
109
124
  </tr>
110
125
 
111
126
  </tbody>
@@ -116,7 +131,7 @@
116
131
  <div class='footer quiet pad2 space-top1 center small'>
117
132
  Code coverage generated by
118
133
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
119
- at 2025-03-26T13:56:54.131Z
134
+ at 2025-03-26T14:08:05.118Z
120
135
  </div>
121
136
  <script src="prettify.js"></script>
122
137
  <script>
@@ -0,0 +1,112 @@
1
+
2
+ <!doctype html>
3
+ <html lang="en">
4
+
5
+ <head>
6
+ <title>Code coverage report for rgbToCssString.ts</title>
7
+ <meta charset="utf-8" />
8
+ <link rel="stylesheet" href="prettify.css" />
9
+ <link rel="stylesheet" href="base.css" />
10
+ <link rel="shortcut icon" type="image/x-icon" href="favicon.png" />
11
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
12
+ <style type='text/css'>
13
+ .coverage-summary .sorter {
14
+ background-image: url(sort-arrow-sprite.png);
15
+ }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <div class='wrapper'>
21
+ <div class='pad1'>
22
+ <h1><a href="index.html">All files</a> rgbToCssString.ts</h1>
23
+ <div class='clearfix'>
24
+
25
+ <div class='fl pad1y space-right2'>
26
+ <span class="strong">100% </span>
27
+ <span class="quiet">Statements</span>
28
+ <span class='fraction'>5/5</span>
29
+ </div>
30
+
31
+
32
+ <div class='fl pad1y space-right2'>
33
+ <span class="strong">100% </span>
34
+ <span class="quiet">Branches</span>
35
+ <span class='fraction'>1/1</span>
36
+ </div>
37
+
38
+
39
+ <div class='fl pad1y space-right2'>
40
+ <span class="strong">100% </span>
41
+ <span class="quiet">Functions</span>
42
+ <span class='fraction'>1/1</span>
43
+ </div>
44
+
45
+
46
+ <div class='fl pad1y space-right2'>
47
+ <span class="strong">100% </span>
48
+ <span class="quiet">Lines</span>
49
+ <span class='fraction'>5/5</span>
50
+ </div>
51
+
52
+
53
+ </div>
54
+ <p class="quiet">
55
+ Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
56
+ </p>
57
+ <template id="filterTemplate">
58
+ <div class="quiet">
59
+ Filter:
60
+ <input oninput="onInput()" type="search" id="fileSearch">
61
+ </div>
62
+ </template>
63
+ </div>
64
+ <div class='status-line high'></div>
65
+ <pre><table class="coverage">
66
+ <tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
67
+ <a name='L2'></a><a href='#L2'>2</a>
68
+ <a name='L3'></a><a href='#L3'>3</a>
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></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
76
+ <span class="cline-any cline-neutral">&nbsp;</span>
77
+ <span class="cline-any cline-yes">4x</span>
78
+ <span class="cline-any cline-yes">4x</span>
79
+ <span class="cline-any cline-yes">4x</span>
80
+ <span class="cline-any cline-yes">1x</span>
81
+ <span class="cline-any cline-neutral">&nbsp;</span>
82
+ <span class="cline-any cline-yes">3x</span>
83
+ <span class="cline-any cline-neutral">&nbsp;</span>
84
+ <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import type { RGBColor } from "./types";
85
+ &nbsp;
86
+ export function rgbToCssString(rgb: RGBColor) {
87
+ const { r, g, b, a } = rgb;
88
+ if (typeof a !== "number") {
89
+ return `rgb(${r}, ${g}, ${b})`;
90
+ }
91
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
92
+ }
93
+ &nbsp;</pre></td></tr></table></pre>
94
+
95
+ <div class='push'></div><!-- for sticky footer -->
96
+ </div><!-- /wrapper -->
97
+ <div class='footer quiet pad2 space-top1 center small'>
98
+ Code coverage generated by
99
+ <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
100
+ at 2025-03-26T14:08:05.118Z
101
+ </div>
102
+ <script src="prettify.js"></script>
103
+ <script>
104
+ window.onload = function () {
105
+ prettyPrint();
106
+ };
107
+ </script>
108
+ <script src="sorter.js"></script>
109
+ <script src="block-navigation.js"></script>
110
+ </body>
111
+ </html>
112
+
@@ -25,7 +25,7 @@
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'>8/8</span>
28
+ <span class='fraction'>9/9</span>
29
29
  </div>
30
30
 
31
31
 
@@ -46,7 +46,7 @@
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'>8/8</span>
49
+ <span class='fraction'>9/9</span>
50
50
  </div>
51
51
 
52
52
 
@@ -77,13 +77,35 @@
77
77
  <a name='L12'></a><a href='#L12'>12</a>
78
78
  <a name='L13'></a><a href='#L13'>13</a>
79
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>
80
+ <a name='L15'></a><a href='#L15'>15</a>
81
+ <a name='L16'></a><a href='#L16'>16</a>
82
+ <a name='L17'></a><a href='#L17'>17</a>
83
+ <a name='L18'></a><a href='#L18'>18</a>
84
+ <a name='L19'></a><a href='#L19'>19</a>
85
+ <a name='L20'></a><a href='#L20'>20</a>
86
+ <a name='L21'></a><a href='#L21'>21</a>
87
+ <a name='L22'></a><a href='#L22'>22</a>
88
+ <a name='L23'></a><a href='#L23'>23</a>
89
+ <a name='L24'></a><a href='#L24'>24</a>
90
+ <a name='L25'></a><a href='#L25'>25</a>
91
+ <a name='L26'></a><a href='#L26'>26</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
81
92
  <span class="cline-any cline-neutral">&nbsp;</span>
82
93
  <span class="cline-any cline-yes">1x</span>
83
94
  <span class="cline-any cline-yes">34x</span>
84
95
  <span class="cline-any cline-yes">34x</span>
85
96
  <span class="cline-any cline-neutral">&nbsp;</span>
86
97
  <span class="cline-any cline-neutral">&nbsp;</span>
98
+ <span class="cline-any cline-neutral">&nbsp;</span>
99
+ <span class="cline-any cline-neutral">&nbsp;</span>
100
+ <span class="cline-any cline-neutral">&nbsp;</span>
101
+ <span class="cline-any cline-neutral">&nbsp;</span>
102
+ <span class="cline-any cline-neutral">&nbsp;</span>
103
+ <span class="cline-any cline-neutral">&nbsp;</span>
104
+ <span class="cline-any cline-neutral">&nbsp;</span>
105
+ <span class="cline-any cline-neutral">&nbsp;</span>
106
+ <span class="cline-any cline-neutral">&nbsp;</span>
107
+ <span class="cline-any cline-neutral">&nbsp;</span>
108
+ <span class="cline-any cline-yes">10x</span>
87
109
  <span class="cline-any cline-yes">10x</span>
88
110
  <span class="cline-any cline-yes">10x</span>
89
111
  <span class="cline-any cline-yes">10x</span>
@@ -98,7 +120,18 @@ const hex = (num: number) =&gt; {
98
120
  return hex.length === 1 ? `0${hex}` : hex;
99
121
  };
100
122
  &nbsp;
101
- export function rgbToHex({ r, g, b, a }: RGBColor): string {
123
+ /**
124
+ * @param {RGBColor} rgb An object containing the RGBA values.
125
+ * @returns {string} The hexadecimal color code
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * rgbToHex({ r: 255, g: 99, b: 71 }); // "#ff6347"
130
+ * rgbToHex({ r: 255, g: 99, b: 71, a: 0.5 }); // "#ff634780"
131
+ * ```
132
+ */
133
+ export function rgbToHex(rgb: RGBColor): string {
134
+ const { r, g, b, a } = rgb;
102
135
  let ret = `#${hex(r)}${hex(g)}${hex(b)}`;
103
136
  if (typeof a === "number" &amp;&amp; a &gt;= 0 &amp;&amp; a &lt;= 1) {
104
137
  ret += hex(parseInt((255 * a).toFixed(0)));
@@ -112,7 +145,7 @@ export function rgbToHex({ r, g, b, a }: RGBColor): string {
112
145
  <div class='footer quiet pad2 space-top1 center small'>
113
146
  Code coverage generated by
114
147
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
115
- at 2025-03-26T13:56:54.131Z
148
+ at 2025-03-26T14:08:05.118Z
116
149
  </div>
117
150
  <script src="prettify.js"></script>
118
151
  <script>
@@ -30,9 +30,26 @@ BRF:11
30
30
  BRH:11
31
31
  end_of_record
32
32
  TN:
33
+ SF:src/rgbToCssString.ts
34
+ FN:3,rgbToCssString
35
+ FNF:1
36
+ FNH:1
37
+ FNDA:4,rgbToCssString
38
+ DA:3,4
39
+ DA:4,4
40
+ DA:5,4
41
+ DA:6,1
42
+ DA:8,3
43
+ LF:5
44
+ LH:5
45
+ BRDA:5,0,0,1
46
+ BRF:1
47
+ BRH:1
48
+ end_of_record
49
+ TN:
33
50
  SF:src/rgbToHex.ts
34
51
  FN:3,(anonymous_1)
35
- FN:8,rgbToHex
52
+ FN:18,rgbToHex
36
53
  FNF:2
37
54
  FNH:2
38
55
  FNDA:34,(anonymous_1)
@@ -40,19 +57,20 @@ FNDA:10,rgbToHex
40
57
  DA:3,1
41
58
  DA:4,34
42
59
  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
60
+ DA:18,10
61
+ DA:19,10
62
+ DA:20,10
63
+ DA:21,10
64
+ DA:22,4
65
+ DA:24,10
66
+ LF:9
67
+ LH:9
50
68
  BRDA:5,0,0,19
51
69
  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
70
+ BRDA:21,1,0,4
71
+ BRDA:21,2,0,10
72
+ BRDA:21,2,1,4
73
+ BRDA:21,2,2,4
56
74
  BRF:6
57
75
  BRH:6
58
76
  end_of_record
@@ -2,7 +2,7 @@ import type { RGBColor } from "./types";
2
2
  /**
3
3
  * Convert a hexadecimal color code to its corresponding RGBA representation.
4
4
  * @param {string} hex - The hexadecimal color code to be converted.
5
- * @returns {RGBA} - An object containing the RGBA values.
5
+ * @returns {RGBColor} - An object containing the RGBA values.
6
6
  * @example
7
7
  * ```
8
8
  * import { hexToRgb } from "@library/color";
package/dist/hexToRgb.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Convert a hexadecimal color code to its corresponding RGBA representation.
3
3
  * @param {string} hex - The hexadecimal color code to be converted.
4
- * @returns {RGBA} - An object containing the RGBA values.
4
+ * @returns {RGBColor} - An object containing the RGBA values.
5
5
  * @example
6
6
  * ```
7
7
  * import { hexToRgb } from "@library/color";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { hexToRgb } from "./hexToRgb.js";
2
2
  export { rgbToHex } from "./rgbToHex.js";
3
+ export { rgbToCssString } from "./rgbToCssString.js";
3
4
  export type * from "./types";
4
5
  //# 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,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,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,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,mBAAmB,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { hexToRgb } from "./hexToRgb.js";
2
2
  export { rgbToHex } from "./rgbToHex.js";
3
+ export { rgbToCssString } from "./rgbToCssString.js";
@@ -0,0 +1,12 @@
1
+ import type { RGBColor } from "./types";
2
+ /**
3
+ * Converts an RGB or RGBA color object into a CSS color string.
4
+ *
5
+ * If the alpha (`a`) value is provided, it returns a `rgba(r, g, b, a)` string.
6
+ * Otherwise, it returns a `rgb(r, g, b)` string.
7
+ *
8
+ * @param {RGBColor} rgb An object containing the RGBA values.
9
+ * @returns {string} A CSS color string.
10
+ */
11
+ export declare function rgbToCssString(rgb: RGBColor): string;
12
+ //# sourceMappingURL=rgbToCssString.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rgbToCssString.d.ts","sourceRoot":"","sources":["../src/rgbToCssString.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAMpD"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Converts an RGB or RGBA color object into a CSS color string.
3
+ *
4
+ * If the alpha (`a`) value is provided, it returns a `rgba(r, g, b, a)` string.
5
+ * Otherwise, it returns a `rgb(r, g, b)` string.
6
+ *
7
+ * @param {RGBColor} rgb An object containing the RGBA values.
8
+ * @returns {string} A CSS color string.
9
+ */
10
+ export function rgbToCssString(rgb) {
11
+ const { r, g, b, a } = rgb;
12
+ if (typeof a !== "number") {
13
+ return `rgb(${r}, ${g}, ${b})`;
14
+ }
15
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
16
+ }
@@ -1,3 +1,13 @@
1
1
  import { RGBColor } from "./types";
2
- export declare function rgbToHex({ r, g, b, a }: RGBColor): string;
2
+ /**
3
+ * @param {RGBColor} rgb An object containing the RGBA values.
4
+ * @returns {string} The hexadecimal color code
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * rgbToHex({ r: 255, g: 99, b: 71 }); // "#ff6347"
9
+ * rgbToHex({ r: 255, g: 99, b: 71, a: 0.5 }); // "#ff634780"
10
+ * ```
11
+ */
12
+ export declare function rgbToHex(rgb: RGBColor): string;
3
13
  //# sourceMappingURL=rgbToHex.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"rgbToHex.d.ts","sourceRoot":"","sources":["../src/rgbToHex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAOnC;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAO9C"}
package/dist/rgbToHex.js CHANGED
@@ -2,7 +2,18 @@ const hex = (num) => {
2
2
  const hex = num.toString(16);
3
3
  return hex.length === 1 ? `0${hex}` : hex;
4
4
  };
5
- export function rgbToHex({ r, g, b, a }) {
5
+ /**
6
+ * @param {RGBColor} rgb An object containing the RGBA values.
7
+ * @returns {string} The hexadecimal color code
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * rgbToHex({ r: 255, g: 99, b: 71 }); // "#ff6347"
12
+ * rgbToHex({ r: 255, g: 99, b: 71, a: 0.5 }); // "#ff634780"
13
+ * ```
14
+ */
15
+ export function rgbToHex(rgb) {
16
+ const { r, g, b, a } = rgb;
6
17
  let ret = `#${hex(r)}${hex(g)}${hex(b)}`;
7
18
  if (typeof a === "number" && a >= 0 && a <= 1) {
8
19
  ret += hex(parseInt((255 * a).toFixed(0)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@library/color",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "main": "./dist/index.js",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -12,5 +12,5 @@
12
12
  "publishConfig": {
13
13
  "access": "public"
14
14
  },
15
- "gitHead": "ecc6c3eabd95b3fd7c0d2c5220ce3856195fb6b9"
15
+ "gitHead": "95b2a37ecb3e4b963a573a66961aa08e35722232"
16
16
  }
package/src/hexToRgb.ts CHANGED
@@ -3,7 +3,7 @@ import type { RGBColor } from "./types";
3
3
  /**
4
4
  * Convert a hexadecimal color code to its corresponding RGBA representation.
5
5
  * @param {string} hex - The hexadecimal color code to be converted.
6
- * @returns {RGBA} - An object containing the RGBA values.
6
+ * @returns {RGBColor} - An object containing the RGBA values.
7
7
  * @example
8
8
  * ```
9
9
  * import { hexToRgb } from "@library/color";
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { hexToRgb } from "./hexToRgb.js";
2
2
  export { rgbToHex } from "./rgbToHex.js";
3
+ export { rgbToCssString } from "./rgbToCssString.js";
3
4
  export type * from "./types";
@@ -0,0 +1,25 @@
1
+ import { rgbToCssString } from "./rgbToCssString";
2
+ import type { RGBColor } from "./types";
3
+
4
+ describe("rgbToCssString", () => {
5
+ test.each<[desc: string, input: RGBColor, expected: string]>([
6
+ ["rgb string without alpha", { r: 255, g: 0, b: 128 }, "rgb(255, 0, 128)"],
7
+ [
8
+ "rgba string with alpha 0.5",
9
+ { r: 255, g: 0, b: 128, a: 0.5 },
10
+ "rgba(255, 0, 128, 0.5)",
11
+ ],
12
+ [
13
+ "rgba string with alpha 0",
14
+ { r: 0, g: 0, b: 0, a: 0 },
15
+ "rgba(0, 0, 0, 0)",
16
+ ],
17
+ [
18
+ "rgba string with alpha 1",
19
+ { r: 255, g: 255, b: 255, a: 1 },
20
+ "rgba(255, 255, 255, 1)",
21
+ ],
22
+ ])("%s", (_, input, expected) => {
23
+ expect(rgbToCssString(input)).toBe(expected);
24
+ });
25
+ });
@@ -0,0 +1,18 @@
1
+ import type { RGBColor } from "./types";
2
+
3
+ /**
4
+ * Converts an RGB or RGBA color object into a CSS color string.
5
+ *
6
+ * If the alpha (`a`) value is provided, it returns a `rgba(r, g, b, a)` string.
7
+ * Otherwise, it returns a `rgb(r, g, b)` string.
8
+ *
9
+ * @param {RGBColor} rgb An object containing the RGBA values.
10
+ * @returns {string} A CSS color string.
11
+ */
12
+ export function rgbToCssString(rgb: RGBColor): string {
13
+ const { r, g, b, a } = rgb;
14
+ if (typeof a !== "number") {
15
+ return `rgb(${r}, ${g}, ${b})`;
16
+ }
17
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
18
+ }
package/src/rgbToHex.ts CHANGED
@@ -5,7 +5,18 @@ const hex = (num: number) => {
5
5
  return hex.length === 1 ? `0${hex}` : hex;
6
6
  };
7
7
 
8
- export function rgbToHex({ r, g, b, a }: RGBColor): string {
8
+ /**
9
+ * @param {RGBColor} rgb An object containing the RGBA values.
10
+ * @returns {string} The hexadecimal color code
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * rgbToHex({ r: 255, g: 99, b: 71 }); // "#ff6347"
15
+ * rgbToHex({ r: 255, g: 99, b: 71, a: 0.5 }); // "#ff634780"
16
+ * ```
17
+ */
18
+ export function rgbToHex(rgb: RGBColor): string {
19
+ const { r, g, b, a } = rgb;
9
20
  let ret = `#${hex(r)}${hex(g)}${hex(b)}`;
10
21
  if (typeof a === "number" && a >= 0 && a <= 1) {
11
22
  ret += hex(parseInt((255 * a).toFixed(0)));