def METHOD_NAME(
    fg: Optional[str]=None,
    bg: Optional[str]=None,
    bold_for_light_color: bool=False,
) -> str:
    """convert foreground and/or background color in ANSI color codes
    colors can be a color name from the ANSI color palette (e.g. 'dark green'),
    a number between 0 and 255 (still pass them as a string) or an HTML color in
    the style `#00FF00` or `#ABC`
    :param fg: foreground color
    :param bg: background color
    :returns: ANSI color code
    """
    result = ''
    for colorstring, is_bg in ((fg, False), (bg, True)):
        if colorstring:
            color = '\33['
            if colorstring in COLORS:
                # 16 color palette
                if not is_bg:
                    # foreground color
                    c = 30 + COLORS[colorstring].color_index
                    if COLORS[colorstring].light:
                        if bold_for_light_color:
                            color += '1;'
                        else:
                            c += 60
                else:
                    # background color
                    c = 40 + COLORS[colorstring].color_index
                    if COLORS[colorstring].light:
                        if not bold_for_light_color:
                            c += 60
                color += str(c)
            elif colorstring.isdigit():
                # 256 color palette
                if not is_bg:
                    color += '38;5;' + colorstring
                else:
                    color += '48;5;' + colorstring
            else:
                # HTML-style 24-bit color
                if len(colorstring) == 4:
                    # e.g. #ABC, equivalent to #AABBCC
                    r = int(colorstring[1] * 2, 16)
                    g = int(colorstring[2] * 2, 16)
                    b = int(colorstring[3] * 2, 16)
                else:
                    # e.g. #AABBCC
                    r = int(colorstring[1:3], 16)
                    g = int(colorstring[3:5], 16)
                    b = int(colorstring[5:7], 16)
                if not is_bg:
                    color += f'38;2;{r!s};{g!s};{b!s}'
                else:
                    color += f'48;2;{r!s};{g!s};{b!s}'
            color += 'm'
            result += color
    return result