(color: RGB, alpha: number)
| 12 | }; |
| 13 | |
| 14 | export const rgbTo8hex = (color: RGB, alpha: number): string => { |
| 15 | // when color is RGBA, alpha is set automatically |
| 16 | // when color is RGB, alpha need to be set manually (default: 1.0) |
| 17 | const hex = |
| 18 | ((alpha * 255) | (1 << 8)).toString(16).slice(1) + |
| 19 | ((color.r * 255) | (1 << 8)).toString(16).slice(1) + |
| 20 | ((color.g * 255) | (1 << 8)).toString(16).slice(1) + |
| 21 | ((color.b * 255) | (1 << 8)).toString(16).slice(1); |
| 22 | |
| 23 | return hex; |
| 24 | }; |
| 25 | |
| 26 | /** |
| 27 | * Converts RGB values to CSS hex or rgba format |
no test coverage detected