fix: match possible whitespace chars at the start

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
This commit is contained in:
Chinmay D. Pai 2020-03-23 21:19:46 +05:30
parent 2688662c82
commit 2eb61e46c0
No known key found for this signature in database
GPG Key ID: 75507BE256F40CED

View File

@ -37,8 +37,8 @@ export function lightenDarkenColor(color, amt) {
export function isValidColor(string) {
// https://stackoverflow.com/a/32685393
let HEX_RE = /^(#)((?:[A-Fa-f0-9]{3}){1,2})$/i
let RGB_RE = /^(rgb|hsl)(a?)[(]\s*([\d.]+\s*%?)\s*,\s*([\d.]+\s*%?)\s*,\s*([\d.]+\s*%?)\s*(?:,\s*([\d.]+)\s*)?[)]$/i
let HEX_RE = /(^\s*)(#)((?:[A-Fa-f0-9]{3}){1,2})$/i
let RGB_RE = /(^\s*)(rgb|hsl)(a?)[(]\s*([\d.]+\s*%?)\s*,\s*([\d.]+\s*%?)\s*,\s*([\d.]+\s*%?)\s*(?:,\s*([\d.]+)\s*)?[)]$/i
return HEX_RE.test(string) || RGB_RE.test(string);
}