color-string 1.5.5 → 1.7.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.
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # color-string
2
2
 
3
- [![Build Status](https://travis-ci.org/Qix-/color-string.svg?branch=master)](https://travis-ci.org/Qix-/color-string)
4
-
5
3
  > library for parsing and generating CSS color strings.
6
4
 
7
5
  ## Install
@@ -21,15 +19,21 @@ colorString.get('#FFF') // {model: 'rgb', value: [255,
21
19
  colorString.get('#FFFA') // {model: 'rgb', value: [255, 255, 255, 0.67]}
22
20
  colorString.get('#FFFFFFAA') // {model: 'rgb', value: [255, 255, 255, 0.67]}
23
21
  colorString.get('hsl(360, 100%, 50%)') // {model: 'hsl', value: [0, 100, 50, 1]}
22
+ colorString.get('hsl(360 100% 50%)') // {model: 'hsl', value: [0, 100, 50, 1]}
24
23
  colorString.get('hwb(60, 3%, 60%)') // {model: 'hwb', value: [60, 3, 60, 1]}
25
24
 
26
25
  colorString.get.rgb('#FFF') // [255, 255, 255, 1]
27
26
  colorString.get.rgb('blue') // [0, 0, 255, 1]
28
27
  colorString.get.rgb('rgba(200, 60, 60, 0.3)') // [200, 60, 60, 0.3]
28
+ colorString.get.rgb('rgba(200 60 60 / 0.3)') // [200, 60, 60, 0.3]
29
+ colorString.get.rgb('rgba(200 60 60 / 30%)') // [200, 60, 60, 0.3]
29
30
  colorString.get.rgb('rgb(200, 200, 200)') // [200, 200, 200, 1]
31
+ colorString.get.rgb('rgb(200 200 200)') // [200, 200, 200, 1]
30
32
 
31
33
  colorString.get.hsl('hsl(360, 100%, 50%)') // [0, 100, 50, 1]
34
+ colorString.get.hsl('hsl(360 100% 50%)') // [0, 100, 50, 1]
32
35
  colorString.get.hsl('hsla(360, 60%, 50%, 0.4)') // [0, 60, 50, 0.4]
36
+ colorString.get.hsl('hsl(360 60% 50% / 0.4)') // [0, 60, 50, 0.4]
33
37
 
34
38
  colorString.get.hwb('hwb(60, 3%, 60%)') // [60, 3, 60, 1]
35
39
  colorString.get.hwb('hwb(60, 3%, 60%, 0.6)') // [60, 3, 60, 0.6]
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
  }
@@ -49,9 +50,9 @@ cs.get.rgb = function (string) {
49
50
 
50
51
  var abbr = /^#([a-f0-9]{3,4})$/i;
51
52
  var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
52
- var rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
53
- var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
54
- var keyword = /(\D+)/;
53
+ var rgba = /^rgba?\(\s*([+-]?\d+)\s*,?\s*([+-]?\d+)\s*,?\s*([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
54
+ var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
55
+ var keyword = /(\w+)/;
55
56
 
56
57
  var rgb = [0, 0, 0, 1];
57
58
  var match;
@@ -88,7 +89,11 @@ cs.get.rgb = function (string) {
88
89
  }
89
90
 
90
91
  if (match[4]) {
91
- rgb[3] = parseFloat(match[4]);
92
+ if (match[5]) {
93
+ rgb[3] = parseInt(match[4], 0) * 0.01;
94
+ } else {
95
+ rgb[3] = parseFloat(match[4]);
96
+ }
92
97
  }
93
98
  } else if (match = string.match(per)) {
94
99
  for (i = 0; i < 3; i++) {
@@ -96,19 +101,22 @@ cs.get.rgb = function (string) {
96
101
  }
97
102
 
98
103
  if (match[4]) {
99
- rgb[3] = parseFloat(match[4]);
104
+ if (match[5]) {
105
+ rgb[3] = parseInt(match[4], 0) * 0.01;
106
+ } else {
107
+ rgb[3] = parseFloat(match[4]);
108
+ }
100
109
  }
101
110
  } else if (match = string.match(keyword)) {
102
111
  if (match[1] === 'transparent') {
103
112
  return [0, 0, 0, 0];
104
113
  }
105
114
 
106
- rgb = colorNames[match[1]];
107
-
108
- if (!rgb) {
115
+ if (!hasOwnProperty.call(colorNames, match[1])) {
109
116
  return null;
110
117
  }
111
118
 
119
+ rgb = colorNames[match[1]];
112
120
  rgb[3] = 1;
113
121
 
114
122
  return rgb;
@@ -129,7 +137,7 @@ cs.get.hsl = function (string) {
129
137
  return null;
130
138
  }
131
139
 
132
- 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\.]+)\s*)?\)$/;
133
141
  var match = string.match(hsl);
134
142
 
135
143
  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.5",
4
+ "version": "1.7.2",
5
5
  "author": "Heather Arthur <fayearthur@gmail.com>",
6
6
  "contributors": [
7
7
  "Maxime Thirouin",
package/CHANGELOG.md DELETED
@@ -1,18 +0,0 @@
1
- # 0.4.0
2
-
3
- - Changed: Invalid conversions now return `null` instead of `undefined`
4
- - Changed: Moved to XO standard
5
- - Fixed: a few details in package.json
6
- - Fixed: readme output regarding wrapped hue values ([#21](https://github.com/MoOx/color-string/pull/21))
7
-
8
- # 0.3.0
9
-
10
- - Fixed: HSL alpha channel ([#16](https://github.com/harthur/color-string/pull/16))
11
- - Fixed: ability to parse signed number ([#15](https://github.com/harthur/color-string/pull/15))
12
- - Removed: component.json
13
- - Removed: browser build
14
- - Added: license field to package.json ([#17](https://github.com/harthur/color-string/pull/17))
15
-
16
- ---
17
-
18
- Check out commit logs for earlier releases