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:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/core-components': patch
|
||||
---
|
||||
|
||||
Parse unicode characters in name for avatar component
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user