blockly > utils > colour > parse

utils.colour.parse() function

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

Signature:

export declare function parse(str: string | number): string | null;

Parameters

Parameter Type Description
str string | number Colour in some CSS format.

Returns:

string | null

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