Skip to content

Commit

Permalink
Optimises the hex color validation.
Browse files Browse the repository at this point in the history
Relates to clean-css#986
  • Loading branch information
alfaproject committed Aug 18, 2018
1 parent 314e465 commit 0a9113d
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/optimizer/validator.js
Expand Up @@ -15,11 +15,7 @@ var timingFunctionRegex = /^(cubic\-bezier|steps)\([^\)]+\)$/;
var validTimeUnits = ['ms', 's'];
var urlRegex = /^url\([\s\S]+\)$/i;
var variableRegex = new RegExp('^' + variableRegexStr + '$', 'i');

var eightValueColorRegex = /^#[0-9a-f]{8}$/i;
var fourValueColorRegex = /^#[0-9a-f]{4}$/i;
var sixValueColorRegex = /^#[0-9a-f]{6}$/i;
var threeValueColorRegex = /^#[0-9a-f]{3}$/i;
var hexColorRegex = /^#(?:(?:[0-9a-fA-F]{2}){2,4}|(?:[0-9a-fA-F]){3})$/; // https://regexr.com/3tdfg

var DECIMAL_DOT = '.';
var MINUS_SIGN = '-';
Expand Down Expand Up @@ -368,7 +364,7 @@ function isFunction(value) {
}

function isHexColor(value) {
return threeValueColorRegex.test(value) || fourValueColorRegex.test(value) || sixValueColorRegex.test(value) || eightValueColorRegex.test(value);
return hexColorRegex.test(value);
}

function isHslColor(value) {
Expand Down

0 comments on commit 0a9113d

Please sign in to comment.