Toolbox-XToolbox-X

Convert Color Code

Converts between solid or alpha-channel color formats, returning all other equivalent formats.

convertColorCode

The convertColorCode function converts between color formats (HEX, RGB, HSL) and their alpha-channel variants (HEX8, RGBA, HSLA). It parses the input format and returns an object containing all other equivalent color representations.

Function Signatures

function convertColorCode(color: Hex6): { rgb: RGB; hsl: HSL }
function convertColorCode(color: RGB): { hex: Hex6; hsl: HSL }
function convertColorCode(color: HSL): { hex: Hex6; rgb: RGB }

function convertColorCode(color: Hex8): { rgba: RGBA; hsla: HSLA }
function convertColorCode(color: RGBA): { hex8: Hex8; hsla: HSLA }
function convertColorCode(color: HSLA): { hex8: Hex8; rgba: RGBA }

Parameters

  • color (ColorType): The solid or alpha-channel color string to convert.

Return Value

  • An object with keys for all equivalent formats excluding the input format (e.g. converting a Hex6 returns { rgb, hsl }).

Example Usage

playground.ts

Notes

  • String inputs that represent branded types (like Hex6 and Hex8) might require type casting (e.g. as Hex6).
  • Throws an error if the color string is malformed or invalid.

See Also

  • Color converters - Direct conversion functions between specific formats.
  • Color class - Object-oriented class wrapper for advanced color management.

Last updated: Sun, Jun 14, 2026 07:15:25PM (UTC)

On this page