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.

Files changed (2) hide show
  1. package/index.js +11 -11
  2. 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})([a-f0-9]{1})?$/i;
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(abbr)) {
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
- rgb[i] = parseInt(match[i] + match[i], 16);
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 + hexAlpha, 16) / 255) * 100) / 100;
71
+ rgb[3] = Math.round((parseInt(hexAlpha, 16) / 255) * 100) / 100;
70
72
  }
71
- } else if (match = string.match(hex)) {
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
- // https://jsperf.com/slice-vs-substr-vs-substring-methods-long-string/19
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 < rgb.length; 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);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "color-string",
3
3
  "description": "Parser and generator for CSS color strings",
4
- "version": "1.5.1",
4
+ "version": "1.5.2",
5
5
  "author": "Heather Arthur <fayearthur@gmail.com>",
6
6
  "contributors": [
7
7
  "Maxime Thirouin",