Skip to main content

decomposeColor

The decomposeColor function decomposes a color string into its components. This function detects the format of the input color string, parses it using the appropriate parser, and returns the corresponding color components as an object.

Syntax

decomposeColor(color: string): any

Parameters

  • color (string): The input color string in any supported format (hex, rgb, hsl, etc.).

Returns

  • object: The decomposed color components as an object.

Throws

  • Error: Throws an error if the input color format is unsupported or invalid.

Example

import { decomposeColor } from 'colore-js';

const decomposedHex = decomposeColor('#ff0000');
console.log(decomposedHex);
// Output: { r: 255, g: 0, b: 0 }

const decomposedRgb = decomposeColor('rgb(255, 0, 0)');
console.log(decomposedRgb);
// Output: { r: 255, g: 0, b: 0 }

Usage

The decomposeColor function is used to break down a color string into its individual components. This can be useful for color manipulation and analysis in various design and art applications.