@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.
- package/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-test.log +247 -20
- package/README.md +32 -0
- package/coverage/lcov-report/{hex-to-rgb.ts.html → hexToRgb.ts.html} +18 -9
- package/coverage/lcov-report/index.html +21 -6
- package/coverage/lcov-report/{to-hex.ts.html → rgbToHex.ts.html} +43 -10
- package/coverage/lcov.info +47 -20
- package/dist/{hex-to-rgb.d.ts → hexToRgb.d.ts} +4 -4
- package/dist/hexToRgb.d.ts.map +1 -0
- package/dist/{hex-to-rgb.js → hexToRgb.js} +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/rgbToHex.d.ts +3 -0
- package/dist/rgbToHex.d.ts.map +1 -0
- package/dist/rgbToHex.js +11 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -4
- package/src/{hex-to-rgb.test.ts → hexToRgb.spec.ts} +1 -1
- package/src/{hex-to-rgb.ts → hexToRgb.ts} +4 -3
- package/src/index.ts +2 -1
- package/src/rgbToHex.spec.ts +19 -0
- package/src/rgbToHex.ts +14 -0
- package/src/types.ts +2 -2
- package/dist/hex-to-rgb.d.ts.map +0 -1
- package/dist/hex-to-rgb.test.d.ts +0 -2
- package/dist/hex-to-rgb.test.d.ts.map +0 -1
- package/dist/hex-to-rgb.test.js +0 -19
- package/dist/to-hex.js +0 -7
- package/typedoc.json +0 -4
package/.turbo/turbo-build.log
CHANGED
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,20 +1,247 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
|
|
2
|
+
[1m[2mDetermining test suites to run...[22m[22m[999D[K
|
|
3
|
+
|
|
4
|
+
[1mTest Suites: [22m0 of 2 total
|
|
5
|
+
[1mTests: [22m0 total
|
|
6
|
+
[1mSnapshots: [22m0 total
|
|
7
|
+
[1mTime:[22m 0 s
|
|
8
|
+
|
|
9
|
+
[1mTest Suites: [22m0 of 2 total
|
|
10
|
+
[1mTests: [22m0 total
|
|
11
|
+
[1mSnapshots: [22m0 total
|
|
12
|
+
[1mTime:[22m 0 s
|
|
13
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
14
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
15
|
+
|
|
16
|
+
[1mTest Suites: [22m0 of 2 total
|
|
17
|
+
[1mTests: [22m0 total
|
|
18
|
+
[1mSnapshots: [22m0 total
|
|
19
|
+
[1mTime:[22m 0 s
|
|
20
|
+
|
|
21
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
22
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
23
|
+
|
|
24
|
+
[1mTest Suites: [22m0 of 2 total
|
|
25
|
+
[1mTests: [22m0 total
|
|
26
|
+
[1mSnapshots: [22m0 total
|
|
27
|
+
[1mTime:[22m 0 s
|
|
28
|
+
|
|
29
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
30
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
31
|
+
|
|
32
|
+
[1mTest Suites: [22m0 of 2 total
|
|
33
|
+
[1mTests: [22m0 total
|
|
34
|
+
[1mSnapshots: [22m0 total
|
|
35
|
+
[1mTime:[22m 0 s
|
|
36
|
+
|
|
37
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
38
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
39
|
+
|
|
40
|
+
[1mTest Suites: [22m0 of 2 total
|
|
41
|
+
[1mTests: [22m0 total
|
|
42
|
+
[1mSnapshots: [22m0 total
|
|
43
|
+
[1mTime:[22m 0 s
|
|
44
|
+
|
|
45
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
46
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
47
|
+
|
|
48
|
+
[1mTest Suites: [22m0 of 2 total
|
|
49
|
+
[1mTests: [22m0 total
|
|
50
|
+
[1mSnapshots: [22m0 total
|
|
51
|
+
[1mTime:[22m 0 s
|
|
52
|
+
|
|
53
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
54
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
55
|
+
|
|
56
|
+
[1mTest Suites: [22m0 of 2 total
|
|
57
|
+
[1mTests: [22m0 total
|
|
58
|
+
[1mSnapshots: [22m0 total
|
|
59
|
+
[1mTime:[22m 0 s
|
|
60
|
+
|
|
61
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
62
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
63
|
+
|
|
64
|
+
[1mTest Suites: [22m0 of 2 total
|
|
65
|
+
[1mTests: [22m0 total
|
|
66
|
+
[1mSnapshots: [22m0 total
|
|
67
|
+
[1mTime:[22m 0 s
|
|
68
|
+
|
|
69
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
70
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
71
|
+
|
|
72
|
+
[1mTest Suites: [22m0 of 2 total
|
|
73
|
+
[1mTests: [22m0 total
|
|
74
|
+
[1mSnapshots: [22m0 total
|
|
75
|
+
[1mTime:[22m 0 s
|
|
76
|
+
|
|
77
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
78
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
79
|
+
|
|
80
|
+
[1mTest Suites: [22m0 of 2 total
|
|
81
|
+
[1mTests: [22m0 total
|
|
82
|
+
[1mSnapshots: [22m0 total
|
|
83
|
+
[1mTime:[22m 0 s
|
|
84
|
+
|
|
85
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
86
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
87
|
+
|
|
88
|
+
[1mTest Suites: [22m0 of 2 total
|
|
89
|
+
[1mTests: [22m0 total
|
|
90
|
+
[1mSnapshots: [22m0 total
|
|
91
|
+
[1mTime:[22m 0 s
|
|
92
|
+
|
|
93
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
94
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
95
|
+
|
|
96
|
+
[1mTest Suites: [22m0 of 2 total
|
|
97
|
+
[1mTests: [22m0 total
|
|
98
|
+
[1mSnapshots: [22m0 total
|
|
99
|
+
[1mTime:[22m 0 s
|
|
100
|
+
|
|
101
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
102
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
103
|
+
|
|
104
|
+
[1mTest Suites: [22m0 of 2 total
|
|
105
|
+
[1mTests: [22m0 total
|
|
106
|
+
[1mSnapshots: [22m0 total
|
|
107
|
+
[1mTime:[22m 0 s
|
|
108
|
+
|
|
109
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
110
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
111
|
+
|
|
112
|
+
[1mTest Suites: [22m0 of 2 total
|
|
113
|
+
[1mTests: [22m0 total
|
|
114
|
+
[1mSnapshots: [22m0 total
|
|
115
|
+
[1mTime:[22m 0 s
|
|
116
|
+
|
|
117
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
118
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
119
|
+
|
|
120
|
+
[1mTest Suites: [22m0 of 2 total
|
|
121
|
+
[1mTests: [22m0 total
|
|
122
|
+
[1mSnapshots: [22m0 total
|
|
123
|
+
[1mTime:[22m 0 s
|
|
124
|
+
|
|
125
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
126
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
127
|
+
|
|
128
|
+
[1mTest Suites: [22m0 of 2 total
|
|
129
|
+
[1mTests: [22m0 total
|
|
130
|
+
[1mSnapshots: [22m0 total
|
|
131
|
+
[1mTime:[22m 0 s
|
|
132
|
+
|
|
133
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
134
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
135
|
+
|
|
136
|
+
[1mTest Suites: [22m0 of 2 total
|
|
137
|
+
[1mTests: [22m0 total
|
|
138
|
+
[1mSnapshots: [22m0 total
|
|
139
|
+
[1mTime:[22m 0 s
|
|
140
|
+
|
|
141
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
142
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
143
|
+
|
|
144
|
+
[1mTest Suites: [22m0 of 2 total
|
|
145
|
+
[1mTests: [22m0 total
|
|
146
|
+
[1mSnapshots: [22m0 total
|
|
147
|
+
[1mTime:[22m 0 s
|
|
148
|
+
|
|
149
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
150
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
151
|
+
|
|
152
|
+
[1mTest Suites: [22m0 of 2 total
|
|
153
|
+
[1mTests: [22m0 total
|
|
154
|
+
[1mSnapshots: [22m0 total
|
|
155
|
+
[1mTime:[22m 0 s
|
|
156
|
+
|
|
157
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
158
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
159
|
+
|
|
160
|
+
[1mTest Suites: [22m0 of 2 total
|
|
161
|
+
[1mTests: [22m0 total
|
|
162
|
+
[1mSnapshots: [22m0 total
|
|
163
|
+
[1mTime:[22m 0 s
|
|
164
|
+
|
|
165
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
166
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
167
|
+
|
|
168
|
+
[1mTest Suites: [22m0 of 2 total
|
|
169
|
+
[1mTests: [22m0 total
|
|
170
|
+
[1mSnapshots: [22m0 total
|
|
171
|
+
[1mTime:[22m 0 s
|
|
172
|
+
|
|
173
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
174
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
175
|
+
|
|
176
|
+
[1mTest Suites: [22m0 of 2 total
|
|
177
|
+
[1mTests: [22m0 total
|
|
178
|
+
[1mSnapshots: [22m0 total
|
|
179
|
+
[1mTime:[22m 0 s
|
|
180
|
+
|
|
181
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
182
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
183
|
+
|
|
184
|
+
[1mTest Suites: [22m0 of 2 total
|
|
185
|
+
[1mTests: [22m0 total
|
|
186
|
+
[1mSnapshots: [22m0 total
|
|
187
|
+
[1mTime:[22m 0 s
|
|
188
|
+
|
|
189
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
190
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
191
|
+
|
|
192
|
+
[1mTest Suites: [22m0 of 2 total
|
|
193
|
+
[1mTests: [22m0 total
|
|
194
|
+
[1mSnapshots: [22m0 total
|
|
195
|
+
[1mTime:[22m 0 s
|
|
196
|
+
|
|
197
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
198
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
199
|
+
|
|
200
|
+
[1mTest Suites: [22m0 of 2 total
|
|
201
|
+
[1mTests: [22m0 total
|
|
202
|
+
[1mSnapshots: [22m0 total
|
|
203
|
+
[1mTime:[22m 0 s
|
|
204
|
+
|
|
205
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
206
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
207
|
+
|
|
208
|
+
[1mTest Suites: [22m0 of 2 total
|
|
209
|
+
[1mTests: [22m0 total
|
|
210
|
+
[1mSnapshots: [22m0 total
|
|
211
|
+
[1mTime:[22m 0 s
|
|
212
|
+
|
|
213
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
214
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
215
|
+
|
|
216
|
+
[1mTest Suites: [22m0 of 2 total
|
|
217
|
+
[1mTests: [22m0 total
|
|
218
|
+
[1mSnapshots: [22m0 total
|
|
219
|
+
[1mTime:[22m 0 s
|
|
220
|
+
|
|
221
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
222
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
223
|
+
|
|
224
|
+
[1mTest Suites: [22m0 of 2 total
|
|
225
|
+
[1mTests: [22m0 total
|
|
226
|
+
[1mSnapshots: [22m0 total
|
|
227
|
+
[1mTime:[22m 0 s
|
|
228
|
+
|
|
229
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
230
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
231
|
+
|
|
232
|
+
[1mTest Suites: [22m0 of 2 total
|
|
233
|
+
[1mTests: [22m0 total
|
|
234
|
+
[1mSnapshots: [22m0 total
|
|
235
|
+
[1mTime:[22m 0 s
|
|
236
|
+
|
|
237
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mhexToRgb.spec.ts[22m
|
|
238
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/[22m[1mrgbToHex.spec.ts[22m
|
|
239
|
+
|
|
240
|
+
[1mTest Suites: [22m0 of 2 total
|
|
241
|
+
[1mTests: [22m0 total
|
|
242
|
+
[1mSnapshots: [22m0 total
|
|
243
|
+
[1mTime:[22m 0 s
|
|
244
|
+
[1mTests: [22m[1m[32m22 passed[39m[22m, 22 total
|
|
245
|
+
[1mSnapshots: [22m0 total
|
|
246
|
+
[1mTime:[22m 0.537 s
|
|
247
|
+
[2mRan all test suites[22m[2m.[22m
|
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
|
|
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>
|
|
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
|
|
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"> </span>
|
|
107
|
+
<span class="cline-any cline-neutral"> </span>
|
|
108
|
+
<span class="cline-any cline-neutral"> </span>
|
|
109
|
+
<span class="cline-any cline-neutral"> </span>
|
|
104
110
|
<span class="cline-any cline-neutral"> </span>
|
|
105
111
|
<span class="cline-any cline-neutral"> </span>
|
|
106
112
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -137,20 +143,23 @@
|
|
|
137
143
|
<span class="cline-any cline-neutral"> </span>
|
|
138
144
|
<span class="cline-any cline-neutral"> </span>
|
|
139
145
|
<span class="cline-any cline-neutral"> </span>
|
|
140
|
-
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">import {
|
|
146
|
+
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">import type { RGBColor } from "./types";
|
|
147
|
+
|
|
141
148
|
/**
|
|
142
|
-
* Convert
|
|
143
|
-
* @param {string} hex
|
|
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):
|
|
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
|
|
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'>
|
|
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'>
|
|
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'>
|
|
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'>
|
|
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="
|
|
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
|
|
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
|
|
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>
|
|
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'>
|
|
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'>
|
|
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'>
|
|
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'>
|
|
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
|
|
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"> </span>
|
|
81
|
+
<span class="cline-any cline-neutral"> </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"> </span>
|
|
86
|
+
<span class="cline-any cline-neutral"> </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"> </span>
|
|
92
|
+
<span class="cline-any cline-yes">10x</span>
|
|
71
93
|
<span class="cline-any cline-neutral"> </span>
|
|
72
|
-
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">
|
|
73
|
-
|
|
94
|
+
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">import { RGBColor } from "./types";
|
|
95
|
+
|
|
96
|
+
const hex = (num: number) => {
|
|
97
|
+
const hex = num.toString(16);
|
|
98
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export function rgbToHex({ r, g, b, a }: RGBColor): string {
|
|
102
|
+
let ret = `#${hex(r)}${hex(g)}${hex(b)}`;
|
|
103
|
+
if (typeof a === "number" && a >= 0 && a <= 1) {
|
|
104
|
+
ret += hex(parseInt((255 * a).toFixed(0)));
|
|
105
|
+
}
|
|
106
|
+
return ret;
|
|
74
107
|
}
|
|
75
108
|
</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
|
|
115
|
+
at 2025-03-26T13:56:54.131Z
|
|
83
116
|
</div>
|
|
84
117
|
<script src="prettify.js"></script>
|
|
85
118
|
<script>
|
package/coverage/lcov.info
CHANGED
|
@@ -1,31 +1,58 @@
|
|
|
1
1
|
TN:
|
|
2
|
-
SF:src/
|
|
3
|
-
FN:
|
|
2
|
+
SF:src/hexToRgb.ts
|
|
3
|
+
FN:17,hexToRgb
|
|
4
4
|
FNF:1
|
|
5
5
|
FNH:1
|
|
6
6
|
FNDA:12,hexToRgb
|
|
7
|
-
DA:
|
|
8
|
-
DA:
|
|
9
|
-
DA:
|
|
10
|
-
DA:
|
|
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:
|
|
19
|
-
BRDA:
|
|
20
|
-
BRDA:
|
|
21
|
-
BRDA:
|
|
22
|
-
BRDA:
|
|
23
|
-
BRDA:
|
|
24
|
-
BRDA:
|
|
25
|
-
BRDA:
|
|
26
|
-
BRDA:
|
|
27
|
-
BRDA:
|
|
28
|
-
BRDA:
|
|
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 {
|
|
1
|
+
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
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):
|
|
17
|
-
//# sourceMappingURL=
|
|
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
|
-
*
|
|
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
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
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 "./
|
|
1
|
+
export { hexToRgb } from "./hexToRgb.js";
|
|
2
|
+
export { rgbToHex } from "./rgbToHex.js";
|
|
@@ -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"}
|
package/dist/rgbToHex.js
ADDED
|
@@ -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
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
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.
|
|
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": "
|
|
15
|
+
"gitHead": "ecc6c3eabd95b3fd7c0d2c5220ce3856195fb6b9"
|
|
17
16
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RGBColor } from "./types";
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
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):
|
|
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
|
@@ -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
|
+
});
|
package/src/rgbToHex.ts
ADDED
|
@@ -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
package/dist/hex-to-rgb.d.ts.map
DELETED
|
@@ -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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hex-to-rgb.test.d.ts","sourceRoot":"","sources":["../src/hex-to-rgb.test.ts"],"names":[],"mappings":""}
|
package/dist/hex-to-rgb.test.js
DELETED
|
@@ -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
package/typedoc.json
DELETED