Skip to content

Instantly share code, notes, and snippets.

View thybzi's full-sized avatar

Evgeni Dmitriev thybzi

View GitHub Profile
/**
* Convert #1a2b3c to { h: 210, g: 40, b: 17 }
* @param {string} hex
* @returns {*}
* @see https://stackoverflow.com/q/46432335/3027390
* @see https://stackoverflow.com/a/46432866/3027390
*/
function hexToHsl(hex) {
const rgb = _f.hexToRgb(hex);
const r = rgb.r / 255;
/**
* Convert #1a2b3c to { r: 26, g: 43, b: 60 }
* @param {string} hex
* @returns {*}
* @see https://stackoverflow.com/a/5624139
*/
function hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {