color-string 1.6.0 → 1.7.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.
- package/README.md +3 -2
- package/index.js +12 -4
- 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
|
|
@@ -27,7 +25,10 @@ colorString.get('hwb(60, 3%, 60%)') // {model: 'hwb', value: [60, 3
|
|
|
27
25
|
colorString.get.rgb('#FFF') // [255, 255, 255, 1]
|
|
28
26
|
colorString.get.rgb('blue') // [0, 0, 255, 1]
|
|
29
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]
|
|
30
30
|
colorString.get.rgb('rgb(200, 200, 200)') // [200, 200, 200, 1]
|
|
31
|
+
colorString.get.rgb('rgb(200 200 200)') // [200, 200, 200, 1]
|
|
31
32
|
|
|
32
33
|
colorString.get.hsl('hsl(360, 100%, 50%)') // [0, 100, 50, 1]
|
|
33
34
|
colorString.get.hsl('hsl(360 100% 50%)') // [0, 100, 50, 1]
|
package/index.js
CHANGED
|
@@ -49,8 +49,8 @@ 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
|
|
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
54
|
var keyword = /(\D+)/;
|
|
55
55
|
|
|
56
56
|
var rgb = [0, 0, 0, 1];
|
|
@@ -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') {
|
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
|