All files / js/composables useInitials.ts

88.88% Statements 8/9
83.33% Branches 5/6
100% Functions 2/2
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  5x   3x   3x 3x   2x       1x    
export function getInitials(fullName?: string): string {
    if (!fullName) return '';
 
    const names = fullName.trim().split(' ');
 
    Iif (names.length === 0) return '';
    if (names.length === 1) return names[0].charAt(0).toUpperCase();
 
    return `${names[0].charAt(0)}${names[names.length - 1].charAt(0)}`.toUpperCase();
}
 
export function useInitials() {
    return { getInitials };
}