14 lines
422 B
JavaScript
14 lines
422 B
JavaScript
const SAFE_COLOR =
|
|
/^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%]+\)|[a-z]+)$/i;
|
|
|
|
// Site icons come from remote sites, so only pass through values that look
|
|
// like plain CSS colors before handing them to a style modifier.
|
|
export function safeColor(value) {
|
|
if (typeof value !== 'string') {
|
|
return undefined;
|
|
}
|
|
|
|
const trimmed = value.trim();
|
|
return SAFE_COLOR.test(trimmed) ? trimmed : undefined;
|
|
}
|