Function hexToRgb

  • Converts a hexadecimal color code to an RGB or RGBA color string.

    Parameters

    • hex: string

      The hexadecimal color code to convert.

    Returns string

    The RGB or RGBA color string.

    Example

    console.log(hexToRgb('#ff0000')); // 'rgb(255, 0, 0)'
    console.log(hexToRgb('#ff000080')); // 'rgba(255, 0, 0, 0.5)'