color-string
Advanced tools
Comparing version 1.5.1 to 1.5.2
22
index.js
@@ -49,3 +49,3 @@ /* MIT license */ | ||
var abbr = /^#([a-f0-9]{3})([a-f0-9]{1})?$/i; | ||
var abbr = /^#([a-f0-9]{3,4})$/i; | ||
var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i; | ||
@@ -61,3 +61,3 @@ var rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/; | ||
if (match = string.match(abbr)) { | ||
if (match = string.match(hex)) { | ||
hexAlpha = match[2]; | ||
@@ -67,20 +67,20 @@ match = match[1]; | ||
for (i = 0; i < 3; i++) { | ||
rgb[i] = parseInt(match[i] + match[i], 16); | ||
// https://jsperf.com/slice-vs-substr-vs-substring-methods-long-string/19 | ||
var i2 = i * 2; | ||
rgb[i] = parseInt(match.slice(i2, i2 + 2), 16); | ||
} | ||
if (hexAlpha) { | ||
rgb[3] = Math.round((parseInt(hexAlpha + hexAlpha, 16) / 255) * 100) / 100; | ||
rgb[3] = Math.round((parseInt(hexAlpha, 16) / 255) * 100) / 100; | ||
} | ||
} else if (match = string.match(hex)) { | ||
hexAlpha = match[2]; | ||
} else if (match = string.match(abbr)) { | ||
match = match[1]; | ||
hexAlpha = match[3]; | ||
for (i = 0; i < 3; i++) { | ||
// https://jsperf.com/slice-vs-substr-vs-substring-methods-long-string/19 | ||
var i2 = i * 2; | ||
rgb[i] = parseInt(match.slice(i2, i2 + 2), 16); | ||
rgb[i] = parseInt(match[i] + match[i], 16); | ||
} | ||
if (hexAlpha) { | ||
rgb[3] = Math.round((parseInt(hexAlpha, 16) / 255) * 100) / 100; | ||
rgb[3] = Math.round((parseInt(hexAlpha + hexAlpha, 16) / 255) * 100) / 100; | ||
} | ||
@@ -121,3 +121,3 @@ } else if (match = string.match(rgba)) { | ||
for (i = 0; i < rgb.length; i++) { | ||
for (i = 0; i < 3; i++) { | ||
rgb[i] = clamp(rgb[i], 0, 255); | ||
@@ -124,0 +124,0 @@ } |
{ | ||
"name": "color-string", | ||
"description": "Parser and generator for CSS color strings", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"author": "Heather Arthur <fayearthur@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10045