Stay organized with collections
Save and categorize content based on your preferences.
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.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-18 UTC."],[[["The `utils.colour.parse()` function converts various color formats (like 'red', '#f00', 'rgb(255, 0, 0)') into a standardized hexadecimal representation (e.g., '#ff0000')."],["If the input color format is invalid or unparsable, the function will return `null`."],["This function accepts color input as either a string or a number."],["The primary purpose of this function is to provide a consistent color format for use within Blockly."]]],[]]