getRgbaFromHex()
function getRgbaFromHex(options): GetRgbaFromHexOutput
Converts a hexadecimal color code to RGBA format.
Parameters
Parameter | Type | Description |
---|---|---|
options | GetRgbaFromHexOptions | The options for converting hex to RGBA. |
Returns
An object containing the RGBA color string and individual RGBA values.
Throws
If the provided hexCode is invalid.
Example
getRgbaFromHex({ hexCode: '#FF0000' });
// Returns { rgba: 'rgba(255, 0, 0, 1)', r: 255, g: 0, b: 0, a: 1 }
getRgbaFromHex({ hexCode: '#00FF00', alpha: 0.5 });
// Returns { rgba: 'rgba(0, 255, 0, 0.5)', r: 0, g: 255, b: 0, a: 0.5 }
getRgbaFromHex({ hexCode: 'invalid' });
// Throws an error: Invalid color