Property

names

static

non-null Object with string properties

A map that contains the 16 basic colour keywords as defined by W3C: https://www.w3.org/TR/2018/REC-css-color-3-20180619/#html4 The keys of this map are the lowercase "readable" names of the colours, while the values are the "hex" values.

Methods

blend

static

blend(colour1, colour2, factor) returns string

Blend two colours together, using the specified factor to indicate the weight given to the first colour.

Parameter

colour1

string

First colour.

colour2

string

Second colour.

factor

number

The weight to be given to colour1 over colour2. Values should be in the range [0, 1].

Returns

string Combined colour represented in hex.

hexToRgb

static

hexToRgb(hexColor) returns Array of number

Converts a hex representation of a colour to RGB.

Parameter

hexColor

string

Colour in '#ff0000' format.

Returns

non-null Array of number RGB representation of the colour.

hsvToHex

static

hsvToHex(h, s, v) returns string

Converts an HSV triplet to hex representation.

Parameter

h

number

Hue value in [0, 360].

s

number

Saturation value in [0, 1].

v

number

Brightness in [0, 255].

Returns

string Hex representation of the colour.

parse

static

parse(str) returns (string or null)

Parses a colour from a string. .parse('red') -> '#ff0000' .parse('#f00') -> '#ff0000' .parse('#ff0000') -> '#ff0000' .parse('rgb(255, 0, 0)') -> '#ff0000'

Parameter

str

string

Colour in some CSS format.

Returns

(string or null) A string containing a hex representation of the colour, or null if can't be parsed.

rgbToHex

static

rgbToHex(r, g, b) returns string

Converts a colour from RGB to hex representation.

Parameter

r

number

Amount of red, int between 0 and 255.

g

number

Amount of green, int between 0 and 255.

b

number

Amount of blue, int between 0 and 255.

Returns

string Hex representation of the colour.