浏览代码

Merge pull request #275 from Thunderbottom/color-check-fix

fix: improve regex to check if string is hex or rgb
tags/v1.3.1
Shivam Mishra 5 年前
committed by GitHub
父节点
当前提交
e95f0aadaa
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 1 个文件被更改,包括 4 次插入2 次删除
  1. +4
    -2
      src/js/utils/colors.js

+ 4
- 2
src/js/utils/colors.js 查看文件

@@ -36,8 +36,10 @@ export function lightenDarkenColor(color, amt) {
}

export function isValidColor(string) {
// https://stackoverflow.com/a/8027444/6495043
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(string);
// https://stackoverflow.com/a/32685393
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) => {


正在加载...
取消
保存