color-string 1.7.1 → 1.8.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 +7 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  /* MIT license */
2
2
  var colorNames = require('color-name');
3
3
  var swizzle = require('simple-swizzle');
4
+ var hasOwnProperty = Object.hasOwnProperty;
4
5
 
5
6
  var reverseNames = {};
6
7
 
7
8
  // create a list of reverse color names
8
9
  for (var name in colorNames) {
9
- if (colorNames.hasOwnProperty(name)) {
10
+ if (hasOwnProperty.call(colorNames, name)) {
10
11
  reverseNames[colorNames[name]] = name;
11
12
  }
12
13
  }
@@ -51,7 +52,7 @@ cs.get.rgb = function (string) {
51
52
  var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
52
53
  var rgba = /^rgba?\(\s*([+-]?\d+)\s*,?\s*([+-]?\d+)\s*,?\s*([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
53
54
  var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
54
- var keyword = /(\w+)/;
55
+ var keyword = /^(\w+)$/;
55
56
 
56
57
  var rgb = [0, 0, 0, 1];
57
58
  var match;
@@ -111,12 +112,11 @@ cs.get.rgb = function (string) {
111
112
  return [0, 0, 0, 0];
112
113
  }
113
114
 
114
- rgb = colorNames[match[1]];
115
-
116
- if (!rgb) {
115
+ if (!hasOwnProperty.call(colorNames, match[1])) {
117
116
  return null;
118
117
  }
119
118
 
119
+ rgb = colorNames[match[1]];
120
120
  rgb[3] = 1;
121
121
 
122
122
  return rgb;
@@ -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.1",
4
+ "version": "1.8.0",
5
5
  "author": "Heather Arthur <fayearthur@gmail.com>",
6
6
  "contributors": [
7
7
  "Maxime Thirouin",