Skip to content

Commit 7e2f2f1

Browse files
committed
Fixes alpha for formatter('rgb')('<hexcode>')
1 parent aa637b1 commit 7e2f2f1

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/formatter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export default (format = 'rgb') => c => {
2323
}
2424

2525
if (format === 'rgb') {
26-
if (c.alpha === undefined || c.alpha === 1) {
26+
if (color.alpha === undefined || color.alpha === 1) {
2727
// opaque color
2828
return `rgb(${r}, ${g}, ${b})`;
2929
} else {
3030
// transparent color
31-
return `rgba(${r}, ${g}, ${b}, ${roundAlpha(c.alpha)})`;
31+
return `rgba(${r}, ${g}, ${b}, ${roundAlpha(color.alpha)})`;
3232
}
3333
}
3434
};

test/formatter.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
let tape = require('tape');
2+
let culori = require('../');
3+
4+
tape('formatter(hex)', function(test) {
5+
let hex = culori.formatter('hex');
6+
7+
test.equal(hex('tomato'), '#ff6347');
8+
9+
test.end();
10+
});
11+
12+
tape('formatter(rgb)', function(test) {
13+
let rgb = culori.formatter('rgb');
14+
15+
test.equal(rgb(culori.rgb('#f0f0f0f0')), 'rgba(240, 240, 240, 0.94)');
16+
test.equal(rgb('#f0f0f0f0'), 'rgba(240, 240, 240, 0.94)');
17+
18+
test.end();
19+
});

0 commit comments

Comments
 (0)