UNPKG

lib-colors

Version:

Simple node.js library for work with colors

15 lines (14 loc) 444 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.rgbFromHex = rgbFromHex; function rgbFromHex(hex) { hex = hex.replace(/^#/, ''); const r = parseInt(hex.substring(0, 2), 16); const g = parseInt(hex.substring(2, 4), 16); const b = parseInt(hex.substring(4, 6), 16); let a; if (hex.length === 8) { a = parseInt(hex.substring(6, 8), 16) / 255; } return { r, g, b, a }; }