UNPKG

niram

Version:

A javascript library to convert between various css colour formats.

13 lines (12 loc) 526 B
import { getAlphaHexFromFraction } from './helpers/hex.js'; import { getRgbHexAndAlpha } from './helpers/getColour.js'; export function colourToDecimal(colour) { if (!colour) { return; } if (!isNaN(Number(colour))) { return Number(colour); } const { type, redHex, greenHex, blueHex, alphaFraction, alphaHex } = getRgbHexAndAlpha(colour); return Number(`0x${redHex}${greenHex}${blueHex}${alphaHex !== null && alphaHex !== void 0 ? alphaHex : getAlphaHexFromFraction(alphaFraction)}`); }