Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add very basic RGB/RGBA color parsing support
  • Loading branch information
jhartikainen committed Jun 17, 2015
commit f21367fa016ec8d34b400d57e178d175b5d9b9e2
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,19 @@ Parser.prototype.string = function(){
return this.single() || this.double();
};

Parser.prototype.color = function(){
var m = /^(rgba?\([^)]*\)) */.exec(this.str);
if (!m) return m;
this.skip(m);
return {
type: 'color',
value: m[1]
}
};

Parser.prototype.value = function(){
return this.number()
|| this.color()
|| this.ident()
|| this.string()
|| this.comma();
Expand Down
6 changes: 6 additions & 0 deletions test/cases/colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exports.string = 'rgba(1,2,3,4) rgb(9,8,7)';

exports.object = [
{ type: 'color', value: 'rgba(1,2,3,4)' },
{ type: 'color', value: 'rgb(9,8,7)' }
];