mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
21 lines
497 B
TypeScript
21 lines
497 B
TypeScript
const BAD_CHARACTERS = /[^A-Za-z\s]+/g;
|
|
const WHITESPACE = /\s+/g;
|
|
|
|
function removeNonInitials(name: string) {
|
|
return name.replace(BAD_CHARACTERS, '').replace(WHITESPACE, ' ');
|
|
}
|
|
|
|
export function getInitials(name?: string): string | undefined {
|
|
if (!name) {
|
|
return;
|
|
}
|
|
|
|
const cleaned = removeNonInitials(name);
|
|
const parts = cleaned.split(' ');
|
|
const initials = parts.map(part => part.trim()[0]);
|
|
if (!initials.length) {
|
|
return;
|
|
}
|
|
|
|
return initials.slice(0, 2).join('');
|
|
}
|