rgbToHex
Convert sRGB (0-255) to a lowercase hex string: #rrggbb, or #rrggbbaa when alpha is below 1. Channels are rounded and clamped to 0-255.
import { rgbToHex } from '@pbroom/color-kit';srgb.ts:134function rgbToHex(rgb: Rgb): string;Parameters
Returns
stringHex string with a leading #
Throws
- When any channel or alpha is not finite
Example
import { rgbToHex } from '@pbroom/color-kit';
rgbToHex({ r: 59, g: 130, b: 246, alpha: 1 }); // → '#3b82f6'
rgbToHex({ r: 59, g: 130, b: 246, alpha: 0.5 }); // → '#3b82f680'
rgbToHex({ r: 300, g: -5, b: 127.6, alpha: 1 }); // → '#ff0080'