fix: garbled text displayed on avatars (#6575)

Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
maruric 2023-05-14 02:49:09 +09:00 committed by GitHub
parent e0f2869374
commit 306e133651
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 28 deletions

View file

@ -20,9 +20,13 @@ export const getClientColors = (clientId: string, appState: AppState) => {
};
};
export const getClientInitials = (userName?: string | null) => {
if (!userName?.trim()) {
return "?";
}
return userName.trim()[0].toUpperCase();
/**
* returns first char, capitalized
*/
export const getNameInitial = (name?: string | null) => {
// first char can be a surrogate pair, hence using codePointAt
const firstCodePoint = name?.trim()?.codePointAt(0);
return (
firstCodePoint ? String.fromCodePoint(firstCodePoint) : "?"
).toUpperCase();
};