@peculiar/color
Version:
Library for color manipulation and conversion in JavaScript.
19 lines • 611 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.hexToRgb = void 0;
/**
* HEX color to RGB color.
* @example
* hexToRgb('#FFCCFF') // => [255,204,255]
*/
function hexToRgb(hex) {
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
var rgb = hex
.replace(shorthandRegex, function (_, r, g, b) { return r + r + g + g + b + b; })
.replace(/^#?/, '')
.match(/.{2}/g)
.map(function (value) { return parseInt(value, 16); });
return [rgb[0], rgb[1], rgb[2]];
}
exports.hexToRgb = hexToRgb;
//# sourceMappingURL=hex_to_rgb.js.map