color-string 1.7.2 → 1.8.1

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 +5 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -52,7 +52,7 @@ cs.get.rgb = function (string) {
52
52
  var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
53
53
  var rgba = /^rgba?\(\s*([+-]?\d+)\s*,?\s*([+-]?\d+)\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
  }
@@ -142,7 +142,7 @@ cs.get.hsl = function (string) {
142
142
 
143
143
  if (match) {
144
144
  var alpha = parseFloat(match[4]);
145
- var h = (parseFloat(match[1]) + 360) % 360;
145
+ var h = ((parseFloat(match[1]) % 360) + 360) % 360;
146
146
  var s = clamp(parseFloat(match[2]), 0, 100);
147
147
  var l = clamp(parseFloat(match[3]), 0, 100);
148
148
  var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
@@ -237,6 +237,6 @@ function clamp(num, min, max) {
237
237
  }
238
238
 
239
239
  function hexDouble(num) {
240
- var str = num.toString(16).toUpperCase();
240
+ var str = Math.round(num).toString(16).toUpperCase();
241
241
  return (str.length < 2) ? '0' + str : str;
242
242
  }
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.2",
4
+ "version": "1.8.1",
5
5
  "author": "Heather Arthur <fayearthur@gmail.com>",
6
6
  "contributors": [
7
7
  "Maxime Thirouin",