Skip to content

Commit

Permalink
feat: add alpha support to getHex
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnsgn committed Feb 25, 2022
1 parent 6523d53 commit ff3cc3c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,16 @@ export function setHex(color, hex) {
* @return {hex}
*/
export function getHex(color) {
const c = [color[0], color[1], color[2]].map((val) => {
return Math.floor(val * 255);
});
const c = color.map((val) => Math.round(val * 255));

return `#${(c[2] | (c[1] << 8) | (c[0] << 16) | (1 << 24))
.toString(16)
.slice(1)
.toUpperCase()}`;
.toUpperCase()}${
color[3] !== undefined && color[3] !== 1
? (c[3] | (1 << 8)).toString(16).slice(1)
: ""
}`;
}

// XYZ
Expand Down

0 comments on commit ff3cc3c

Please sign in to comment.