Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
dj-kaos-utils / string.py
Size: Mime:
import re


def create_initials(s: str) -> str:
    """
    Return the initial letter of each word in `s`, capitalized and strung together

    Example:
        >>> create_initials("John Smith") == "JS"

    :param s: String to create initials out of
    :return: Initials of `s`, capitalized
    """
    return "".join(s[0] if s else '' for s in re.split(r"[\W_]+", s)).upper()


def snake_case_into_class_case(s: str):
    return ''.join(word[0].upper() + word[1:] for word in s.split('_'))


def remove_suffix(text, suffix):
    if text.endswith(suffix):
        return text[:-len(suffix)]
    return text


__all__ = (
    'create_initials',
    'snake_case_into_class_case',
    'remove_suffix',
)