You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
884 B
TypeScript
36 lines
884 B
TypeScript
export function getInitials(name?: string): string {
|
|
if (!name || !name.length) {
|
|
return '0';
|
|
}
|
|
|
|
if (name.length > 2 && name.startsWith('05')) {
|
|
// Just the third char of the pubkey when the name is a pubkey
|
|
return upperAndShorten(name[2]);
|
|
}
|
|
|
|
if (name.indexOf(' ') === -1) {
|
|
// there is no space, just return the first 2 chars of the name
|
|
|
|
if (name.length > 1) {
|
|
return upperAndShorten(name.slice(0, 2));
|
|
}
|
|
return upperAndShorten(name[0]);
|
|
}
|
|
|
|
// name has a space, just extract the first char of each words
|
|
return upperAndShorten(
|
|
name
|
|
.split(' ')
|
|
.slice(0, 2)
|
|
.map(n => {
|
|
return n[0];
|
|
})
|
|
.join('')
|
|
);
|
|
}
|
|
|
|
function upperAndShorten(str: string) {
|
|
// believe it or not, some chars put in uppercase can be more than one char. (ß for instance)
|
|
return str.toLocaleUpperCase().slice(0, 2);
|
|
}
|