from typing import Optional


def parse_bool(s: str) -> Optional[bool]:
    """Parse string as boolean.

    Values ``1, ``true``, ``t``, ``yes``, ``y``, ``on`` are parsed as ``True``.
    Values ``0``, ``false``, ``f``, ``no``, ``n``, ``off`` and empty string
    are parsed as ``False``. If none maches, return ``None``. Matching is
    case-insensitive, whitespaces at the beginning and at the end are stripped
    before performing the match.
    """

    s = s.strip().lower()

    if s in {"1", "true", "t", "yes", "y", "on"}:
        return True
    if s in {"0", "false", "f", "no", "n", "off", ""}:
        return False
    return None