We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 04b645e commit 070ae0cCopy full SHA for 070ae0c
packages/uui-avatar/lib/uui-avatar.element.ts
@@ -102,13 +102,22 @@ export class UUIAvatarElement extends LitElement {
102
private createInitials(name: string) {
103
let initials = '';
104
105
- if (name) {
106
- const words = name.match(/(\w+)/g) || [];
107
- initials = words[0].substring(0, 1);
108
- if (words.length > 1) {
109
- initials += words[words.length - 1].substring(0, 1);
110
- }
+ if (!name) {
+ return initials;
+ }
+
+ const words = name.match(/(\w+)/g);
111
+ if (!words?.length) {
112
113
}
114
115
+ initials = words[0].substring(0, 1);
116
117
+ if (words.length > 1) {
118
+ initials += words[words.length - 1].substring(0, 1);
119
120
121
return initials.toUpperCase();
122
123
0 commit comments