color-string 1.5.4 → 1.7.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.
- package/README.md +6 -2
- package/index.js +15 -7
- package/package.json +1 -1
- package/CHANGELOG.md +0 -18
package/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# color-string
|
|
2
2
|
|
|
3
|
-
[](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
|
@@ -49,9 +49,9 @@ cs.get.rgb = function (string) {
|
|
|
49
49
|
|
|
50
50
|
var abbr = /^#([a-f0-9]{3,4})$/i;
|
|
51
51
|
var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
|
|
52
|
-
var rgba = /^rgba?\(\s*([+-]?\d+)\s
|
|
53
|
-
var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s
|
|
54
|
-
var keyword = /(\
|
|
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 = /(\w+)/;
|
|
55
55
|
|
|
56
56
|
var rgb = [0, 0, 0, 1];
|
|
57
57
|
var match;
|
|
@@ -88,7 +88,11 @@ cs.get.rgb = function (string) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
if (match[4]) {
|
|
91
|
-
|
|
91
|
+
if (match[5]) {
|
|
92
|
+
rgb[3] = parseInt(match[4], 0) * 0.01;
|
|
93
|
+
} else {
|
|
94
|
+
rgb[3] = parseFloat(match[4]);
|
|
95
|
+
}
|
|
92
96
|
}
|
|
93
97
|
} else if (match = string.match(per)) {
|
|
94
98
|
for (i = 0; i < 3; i++) {
|
|
@@ -96,7 +100,11 @@ cs.get.rgb = function (string) {
|
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
if (match[4]) {
|
|
99
|
-
|
|
103
|
+
if (match[5]) {
|
|
104
|
+
rgb[3] = parseInt(match[4], 0) * 0.01;
|
|
105
|
+
} else {
|
|
106
|
+
rgb[3] = parseFloat(match[4]);
|
|
107
|
+
}
|
|
100
108
|
}
|
|
101
109
|
} else if (match = string.match(keyword)) {
|
|
102
110
|
if (match[1] === 'transparent') {
|
|
@@ -129,7 +137,7 @@ cs.get.hsl = function (string) {
|
|
|
129
137
|
return null;
|
|
130
138
|
}
|
|
131
139
|
|
|
132
|
-
var hsl = /^hsla?\(\s*([+-]?(?:\d
|
|
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) {
|
|
@@ -150,7 +158,7 @@ cs.get.hwb = function (string) {
|
|
|
150
158
|
return null;
|
|
151
159
|
}
|
|
152
160
|
|
|
153
|
-
var hwb = /^hwb\(\s*([+-]?\d
|
|
161
|
+
var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
|
|
154
162
|
var match = string.match(hwb);
|
|
155
163
|
|
|
156
164
|
if (match) {
|
package/package.json
CHANGED
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
|