Skip to content

Commit ac30311

Browse files
jwilssonshellscape
authored andcommitted
Word.isColor should handle RGBA hex colors. Closes #32 (#33)
1 parent 5e35136 commit ac30311

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ module.exports = class Parser {
463463

464464
if (node.constructor.name === 'Word') {
465465
node.isHex = /^#(.+)/.test(value);
466-
node.isColor = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(value);
466+
node.isColor = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(value);
467467
}
468468
else {
469469
this.cache.push(this.current);

test/word.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ describe('Parser → Word', () => {
6767
expected: [
6868
{ type: 'word', value: '-webkit-transition' }
6969
]
70+
},
71+
{
72+
it: 'should parse hex colors',
73+
test: '#123 #abcdef #a2b3c4d5',
74+
expected: [
75+
{ type: 'word', value: '#123', isHex: true, isColor: true },
76+
{ type: 'word', value: '#abcdef', isHex: true, isColor: true },
77+
{ type: 'word', value: '#a2b3c4d5', isHex: true, isColor: true }
78+
]
7079
}
7180
];
7281

0 commit comments

Comments
 (0)