fix(Avatar): Fix initials when avatar contains multiple special characters

This commit is contained in:
Vlad Piersec 2021-11-26 10:14:20 +02:00 committed by vp8x8
parent f620d101ba
commit 35b76a2f7c
1 changed files with 2 additions and 2 deletions

View File

@ -16,7 +16,7 @@ const AVATAR_COLORS = [
'#2AA076',
'#00A8B3'
];
const wordSplitRegex = (/\s+|\.+|_+|;+|-+|,+|\|+|\/+|\\+/);
const wordSplitRegex = (/\s+|\.+|_+|;+|-+|,+|\|+|\/+|\\+|"+|'+|\(+|\)+|#+|&+/);
const splitter = new GraphemeSplitter();
/**
@ -68,7 +68,7 @@ function getFirstGraphemeUpper(word) {
export function getInitials(s: ?string) {
// We don't want to use the domain part of an email address, if it is one
const initialsBasis = _.split(s, '@')[0];
const [ firstWord, secondWord ] = initialsBasis.split(wordSplitRegex);
const [ firstWord, secondWord ] = initialsBasis.split(wordSplitRegex).filter(Boolean);
return getFirstGraphemeUpper(firstWord) + getFirstGraphemeUpper(secondWord);
}