color-string 1.7.4 → 1.9.0

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.
Files changed (2) hide show
  1. package/index.js +6 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -50,9 +50,9 @@ cs.get.rgb = function (string) {
50
50
 
51
51
  var abbr = /^#([a-f0-9]{3,4})$/i;
52
52
  var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
53
- var rgba = /^rgba?\(\s*([+-]?\d+)\s*,?\s*([+-]?\d+)\s*,?\s*([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
53
+ var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
54
54
  var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
55
- var keyword = /(\w+)/;
55
+ var keyword = /^(\w+)$/;
56
56
 
57
57
  var rgb = [0, 0, 0, 1];
58
58
  var match;
@@ -90,7 +90,7 @@ cs.get.rgb = function (string) {
90
90
 
91
91
  if (match[4]) {
92
92
  if (match[5]) {
93
- rgb[3] = parseInt(match[4], 0) * 0.01;
93
+ rgb[3] = parseFloat(match[4]) * 0.01;
94
94
  } else {
95
95
  rgb[3] = parseFloat(match[4]);
96
96
  }
@@ -102,7 +102,7 @@ cs.get.rgb = function (string) {
102
102
 
103
103
  if (match[4]) {
104
104
  if (match[5]) {
105
- rgb[3] = parseInt(match[4], 0) * 0.01;
105
+ rgb[3] = parseFloat(match[4]) * 0.01;
106
106
  } else {
107
107
  rgb[3] = parseFloat(match[4]);
108
108
  }
@@ -137,7 +137,7 @@ cs.get.hsl = function (string) {
137
137
  return null;
138
138
  }
139
139
 
140
- var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?[\d\.]+)\s*)?\)$/;
140
+ var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
141
141
  var match = string.match(hsl);
142
142
 
143
143
  if (match) {
@@ -158,7 +158,7 @@ cs.get.hwb = function (string) {
158
158
  return null;
159
159
  }
160
160
 
161
- var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
161
+ var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
162
162
  var match = string.match(hwb);
163
163
 
164
164
  if (match) {
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.7.4",
4
+ "version": "1.9.0",
5
5
  "author": "Heather Arthur <fayearthur@gmail.com>",
6
6
  "contributors": [
7
7
  "Maxime Thirouin",