Skip to content

Commit f21367f

Browse files
committed
Add very basic RGB/RGBA color parsing support
1 parent feeda41 commit f21367f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,19 @@ Parser.prototype.string = function(){
9292
return this.single() || this.double();
9393
};
9494

95+
Parser.prototype.color = function(){
96+
var m = /^(rgba?\([^)]*\)) */.exec(this.str);
97+
if (!m) return m;
98+
this.skip(m);
99+
return {
100+
type: 'color',
101+
value: m[1]
102+
}
103+
};
95104

96105
Parser.prototype.value = function(){
97106
return this.number()
107+
|| this.color()
98108
|| this.ident()
99109
|| this.string()
100110
|| this.comma();

test/cases/colors.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
exports.string = 'rgba(1,2,3,4) rgb(9,8,7)';
2+
3+
exports.object = [
4+
{ type: 'color', value: 'rgba(1,2,3,4)' },
5+
{ type: 'color', value: 'rgb(9,8,7)' }
6+
];

0 commit comments

Comments
 (0)