parseHex
Parses a hex color string into an RGB color object.Parameters
The hex color string to parse. Supports 6-character hex codes (e.g.,
#FF00FF) and 8-character hex codes with alpha (e.g., #FF00FFFF). The leading # is optional.Returns
Returns a
Color object with red, green, blue, and optional alpha properties if the input is valid, or undefined if the hex string is invalid.Example
toHex
Converts an RGB color object to a hex color string.Parameters
The RGB color object to convert. Must have
red, green, and blue properties (0-255), and an optional alpha property (0-1).Returns
A hex color string without the leading
#. If the color has an alpha value, it will be included as the last two characters.Example
toHexHash
Converts an RGB color object to a hex CSS value with a leading#.
Parameters
The RGB color object to convert. Must have
red, green, and blue properties (0-255), and an optional alpha property (0-1).Returns
A hex CSS value string with a leading
#. If the color has an alpha value, it will be included in the output.