Merge pull request #18638 from legendik/fix/unicode_avatar_name

fix(avatar): Parse unicode characters in name for avatar component
This commit is contained in:
Ben Lambert
2023-07-12 13:33:00 +02:00
committed by GitHub
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);
}