TK.Colors

TK.Colors provides a couple of functions for easy color calculations and conversions.

Source:

Methods

hex2hsl(hex) → {object}

Returns an object containing hue, stauration and lightness from a hexadecimal rgb color string

Parameters:
Name Type Description
hex string

Color string like "#FF0099"

Source:
Returns:

Object with members h, s and l as numbers (0..1)

Type
object

hex2rgb(hex) → {object}

Returns an object containing red, green and blue from a hexadecimal rgb color string

Parameters:
Name Type Description
hex string

Color string like "#FF0099"

Source:
Returns:

Object with members r, g and b as numbers (0..255)

Type
object

hsl2hex(h, s, l) → {string}

Returns hexadecimal color string from h, s and l as numbers (0..1)

Parameters:
Name Type Description
h number | array | object

red as number (0..1) or object with members h, s and l or array of HSL

s number

green as number (0..1)

l number

blue as number (0..1)

Source:
Returns:

hexadecimal string to be used in CSS or SVG

Type
string

hsl2rgb(h, s, l) → {object}

Returns red, green and blue (0..255) from hue, saturation and lightness (0..1)

Parameters:
Name Type Description
h number | array | object

hue (0..1) or object with members h, s and l or array of HSL

s number

saturation (0..1)

l number

lightness (0..1)

Source:
Returns:

Object with members r, g and b as numbers (0..255)

Type
object

name2hex(colorname) → {string}

Returns hexadecimal color string from color name

Parameters:
Name Type Description
colorname string

name of the color, e.g. "white", "IslamicGreen" or "lightCoral"

Source:
Returns:

hexadecimal string to be used in CSS or SVG

Type
string

rgb2bw(r, g, b) → {string}

Returns the highest contrast from red, green and blue (0..255) regarding ITU-R BT.709 as hex string

Parameters:
Name Type Description
r number | array | object

red (0..255) or object with members r, g and b or array of RGB

g number

green (0..255)

b number

blue (0..255)

Source:
Returns:

color ("#000000" or "#ffffff")

Type
string

rgb2gray(r, g, b) → {number}

Returns gray (0..1) from red, green and blue (0..255) regarding ITU-R BT.709

Parameters:
Name Type Description
r number | array | object

red (0..255) or object with members r, g and b or array of RGB

g number

green (0..255)

b number

blue (0..255)

Source:
Returns:

gray lightness (0..1)

Type
number

rgb2hex(r, g, b) → {string}

Returns hexadecimal color string from r, g and b as numbers (0..255)

Parameters:
Name Type Description
r number | array | object

red as number (0..255) or object with members r, g and b or array of RGB

g number

green as number (0..255)

b number

blue as number (0..255)

Source:
Returns:

hexadecimal string to be used in CSS or SVG

Type
string

rgb2hsl(r, g, b) → {object}

Returns hue, saturation and lightness (0..1) from red, green and blue (0..255).

Parameters:
Name Type Description
r number | array | object

red (0..255) or object with members r, g and b or array of RGB

g number

green (0..255)

b number

blue (0..255)

Source:
Returns:

Object with members h, s and l as numbers (0..1)

Type
object