color-string 0.2.4 → 0.3.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.
Potentially problematic release.
This version of color-string might be problematic. Click here for more details.
- package/CHANGELOG.md +11 -0
- package/color-string.js +9 -7
- package/package.json +7 -6
- package/test/basic.js +14 -1
- package/Gruntfile.js +0 -42
- package/browser.js +0 -3
- package/component.json +0 -13
- package/test.html +0 -8
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# 0.3.0
|
|
2
|
+
|
|
3
|
+
- Fixed: HSL alpha channel ([#16](https://github.com/harthur/color-string/pull/16))
|
|
4
|
+
- Fixed: ability to parse signed number ([#15](https://github.com/harthur/color-string/pull/15))
|
|
5
|
+
- Removed: component.json
|
|
6
|
+
- Removed: browser build
|
|
7
|
+
- Added: license field to package.json ([#17](https://github.com/harthur/color-string/pull/17))
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Check out commit logs for earlier releases
|
package/color-string.js
CHANGED
|
@@ -26,8 +26,8 @@ function getRgba(string) {
|
|
|
26
26
|
}
|
|
27
27
|
var abbr = /^#([a-fA-F0-9]{3})$/,
|
|
28
28
|
hex = /^#([a-fA-F0-9]{6})$/,
|
|
29
|
-
rgba = /^rgba?\(\s*(
|
|
30
|
-
per = /^rgba?\(\s*([\d\.]+)\%\s*,\s*([\d\.]+)\%\s*,\s*([\d\.]+)\%\s*(?:,\s*([\d\.]+)\s*)?\)$/,
|
|
29
|
+
rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,
|
|
30
|
+
per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,
|
|
31
31
|
keyword = /(\D+)/;
|
|
32
32
|
|
|
33
33
|
var rgb = [0, 0, 0],
|
|
@@ -84,13 +84,14 @@ function getHsla(string) {
|
|
|
84
84
|
if (!string) {
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
|
-
var hsl = /^hsla?\(\s*(
|
|
87
|
+
var hsl = /^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
|
|
88
88
|
var match = string.match(hsl);
|
|
89
89
|
if (match) {
|
|
90
|
+
var alpha = parseFloat(match[4]);
|
|
90
91
|
var h = scale(parseInt(match[1]), 0, 360),
|
|
91
92
|
s = scale(parseFloat(match[2]), 0, 100),
|
|
92
93
|
l = scale(parseFloat(match[3]), 0, 100),
|
|
93
|
-
a = scale(
|
|
94
|
+
a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
|
|
94
95
|
return [h, s, l, a];
|
|
95
96
|
}
|
|
96
97
|
}
|
|
@@ -99,13 +100,14 @@ function getHwb(string) {
|
|
|
99
100
|
if (!string) {
|
|
100
101
|
return;
|
|
101
102
|
}
|
|
102
|
-
var hwb = /^hwb\(\s*(
|
|
103
|
+
var hwb = /^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
|
|
103
104
|
var match = string.match(hwb);
|
|
104
105
|
if (match) {
|
|
106
|
+
var alpha = parseFloat(match[4]);
|
|
105
107
|
var h = scale(parseInt(match[1]), 0, 360),
|
|
106
108
|
w = scale(parseFloat(match[2]), 0, 100),
|
|
107
109
|
b = scale(parseFloat(match[3]), 0, 100),
|
|
108
|
-
a = scale(
|
|
110
|
+
a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
|
|
109
111
|
return [h, w, b, a];
|
|
110
112
|
}
|
|
111
113
|
}
|
|
@@ -216,4 +218,4 @@ function hexDouble(num) {
|
|
|
216
218
|
var reverseNames = {};
|
|
217
219
|
for (var name in colorNames) {
|
|
218
220
|
reverseNames[colorNames[name]] = name;
|
|
219
|
-
}
|
|
221
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "color-string",
|
|
3
3
|
"description": "Parser and generator for CSS color strings",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"author": "Heather Arthur <fayearthur@gmail.com>",
|
|
6
|
-
"contributors":
|
|
6
|
+
"contributors": [
|
|
7
|
+
"Maxime Thirouin",
|
|
8
|
+
"Dyma Ywanov <dfcreative@gmail.com>"
|
|
9
|
+
],
|
|
7
10
|
"repository": {
|
|
8
11
|
"type": "git",
|
|
9
12
|
"url": "http://github.com/harthur/color-string.git"
|
|
@@ -11,14 +14,12 @@
|
|
|
11
14
|
"scripts": {
|
|
12
15
|
"test": "node test/basic.js"
|
|
13
16
|
},
|
|
17
|
+
"license": "MIT",
|
|
14
18
|
"main": "./color-string",
|
|
15
19
|
"dependencies": {
|
|
16
|
-
"color-name": "1.0.
|
|
20
|
+
"color-name": "^1.0.0"
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
19
|
-
"browserify": ">=1.0.0",
|
|
20
|
-
"uglify-js": "1.0.x",
|
|
21
|
-
"grunt": "^0.4.5"
|
|
22
23
|
},
|
|
23
24
|
"keywords": [
|
|
24
25
|
"color",
|
package/test/basic.js
CHANGED
|
@@ -12,9 +12,19 @@ assert.deepEqual(string.getHsla("hsl(240deg, 100%, 50.5%)"), [240, 100, 50.5, 1]
|
|
|
12
12
|
assert.deepEqual(string.getHwb("hwb(240, 100%, 50.5%)"), [240, 100, 50.5, 1]);
|
|
13
13
|
assert.deepEqual(string.getHwb("hwb(240deg, 100%, 50.5%)"), [240, 100, 50.5, 1]);
|
|
14
14
|
|
|
15
|
+
// with sign
|
|
16
|
+
assert.deepEqual(string.getRgba("rgb(-244, +233, -100)"), [0, 233, 0, 1]);
|
|
17
|
+
assert.deepEqual(string.getHsla("hsl(+240, 100%, 50.5%)"), [240, 100, 50.5, 1]);
|
|
18
|
+
assert.deepEqual(string.getRgba("rgba(200, +20, -233, -0.0)"), [200, 20, 0, 0]);
|
|
19
|
+
assert.deepEqual(string.getRgba("rgba(200, +20, -233, -0.0)"), [200, 20, 0, 0]);
|
|
20
|
+
assert.deepEqual(string.getHsla("hsla(+200, 100%, 50%, -0.2)"), [200, 100, 50, 0]);
|
|
21
|
+
assert.deepEqual(string.getHwb("hwb(+240, 100%, 50.5%)"), [240, 100, 50.5, 1]);
|
|
22
|
+
assert.deepEqual(string.getHwb("hwb(-240deg, 100%, 50.5%)"), [0, 100, 50.5, 1]);
|
|
23
|
+
assert.deepEqual(string.getHwb("hwb(-240deg, 100%, 50.5%, +0.6)"), [0, 100, 50.5, 0.6]);
|
|
24
|
+
|
|
15
25
|
//subsequent return values should not change array
|
|
16
26
|
assert.deepEqual(string.getRgba("blue"), [0, 0, 255, 1]);
|
|
17
|
-
assert.deepEqual(string.getRgba("blue"), [0, 0, 255, 1]);
|
|
27
|
+
assert.deepEqual(string.getRgba("blue"), [0, 0, 255, 1]);
|
|
18
28
|
|
|
19
29
|
assert.equal(string.getAlpha("rgb(244, 233, 100)"), 1);
|
|
20
30
|
assert.equal(string.getAlpha("rgba(244, 233, 100, 0.5)"), 0.5);
|
|
@@ -33,6 +43,9 @@ assert.deepEqual(string.getHwb("hwb(200, 20%, 33%, 0.2)"), [200, 20, 33, 0.2]);
|
|
|
33
43
|
assert.deepEqual(string.getRgb("#fef"), [255, 238, 255]);
|
|
34
44
|
assert.deepEqual(string.getRgb("rgba(200, 20, 233, 0.2)"), [200, 20, 233]);
|
|
35
45
|
assert.deepEqual(string.getHsl("hsl(240, 100%, 50.5%)"), [240, 100, 50.5]);
|
|
46
|
+
assert.deepEqual(string.getRgba('rgba(0,0,0,0)'), [0, 0, 0, 0]);
|
|
47
|
+
assert.deepEqual(string.getHsla('hsla(0,0%,0%,0)'), [0, 0, 0, 0]);
|
|
48
|
+
assert.deepEqual(string.getHwb("hwb(400, 10%, 200%, 0)"), [360, 10, 100, 0]);
|
|
36
49
|
|
|
37
50
|
// range
|
|
38
51
|
assert.deepEqual(string.getRgba("rgba(300, 600, 100, 3)"), [255, 255, 100, 1]);
|
package/Gruntfile.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* To run this file:
|
|
3
|
-
* `npm install --dev`
|
|
4
|
-
* `npm install -g grunt`
|
|
5
|
-
*
|
|
6
|
-
* `grunt --help`
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
var fs = require("fs"),
|
|
10
|
-
browserify = require("browserify"),
|
|
11
|
-
pkg = require("./package.json");
|
|
12
|
-
|
|
13
|
-
module.exports = function(grunt) {
|
|
14
|
-
grunt.initConfig({
|
|
15
|
-
pkg: grunt.file.readJSON('package.json'),
|
|
16
|
-
uglify: {
|
|
17
|
-
options: {
|
|
18
|
-
banner: "/*\n" + grunt.file.read('LICENSE') + "\n*/"
|
|
19
|
-
},
|
|
20
|
-
dist: {
|
|
21
|
-
files: {
|
|
22
|
-
'<%=pkg.name%>-<%=pkg.version%>.min.js': ['<%=pkg.name%>-<%=pkg.version%>.js']
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
grunt.registerTask('build', 'build a browser file', function() {
|
|
29
|
-
var done = this.async();
|
|
30
|
-
|
|
31
|
-
var outfile = './color-string-' + pkg.version + '.js';
|
|
32
|
-
|
|
33
|
-
var bundle = browserify('./browser.js').bundle(function(err, src) {
|
|
34
|
-
console.log("> " + outfile);
|
|
35
|
-
// write sync instead of piping to get around event bug
|
|
36
|
-
fs.writeFileSync(outfile, src);
|
|
37
|
-
done();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
grunt.loadNpmTasks('grunt-contrib-uglify');
|
|
42
|
-
};
|
package/browser.js
DELETED
package/component.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "color-string",
|
|
3
|
-
"description": "Parser and generator for CSS color strings",
|
|
4
|
-
"version": "0.1.1",
|
|
5
|
-
"author": "Heather Arthur <fayearthur@gmail.com>",
|
|
6
|
-
"repository": "harthur/color-string",
|
|
7
|
-
"scripts": ["color-string.js"],
|
|
8
|
-
"main": "color-string.js",
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"harthur/color-convert": "*"
|
|
11
|
-
},
|
|
12
|
-
"keywords": ["color", "colour", "rgb", "css"]
|
|
13
|
-
}
|