def custom_format_color(color_value, color_format, alone_when_single):
    """Return color value converted to specified format.

    Parameters
    ==========
    color_value (string or tuple)
        a value representing a color or multiple colors,
        as accepted by the get_custom_color_format_info
        function.
    color_format (string)
        either 'rgb_tuple' or 'hex_string';
        indicates whether individual colors are represented
        by tuples or strings.
    alone_when_single (bool)
        whether an individual color must appear alone
        rather than within a tuple of length 1 when
        it is the only color represented by the color
        value.
    """
    ### retrieve the current format name and length of
    ### color value

    format_name, length = get_custom_color_format_info(color_value)

    ### make it so the color value is treated as multiple
    ### color values if it represents a single color
    if "single" in format_name:
        color_value = (color_value,)

    ### if the requested color format is rgb integers but
    ### the format name indicates the colors are represented
    ### by hex strings, convert each item from hex strings
    ### to rgb(a) colors

    if color_format == "rgb_tuple" and "hex" in format_name:

        color_value = tuple(hex_string_to_full_rgb(item) for item in color_value)

    ### if, otherwise, the requested color format is hex
    ### string, but the format name indicates the colors are
    ### represented by rgb(a) colors (tuples), convert each
    ### string into its respective tuple of rgb(a) values

    elif color_format == "hex_string" and "rgb" in format_name:

        color_value = tuple(full_rgb_to_hex_string(item) for item in color_value)

    ### if the color value represents a single color and
    ### it was requested that the color itself is used when
    ### alone, replace the color value by the single value
    ### it contains

    if length == 1 and alone_when_single:
        color_value = color_value[0]

    ### finally return the color value
    return color_value
Return color value converted to specified format.

    Parameters
    ==========
    color_value (string or tuple)
        a value representing a color or multiple colors,
        as accepted by the get_custom_color_format_info
        function.
    color_format (string)
        either 'rgb_tuple' or 'hex_string';
        indicates whether individual colors are represented
        by tuples or strings.
    alone_when_single (bool)
        whether an individual color must appear alone
        rather than within a tuple of length 1 when
        it is the only color represented by the color
        value.
    
nodezator/ourstdlibs/color/custom.py