"""Shared formatting utilities."""


def human_size(size_bytes: float) -> str:
    """Convert bytes to human-readable size string.

    Args:
        size_bytes: Size in bytes.

    Returns:
        Human-readable string like "247.0 MB" or "1.5 GB".
    """
    for unit in ("B", "KB", "MB", "GB"):
        if abs(size_bytes) < 1024:
            return f"{size_bytes:.1f} {unit}"
        size_bytes /= 1024
    return f"{size_bytes:.1f} TB"
