Merge pull request #275 from Thunderbottom/color-check-fix
fix: improve regex to check if string is hex or rgb
This commit is contained in:
commit
e95f0aadaa
@ -36,8 +36,10 @@ export function lightenDarkenColor(color, amt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isValidColor(string) {
|
export function isValidColor(string) {
|
||||||
// https://stackoverflow.com/a/8027444/6495043
|
// https://stackoverflow.com/a/32685393
|
||||||
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(string);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getColor = (color) => {
|
export const getColor = (color) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user