from typing import Dict
from typing import Optional


def format_name(data: Dict, is_recipe=True) -> Optional[str]:
    """
    Returns recipe 'externalName' if it exists, otherwise returns 'name'.
    Default returns 'name' for non-recipe (ingredient) types if 'name'
    exists. If 'name' doesn't exist, returns None.
    """
    if data.get('externalName') and is_recipe:
        return data['externalName']
    return data.get('name') or None