diff --git a/lib/parsers.js b/lib/parsers.js index 05e8da9..786179f 100644 --- a/lib/parsers.js +++ b/lib/parsers.js @@ -29,7 +29,8 @@ var percentRegEx = /^[-+]?[0-9]*\.?[0-9]+%$/; var urlRegEx = /^url\(\s*([^)]*)\s*\)$/; var stringRegEx = /^("[^"]*"|'[^']*')$/; var colorRegEx1 = /^#([0-9a-fA-F]{3,4}){1,2}$/; -var colorRegEx2 = /^rgba?\(\s*((?:(?:none|[-+]?[0-9]*\.?[0-9]+%?)[\s,/]*){2,3}(?:none|[-+]?[0-9]*\.?[0-9]+%?))\s*\)$/; +var colorRegEx2 = +/^rgba?\(\s*((?:(?:none|[-+]?[0-9]*\.?[0-9]+%?)[\s,/]*){2,3}(?:none|[-+]?[0-9]*\.?[0-9]+%?))\s*\)$/; var rgbdelimiters = /[\s,/]+/; var calcRegEx = /^calc\(([^)]*)\)$/; var colorRegEx4 = @@ -297,14 +298,20 @@ exports.parseColor = function parseColor(val) { res = colorRegEx2.exec(val); if (res) { parts = res[1].split(rgbdelimiters); - [red, green, blue] = parts.slice(0, 3).map(code => - code.toLowerCase() == "none" ? 0 : - Math.min(255, Math.max(0, - percentRegEx.test(code) - ? Math.round((parseFloat(code.slice(0, -1)) * 255) / 100) - : integerRegEx.test(code) - ? parseInt(code, 10) - : undefined + [red, green, blue] = parts + .slice(0, 3) + .map((code) => + code.toLowerCase() == 'none' + ? 0 + : Math.min( + 255, + Math.max( + 0, + percentRegEx.test(code) + ? Math.round((parseFloat(code.slice(0, -1)) * 255) / 100) + : integerRegEx.test(code) + ? parseInt(code, 10) + : undefined ) ) );