avatar placeholder skip first 05 for initial from pubkey
parent
663654ef2c
commit
e83912e449
@ -1,21 +1,11 @@
|
||||
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) {
|
||||
if (!name || !name.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cleaned = removeNonInitials(name);
|
||||
const parts = cleaned.split(' ');
|
||||
const initials = parts.map(part => part.trim()[0]);
|
||||
if (!initials.length) {
|
||||
return;
|
||||
if (name.length > 2 && name.startsWith('05')) {
|
||||
return name[2];
|
||||
}
|
||||
|
||||
return initials[0];
|
||||
return name[0];
|
||||
}
|
||||
|
Loading…
Reference in New Issue