Skip to content

Commit c7ceab0

Browse files
committed
[Services] toInitials returns always a string
1 parent d00032d commit c7ceab0

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

packages/eui/src/services/string/to_initials.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* Side Public License, v 1.
77
*/
88

9+
export const MAX_INITIALS = 2;
10+
911
/**
1012
* This function calculates the initials/acronym for a given name.
1113
* It defaults to only 2 characters and will take the first character (of each word).
@@ -17,16 +19,12 @@
1719
* @param {string} name The full name of the item to turn into initials
1820
* @param {number} initialsLength (Optional) How many characters to show (max 2 allowed)
1921
* @param {string} initials (Optional) Custom initials (max 2 characters)
20-
* @returns {string} True if the color is dark, false otherwise.
2122
*/
22-
23-
export const MAX_INITIALS = 2;
24-
2523
export function toInitials(
2624
name: string,
2725
initialsLength?: 1 | 2,
2826
initials?: string
29-
): string | null {
27+
) {
3028
// If `initials` provided, check if it's a single emoji
3129
// in order to support complex, "multi-character" ones
3230
if (initials) {
@@ -71,7 +69,7 @@ export function toInitials(
7169
}
7270
}
7371

74-
return calculatedInitials;
72+
return calculatedInitials || '';
7573
}
7674

7775
function isEmoji(str: string): boolean {

0 commit comments

Comments
 (0)