hexAlphaToHsla
Legacy documentation for Colore JS 1.4.4.View v2 docs
The hexAlphaToHsla function is used to convert a HEX color with alpha to HSLA. This function supports both shorthand (#RGBA) and standard (#RRGGBBAA) HEX formats.
Syntax
hexAlphaToHsla(hex: string, asString?: true): string;
hexAlphaToHsla(hex: string, asString?: false): { h: number; s: number; l: number; a: number };
hexAlphaToHsla(hex: string, asString: boolean = true): string | { h: number; s: number; l: number; a: number };
Parameters
hex(string): The HEX color string with alpha (e.g.,#RRGGBBAAor#RGBA).asString(boolean, optional): Whether to return the result as a string. Defaults totrue.
Returns
- string | object: The HSLA color components.
- If
asStringistrue: The HSLA color as a string. - If
asStringisfalse: An object containing the HSLA color components.h(number): The hue component.s(number): The saturation component.l(number): The lightness component.a(number): The alpha component.
- If
Example
import { hexAlphaToHsla } from 'colore-js';
const hslaColor = hexAlphaToHsla('#ff5733cc');
console.log(hslaColor);
// Output: "hsla(14, 100%, 60%, 0.8)"
const hslaObject = hexAlphaToHsla('#ff5733cc', false);
console.log(hslaObject);
// Output: { h: 14, s: 100, l: 60, a: 0.8 }
Usage
The hexAlphaToHsla function is commonly used in web development to convert HEX colors with alpha transparency to HSLA format, which can be useful for CSS styling and other applications that require color manipulation.