({ r, g, b, a })
| 187 | } |
| 188 | |
| 189 | function rgbToHex({ r, g, b, a }) { |
| 190 | if (a !== 1) { |
| 191 | return `rgba(${[r, g, b] |
| 192 | .map((n) => Math.round(n * 255)) |
| 193 | .join(", ")}, ${a.toFixed(4)})`; |
| 194 | } |
| 195 | const toHex = (value) => { |
| 196 | const hex = Math.round(value * 255).toString(16); |
| 197 | return hex.length === 1 ? "0" + hex : hex; |
| 198 | }; |
| 199 | |
| 200 | const hex = [toHex(r), toHex(g), toHex(b)].join(""); |
| 201 | return `#${hex}`; |
| 202 | } |
| 203 | |
| 204 | function parseColor(color) { |
| 205 | color = color.trim(); |
no test coverage detected