color-string 1.5.2 → 1.6.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 (3) hide show
  1. package/README.md +3 -0
  2. package/index.js +7 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -21,6 +21,7 @@ colorString.get('#FFF') // {model: 'rgb', value: [255,
21
21
  colorString.get('#FFFA') // {model: 'rgb', value: [255, 255, 255, 0.67]}
22
22
  colorString.get('#FFFFFFAA') // {model: 'rgb', value: [255, 255, 255, 0.67]}
23
23
  colorString.get('hsl(360, 100%, 50%)') // {model: 'hsl', value: [0, 100, 50, 1]}
24
+ colorString.get('hsl(360 100% 50%)') // {model: 'hsl', value: [0, 100, 50, 1]}
24
25
  colorString.get('hwb(60, 3%, 60%)') // {model: 'hwb', value: [60, 3, 60, 1]}
25
26
 
26
27
  colorString.get.rgb('#FFF') // [255, 255, 255, 1]
@@ -29,7 +30,9 @@ colorString.get.rgb('rgba(200, 60, 60, 0.3)') // [200, 60, 60, 0.3]
29
30
  colorString.get.rgb('rgb(200, 200, 200)') // [200, 200, 200, 1]
30
31
 
31
32
  colorString.get.hsl('hsl(360, 100%, 50%)') // [0, 100, 50, 1]
33
+ colorString.get.hsl('hsl(360 100% 50%)') // [0, 100, 50, 1]
32
34
  colorString.get.hsl('hsla(360, 60%, 50%, 0.4)') // [0, 60, 50, 0.4]
35
+ colorString.get.hsl('hsl(360 60% 50% / 0.4)') // [0, 60, 50, 0.4]
33
36
 
34
37
  colorString.get.hwb('hwb(60, 3%, 60%)') // [60, 3, 60, 1]
35
38
  colorString.get.hwb('hwb(60, 3%, 60%, 0.6)') // [60, 3, 60, 0.6]
package/index.js CHANGED
@@ -12,7 +12,8 @@ for (var name in colorNames) {
12
12
  }
13
13
 
14
14
  var cs = module.exports = {
15
- to: {}
15
+ to: {},
16
+ get: {}
16
17
  };
17
18
 
18
19
  cs.get = function (string) {
@@ -68,7 +69,7 @@ cs.get.rgb = function (string) {
68
69
  }
69
70
 
70
71
  if (hexAlpha) {
71
- rgb[3] = Math.round((parseInt(hexAlpha, 16) / 255) * 100) / 100;
72
+ rgb[3] = parseInt(hexAlpha, 16) / 255;
72
73
  }
73
74
  } else if (match = string.match(abbr)) {
74
75
  match = match[1];
@@ -79,7 +80,7 @@ cs.get.rgb = function (string) {
79
80
  }
80
81
 
81
82
  if (hexAlpha) {
82
- rgb[3] = Math.round((parseInt(hexAlpha + hexAlpha, 16) / 255) * 100) / 100;
83
+ rgb[3] = parseInt(hexAlpha + hexAlpha, 16) / 255;
83
84
  }
84
85
  } else if (match = string.match(rgba)) {
85
86
  for (i = 0; i < 3; i++) {
@@ -128,12 +129,12 @@ cs.get.hsl = function (string) {
128
129
  return null;
129
130
  }
130
131
 
131
- var hsl = /^hsla?\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
132
+ var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?[\d\.]+)\s*)?\)$/;
132
133
  var match = string.match(hsl);
133
134
 
134
135
  if (match) {
135
136
  var alpha = parseFloat(match[4]);
136
- var h = ((parseFloat(match[1]) % 360) + 360) % 360;
137
+ var h = (parseFloat(match[1]) + 360) % 360;
137
138
  var s = clamp(parseFloat(match[2]), 0, 100);
138
139
  var l = clamp(parseFloat(match[3]), 0, 100);
139
140
  var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
@@ -149,7 +150,7 @@ cs.get.hwb = function (string) {
149
150
  return null;
150
151
  }
151
152
 
152
- var hwb = /^hwb\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
153
+ var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
153
154
  var match = string.match(hwb);
154
155
 
155
156
  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.5.2",
4
+ "version": "1.6.0",
5
5
  "author": "Heather Arthur <fayearthur@gmail.com>",
6
6
  "contributors": [
7
7
  "Maxime Thirouin",