Repository URL to install this package:
Version:
0.2.0a4 ▾
|
dj-kaos-utils
/
string.py
|
---|
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',
)