HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/node_modules/vue3-spinners/utils/rgba.js
import toHex from 'colornames';
export const calculateRgba = (input, opacity) => {
    let color = '';
    const colorNameHex = toHex(input);
    if (colorNameHex !== undefined) {
        // Remove the leading '#'
        color = colorNameHex.slice(1);
    }
    else if (input.startsWith(`#`)) {
        color = input.slice(1);
    }
    if (color.length === 3) {
        let res = '';
        for (const c of color) {
            res += c;
            res += c;
        }
        color = res;
    }
    const rgbParts = color.match(/.{2}/g);
    if (rgbParts === null) {
        throw new Error(`Could not identify RGB value of color \`${input}\``);
    }
    const rgbValues = rgbParts.map((hex) => Number.parseInt(hex, 16)).join(`, `);
    return `rgba(${rgbValues}, ${opacity})`;
};