Color / add an isStringColor utility function
This commit is contained in:
@@ -223,3 +223,14 @@ export function toString(color) {
|
||||
const a = color[3] === undefined ? 1 : color[3];
|
||||
return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} s String.
|
||||
* @return {boolean} Whether the string is actually a valid color
|
||||
*/
|
||||
export function isStringColor(s) {
|
||||
if (NAMED_COLOR_RE_.test(s)) {
|
||||
s = fromNamed(s);
|
||||
}
|
||||
return HEX_COLOR_RE_.test(s) || s.indexOf('rgba(') === 0 || s.indexOf('rgb(') === 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user