Function Signature
js
hexAToRgba(hexA: string): { r: number, g: number, b: number, a: number }Parameters
hexA(string): A HEX alpha color in#rgbaor#rrggbbaaformat.
Return Value
An object containing RGB channel values and alpha rounded to two decimals.
js
hexAToRgba("#00aaffcc");
// { r: 0, g: 170, b: 255, a: 0.8 }
hexAToRgba("#0afc");
// { r: 0, g: 170, b: 255, a: 0.8 }Examples
js
console.log(hexAToRgba("#ff6600ff"));
// { r: 255, g: 102, b: 0, a: 1 }
console.log(hexAToRgba("#0000"));
// { r: 0, g: 0, b: 0, a: 0 }Error Handling
Throws Invalid hexA color if the input is not valid 4-digit or 8-digit HEX alpha.
Usage Notes
- Use
rgbaToHexAfor the reverse conversion. - The alpha channel is decoded from the final HEX byte.
- For non-alpha HEX colors, use
hexToRgb.