소스 검색

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
No known key found for this signature in database 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) => {


불러오는 중...
취소
저장