Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ cs.get.rgb = function (string) {
return null;
}

rgb = colorNames[match[1]];
// eslint-disable-next-line unicorn/prefer-spread
rgb = colorNames[match[1]].slice();
rgb[3] = 1;

return rgb;
Expand Down
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ assert.deepEqual(string.get.hwb('hwb(-10.0deg, 100%, 50.5%, +0.6)'), [350, 100,
assert.deepEqual(string.get.rgb('blue'), [0, 0, 255, 1]);
assert.deepEqual(string.get.rgb('blue'), [0, 0, 255, 1]);

// Changing the returned array shouldn't change the array when called with the same named color
{
const col = string.get.rgb('red');
assert.deepEqual(col, [255, 0, 0, 1]);
col[0] = 0;
assert.deepEqual(col, [0, 0, 0, 1]);
assert.deepEqual(string.get.rgb('red'), [255, 0, 0, 1]);
}

// Alpha
assert.deepEqual(normalizeAlpha(string.get.rgb('#fffa')), [255, 255, 255, '0.67']);
assert.deepEqual(string.get.rgb('#c814e933'), [200, 20, 233, 0.2]);
Expand Down