Color formats

Supported color formats

Color formats
Static Members
isHex(color)
isRgb(color)
isRgba(color)
isHsl(color)
isHsla(color)
isCmyk(color)
isColor(color)

Color to string

Functions to convert a color object to a string

Color to string
Static Members
color2string(color)
colorToString(color)
color2cssString(color)
colorToCssString(color)

Hex

Functions about hex color format

Hex
Static Members
hex2rgbOrRgba(hex)
hexToRgbOrRgba(hex)
hexToRgb(hex)
hex2rgba(hex, alpha)
hexToRgba(hex, alpha)
hex2hexWithAlpha(hex, alpha)
hexToHexWithAlpha(hex, alpha)
hex2cmyk(hex)
hexToCmyk(hex)
hex2hsl(hex)
hexToHsl(hex)
hexToHsla(hex, alpha)
shortToLongHex(hex)
colorToHex(color)

Rgb

Functions about rgb color format

Rgb
Static Members
rgb2hex(rgb)
rgbToHex(rgb)
rgb2cmyk(rgb)
rgbToCmyk(rgb)
rgb2hsl(rgb)
rgbToHsl(rgb)
rgbToHsla(rgb, alpha)
rgb2rgba(rgb, alpha)
rgbToRgba(rgb, alpha)
color2rgb(color)
colorToRgb(color)
rgbString2Object(rgbString)
rgbStringToObject(rgbString)

Rgba

Functions about rgba color format

Rgba
Static Members
rgbaToHex(rgba)
rgba2rgb(rgba)
rgbaToRgb(rgba)
rgbaToCmyk(rgba)
rgbaToHsl(rgba)
rgbaToHsla(rgba)
colorToRgba(color)
rgbaString2Object(rgbaString)
rgbaStringToObject(rgbaString)

Hsl

Functions about hsl color format

Hsl
Static Members
hsl2hex(hsl)
hslToHex(hsl)
hsl2rgb(hsl)
hslToRgb(hsl)
hslToRgba(hsl, alpha)
hsl2cmyk(hsl)
hslToCmyk(hsl)
hslToHsla(hsl, alpha)
colorToHsl(color)
hslString2Object(hslString, hsl)
hslStringToObject(hslString, hsl)

Hsla

Functions about hsla color format

Hsla
Static Members
hslaToHex(hsla)
hslaToRgb(hsla)
hslaToRgba(hsla)
hslaToHsl(hsla)
hslaToCmyk(hsla)
colorToHsla(color)
hslaStringToObject(hslaString, hsls)

Cmyk

Functions about cmyk color format

Cmyk
Static Members
cmyk2hex(cmyk)
cmykToHex(cmyk)
cmyk2rgb(cmyk)
cmykToRgb(cmyk)
cmykToRgba(cmyk, alpha)
cmyk2hsl(cmyk)
cmykToHsl(cmyk)
cmykToHsla(cmyk, alpha)
colorToCmyk(color)
cmykString2Object(cmykString)
cmykStringToObject(cmykString)

Random

Random color generation

Random
Static Members
getRandomColor()
randomHex()

Mix

Functions about mixing colors

Mix
Static Members
mix(colors, weights?)

Naming

Functions about naming colors

Naming
Static Members
name(color)

stringToColor

Check if a string is a valid color and if so, transform it to the right Color.

stringToColor(stringColor: string, string: any): Color
Parameters
stringColor (string)
string (any) to convert to a Color
Returns
Color: Color

isRgbString

Check if a string is in these two formats:

  • 255, 0, 255 (short format)
  • rgb(255, 0, 255) (long format).
isRgbString(rgbString: string): any
Parameters
rgbString (string) rgb string color to check to be a valid rgb string
Returns
any: true if rgbString is a valid format, false otherwise

isRgbaString

Check if a string is in these two formats:

  • 255, 0, 255 (short format)
  • rgba(255, 0, 255) (long format).
isRgbaString(rgbaString: string): any
Parameters
rgbaString (string) rgba string color to check to be a valid rgba string
Returns
any: true if rgbaString is a valid format, false otherwise

isCmykString

Check if a string is in these two formats:

  • 0, 50, 20, 100 (short format)
  • cmyk(0, 50, 20, 100) (long format).
isCmykString(cmykString: string): any
Parameters
cmykString (string) cmyk string color to check to be a valid cmyk string
Returns
any: true if cmykString is a valid format, false otherwise

isHslString

Check if a string is in these two formats:

  • 322, 79%, 52% (short format)
  • hsl(322, 79%, 52%) (long format).
isHslString(hslString: string): any
Parameters
hslString (string) hsl string color to check to be a valid hsl string
Returns
any: true if hslString is a valid format, false otherwise

isHslaString

Check if a string is in these two formats:

  • 322, 79%, 52%, 0.5 (short format)
  • hsla(322, 79%, 52%, 0.5) (long format).
isHslaString(hslaString: string): any
Parameters
hslaString (string) hsl string color to check to be a valid hsla string
Returns
any: true if hslaString is a valid format, false otherwise