import unicodedata


def normalize(s, allow_nonascii=True):
    """Applies Unicode normalization and optionally strips all non-ASCII characters."""
    if (allow_nonascii):
        return unicodedata.normalize('NFKC', s)
    else:
        return unicodedata.normalize('NFKD', s).encode('ascii', 'ignore').decode('ascii')