fix(avatar): Parse unicode characters in name for avatar component

Signed-off-by: Marek Šneberger <marek@sneberger.cz>
This commit is contained in:
Marek Šneberger
2023-07-12 10:33:33 +02:00
parent ba3b7d1782
commit 4722c948c2
4 changed files with 14 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/core-components': patch
---
Parse unicode characters in name for avatar component
+1
View File
@@ -402,6 +402,7 @@ Uffizzi
ui
unbreak
Unconference
unicode
unmanaged
unregister
unregistering
@@ -27,6 +27,10 @@ describe('extractInitials', () => {
expect(extractInitials('Jenny Doe')).toEqual('JD');
});
it('extract unicode initials', async () => {
expect(extractInitials('Petr Čech')).toEqual('PČ');
});
it('extract single letter for short name', async () => {
expect(extractInitials('Doe')).toEqual('D');
});
@@ -28,5 +28,8 @@ export function stringToColor(str: string) {
}
export function extractInitials(value: string) {
return value.match(/\b\w/g)?.join('').slice(0, 2);
return value
.match(/(?<!\p{L})\p{L}/gu)
?.join('')
.slice(0, 2);
}