color-string 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of color-string might be problematic. Click here for more details.
- package/index.js +11 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -46,7 +46,7 @@ cs.get.rgb = function (string) {
|
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
var abbr = /^#([a-f0-9]{3})
|
|
49
|
+
var abbr = /^#([a-f0-9]{3,4})$/i;
|
|
50
50
|
var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
|
|
51
51
|
var rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
|
|
52
52
|
var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
|
|
@@ -57,29 +57,29 @@ cs.get.rgb = function (string) {
|
|
|
57
57
|
var i;
|
|
58
58
|
var hexAlpha;
|
|
59
59
|
|
|
60
|
-
if (match = string.match(
|
|
60
|
+
if (match = string.match(hex)) {
|
|
61
61
|
hexAlpha = match[2];
|
|
62
62
|
match = match[1];
|
|
63
63
|
|
|
64
64
|
for (i = 0; i < 3; i++) {
|
|
65
|
-
|
|
65
|
+
// https://jsperf.com/slice-vs-substr-vs-substring-methods-long-string/19
|
|
66
|
+
var i2 = i * 2;
|
|
67
|
+
rgb[i] = parseInt(match.slice(i2, i2 + 2), 16);
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
if (hexAlpha) {
|
|
69
|
-
rgb[3] = Math.round((parseInt(hexAlpha
|
|
71
|
+
rgb[3] = Math.round((parseInt(hexAlpha, 16) / 255) * 100) / 100;
|
|
70
72
|
}
|
|
71
|
-
} else if (match = string.match(
|
|
72
|
-
hexAlpha = match[2];
|
|
73
|
+
} else if (match = string.match(abbr)) {
|
|
73
74
|
match = match[1];
|
|
75
|
+
hexAlpha = match[3];
|
|
74
76
|
|
|
75
77
|
for (i = 0; i < 3; i++) {
|
|
76
|
-
|
|
77
|
-
var i2 = i * 2;
|
|
78
|
-
rgb[i] = parseInt(match.slice(i2, i2 + 2), 16);
|
|
78
|
+
rgb[i] = parseInt(match[i] + match[i], 16);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
if (hexAlpha) {
|
|
82
|
-
rgb[3] = Math.round((parseInt(hexAlpha, 16) / 255) * 100) / 100;
|
|
82
|
+
rgb[3] = Math.round((parseInt(hexAlpha + hexAlpha, 16) / 255) * 100) / 100;
|
|
83
83
|
}
|
|
84
84
|
} else if (match = string.match(rgba)) {
|
|
85
85
|
for (i = 0; i < 3; i++) {
|
|
@@ -115,7 +115,7 @@ cs.get.rgb = function (string) {
|
|
|
115
115
|
return null;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
for (i = 0; i <
|
|
118
|
+
for (i = 0; i < 3; i++) {
|
|
119
119
|
rgb[i] = clamp(rgb[i], 0, 255);
|
|
120
120
|
}
|
|
121
121
|
rgb[3] = clamp(rgb[3], 0, 1);
|