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 {
|
export function getInitials(name?: string): string | undefined {
|
||||||
if (!name) {
|
if (!name || !name.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleaned = removeNonInitials(name);
|
if (name.length > 2 && name.startsWith('05')) {
|
||||||
const parts = cleaned.split(' ');
|
return name[2];
|
||||||
const initials = parts.map(part => part.trim()[0]);
|
|
||||||
if (!initials.length) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return initials[0];
|
return name[0];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue