ISC License
from pyinitials import initials
print(initials('Guido van Rossum')) # prints "GvR"
This project is a Python clone of the JavaScript initials package.
Install from PyPi, for example with Poetry:
poetry add pyinitials
from pyinitials import initials, find, parse, add_to
initials('John Doe') # 'JD'
initials(['John Doe', 'Robert Roe']) # ['JD', 'RR']
# alias for initials('John Doe')
find('John Doe') # 'JD'
parse('John Doe') # Parts(name='John Doe', initials='JD', email=None)
# add initials to name(s)
add_to('John Doe') # 'John Doe (JD)'
# Pass existing initials for names
initials(['John Doe', 'Jane Dane'], existing={'John Doe': 'JD'}) # ['JD', 'JDa']
Preffered initials can be passed in (JD)
, e.g.
initials('John Doe (JoDo)') # 'JoDo'
If a name contains an email, it gets ignored when calculating initials
initials('John Doe [email protected]') # 'JD'
If a name is an email, the domain part gets ignored
initials('[email protected]') # 'jo'
When passing an Array of names, duplicates of initials are avoided
initials(['John Doe', 'Jane Dane']) # ['JDo', 'JDa']
Install dependencies:
poetry install
Run the unit-tests:
poetry run pytest