def largest_component(G: nx.MultiDiGraph, *, strongly: bool = False) -> nx.MultiDiGraph:
    """
    Return `G`'s largest weakly or strongly connected component as a graph.

    Parameters
    ----------
    G
        Input graph.
    strongly
        If True, return the largest strongly connected component. Otherwise
        return the largest weakly connected component.

    Returns
    -------
    G
        The largest connected component subgraph of the original graph.
    """
    if strongly:
        kind = "strongly"
        is_connected = nx.is_strongly_connected
        connected_components = nx.strongly_connected_components
    else:
        kind = "weakly"
        is_connected = nx.is_weakly_connected
        connected_components = nx.weakly_connected_components

    if not is_connected(G):
        # get all the connected components in graph then identify the largest
        largest_cc = max(connected_components(G), key=len)
        n = len(G)

        # induce (frozen) subgraph then unfreeze it by making new MultiDiGraph
        G = nx.MultiDiGraph(G.subgraph(largest_cc))

        msg = f"Got largest {kind} connected component ({len(G):,} of {n:,} total nodes)"
        utils.log(msg, level=lg.INFO)

    return G

    Return `G`'s largest weakly or strongly connected component as a graph.

    Parameters
    ----------
    G
        Input graph.
    strongly
        If True, return the largest strongly connected component. Otherwise
        return the largest weakly connected component.

    Returns
    -------
    G
        The largest connected component subgraph of the original graph.
    
osmnx/truncate.py