1.4.1
Supported color formats
Accept:
(any)
color to check if it is in the right hex format
any
:
true if color is in the right hex format, false otherwise
Accept an object like this {r, g, b} with r, b, g numeric values in [0, 255].
(any)
color to check if it is in the right rgb format
any
:
true if color is in the right rgb format, false otherwise
Accept an object like this {r, g, b, a} with r, g, b numeric values in [0, 255] and a in [0, 1].
(any)
color to check if it is in the right rgba format
any
:
true if color is in the right rgba format, false otherwise
Accept hsl colors with:
(any)
color to check if it is in the right hsl format
any
:
true if color is in the right hsl format, false otherwise
Accept hsla colors with:
(any)
color to check if it is in the right hsla format
any
:
true if color is in the right hsla format, false otherwise
Accept an object like this {c, m, y, k} with c, m, y, k numeric values in [0, 100].
(any)
color to check if it is in the right cmyk format
any
:
true if color is in the right cmyk format, false otherwise
Return true if color is hex, rgb, rgba, cmyk, hls or hsla, false otherwise
(any)
color to check if it is in the right Color format
any
:
true if color is in the right Color format, false otherwise
Functions to convert a color object to a string
Functions about hex color format
Convert a hex to a rgb or rgba color (depends on hex format).
hexToRgbOrRgba
instead
(HEX)
color to convert to rgb or rgba
any
:
rgb or rgba object
Convert a hex to a rgb or rgba color (depends on hex format).
(HEX)
color to convert to rgb or rgba
any
:
rgb or rgba object
Convert a hex to a rgb color, if hex color has opacity, it will be lost.
(HEX)
color to convert to rgb
RGB
:
rgb object
Convert a hex to a cmyk. It ignores opacity because cmyk doens't support it.
hexToCmyk
instead
(HEX)
color to convert to cmyk
CMYK
:
cmyk color object
Convert a hex to a cmyk. It ignores opacity because cmyk doens't support it.
(HEX)
color to convert to cmyk
CMYK
:
cmyk color object
Convert a hex color string to a hsl object. It ignores opacity.
hexToHsl
instead
(HEX)
color to convert to hsl
HSL
:
hsl color object
Convert a hex color string to a hsl object. It ignores opacity.
(HEX)
color to convert to hsl
HSL
:
hsl color object
Convert a hex color string to a hsla object. Hex can have opacity or not, if not you can use the alpha parameter. If hex has opacity and alpha != undefined, then the returned alpha value is the hex related one.
(HEX)
color to convert to hsla
(number
= 1
)
opacity value in range
[0, 1]
HSLA
:
hsla color object
Expand the 3-digit hexadecimal form to the 6-digit form doubling each digit. For example #09C becomes #0099CC and #09CA becomes #0099CCAA. If hex is in the long format, return it.
(HEX)
in the short form
HEX
:
hex in the long form
Convert a generic color to hex string.
(Color)
color to convert to hex
HEX
:
hex string
Functions about rgb color format
Convert an rgb object to hex.
rgbToHex
instead
(RGB)
color object to convert to hex
HEX
:
hex color
Convert an rgb object to hex.
(RGB)
color object to convert to hex
HEX
:
hex color
Convert a rgb object to a cmyk object.
rgbToCmyk
instead
(RGB)
color object to convert to cmyk
CMYK
:
cmyk color
Convert a rgb object to a cmyk object.
(RGB)
color object to convert to cmyk
CMYK
:
cmyk color
Convert a rgb object to hsl object.
rgbToHsl
instead
(RGB)
color to convert to HSL
HSL
:
hsl color object
Convert a rgb object to hsl object.
(RGB)
color to convert to HSL
HSL
:
hsl color object
Convert a generic color to rgb.
colorToRgb
instead
(Color)
color to convert to rgb
RGB
:
rgb color object
Convert a generic color to rgb.
(Color)
color to convert to rgb
RGB
:
rgb color object
Convert a string in these two formats to a rgb object:
rgbStringToObject
instead
(string)
rgb string color to convert to rgb
RGB
:
rgb color object
Convert a string in these two formats to a rgb object:
(string)
rgb string color to convert to rgb
RGB
:
rgb color object
Functions about rgba color format
Convert a rgba color object to a hex color.
(RGBA)
color to convert to hex
HEX
:
hex color
Convert a rgba color object to a rgb color removing the alpha value.
rgbaToRgb
instead
(RGBA)
color to convert to rgb
RGB
:
rgb color object
Convert a rgba color object to a rgb color removing the alpha value.
(RGBA)
color to convert to rgb
RGB
:
rgb color object
Convert a rgba color object to a cmyk color object. It ignores opacity because cmyk doens't support it.
(RGBA)
color to convert to cmyk
CMYK
:
cmyk color object
Convert a rgba color object to a hsl color object removing the alpha value.
(RGBA)
color to convert to hsl
HSL
:
hsl color object
Convert a rgba color object to a hsla color object.
(RGBA)
color to convert to hsla
HSLA
:
hsla color object
Convert a generic color to rgba.
(Color)
color to convert to rgba
RGBA
:
rgba color object
Covert a string in these two formats to a rgba object:
rgbaStringToObject
instead
(string)
rgba string
RGBA
:
rgba object
Covert a string in these two formats to a rgba object:
(string)
rgba string
RGBA
:
rgba object
Functions about hsl color format
Convert a hsl object to hex.
hslToHex
instead
(HSL)
color to convert to hex
HEX
:
hex color
Convert a hsl object to hex.
(HSL)
color to convert to hex
HEX
:
hex color
Convert a hsl object to rgb color object.
hslToRgb
instead
(HSL)
color to convert to rgb color object
RGB
:
rgb color object
Convert a hsl object to rgb color object.
(HSL)
color to convert to rgb color object
RGB
:
rgb color object
Convert a hsl object to cmyk.
hslToCmyk
instead
(HSL)
color to convert to cmyk
CMYK
:
cmyk object
Convert a hsl object to cmyk.
(HSL)
color to convert to cmyk
CMYK
:
cmyk object
Convert a generic color to hsl.
(Color)
color to convert to hsl
HSL
:
hsl color object
Covert a string in these two formats to a hsl object:
hslStringToObject
instead
(string)
(any)
string to convert to hsl object
HSL
:
hsl object
Covert a string in these two formats to a hsl object:
(string)
(any)
string to convert to hsl object
HSL
:
hsl object
Functions about hsla color format
Convert a hsla object to hex long format #RRGGBBAA.
(HSLA)
color to convert to hex
HEX
:
hex color string
Convert a hsla object to and rgb color object.
(HSLA)
color to convert to rgba
RGB
:
rgb color object
Convert a hsla object to and rgba color object.
(HSLA)
color to convert to rgba
RGBA
:
rgba color object
Convert a hsla object to and hsl color object.
(HSLA)
color to convert to hsl
HSL
:
hsl color object
Convert a hsla object to and cmyk color object. It ignores opacity because cmyk doens't support it.
(HSLA)
color to convert to cmyk
CMYK
:
cmyk color object
Convert a generic color to hsla.
(Color)
color to convert to hsla
HSLA
:
hsla color object
Covert a string in these two formats to a hsla object:
(string)
(any)
string to convert to hsla object
HSLA
:
hsla object
Functions about cmyk color format
Convert a cmyk color to a hex.
cmykToHex
instead
(CMYK)
color to convert to hex
HEX
:
hex color
Convert a cmyk color to a hex.
(CMYK)
color to convert to hex
HEX
:
hex color
Convert a cmyk color to a rgb.
cmykToRgb
instead
(CMYK)
color to convert to rgb
RGB
:
rgb object
Convert a cmyk color to a rgb.
(CMYK)
color to convert to rgb
RGB
:
rgb object
Convert a cmyk color to a hsl.
cmykToHsl
instead
(CMYK)
color to convert to hsl
HSL
:
hsl object
Convert a cmyk color to a hsl.
(CMYK)
color to convert to hsl
HSL
:
hsl object
Convert a generic color to cmyk.
(Color)
color to convert to cmyk
CMYK
:
cmyk color object
Covert a string in these two formats to a cmyk object:
cmykStringToObject
instead
(string)
string to convert to cmyk
CMYK
:
cmyk object
Covert a string in these two formats to a cmyk object:
(string)
string to convert to cmyk
CMYK
:
cmyk object
Random color generation
Functions about mixing colors
Mix two or more colors based on their weights. Given [c1, c2, c3, ...] and [w1, w2, w3, ...], it returns: mixedCol = { r: sqrt(r1^2 w1 + r2^2 w2 + r3^2 w3 + ...) g: sqrt(g1^2 w1 + g2^2 w2 + g3^2 w3 + ...) b: sqrt(b1^2 w1 + b2^2 w2 + b3^2 * w3 + ...) }
RGB
:
RGB object
Functions about naming colors
Check if a string is a valid color and if so, transform it to the right Color.
(string)
(any)
to convert to a Color
Color
:
Color
Check if a string is in these two formats:
(string)
rgb string color to check to be a valid rgb string
any
:
true if rgbString is a valid format, false otherwise
Check if a string is in these two formats:
(string)
rgba string color to check to be a valid rgba string
any
:
true if rgbaString is a valid format, false otherwise
Check if a string is in these two formats:
(string)
cmyk string color to check to be a valid cmyk string
any
:
true if cmykString is a valid format, false otherwise
Check if a string is in these two formats:
(string)
hsl string color to check to be a valid hsl string
any
:
true if hslString is a valid format, false otherwise
Check if a string is in these two formats:
(string)
hsl string color to check to be a valid hsla string
any
:
true if hslaString is a valid format, false otherwise