Add library to tsconfig.json
{
"compilerOptions": {
"types": ["color-types"]
}
}
Format | Support |
---|---|
Color name | ✅ |
Hex | ✅ |
RGB | ✅ |
RGBA | ✅ |
HSL | ✅ |
HSLA | ✅ |
HWB | ✅ |
const color: ColorName = 'red';
const color: HEX = '#ff0000';
const color: RGB = 'rgb(255, 0, 0)';
const color: RGBA = 'rgb(255 0 0 / 100%)' | 'rgba(255, 0, 0, 1)';
const color: HSL = 'hsl(0deg 100% 50%)';
const color: HSLA = 'hsla(0rad, 100%, 50%, 1)';
const color: HWB = 'hwb(0turn 0% 0%)';
const color: RGBObject = { r: 255, g: 0, b: 0 } || { red: 255, green: 0, blue: 0 };
const color: RGBAObject = { r: 255, g: 0, b: 0, a: 1 } || { red: 255, green: 0, blue: 0, alpha: 1 };
const color: HSLObject = { h: 0, s: 100, l: 50 } || { hue: 0, saturation: 100, lightness: 50 };
const color: HSLAObject = { h: 0, s: 100, l: 50, a: 1 } || { hue: 0, saturation: 100, lightness: 50, alpha: 1 };
const color: HWBObject = { h: 0, w: 0, b: 0 } || { hue: 0, whiteness: 0, blackness: 0 } || { hue: 0, whiteness: 0, blackness: 0, aplha: 1 };
// All of type color
const color: Color = 'red' || '#ff0000' || 'rgb(255, 0, 0)';