mirror of
https://github.com/vitodeploy/vito.git
synced 2025-05-14 03:53:35 +00:00
16 lines
454 B
TypeScript
16 lines
454 B
TypeScript
import { useCallback } from 'react';
|
|
|
|
export function useInitials() {
|
|
return useCallback((fullName: string): string => {
|
|
const names = fullName.trim().split(' ');
|
|
|
|
if (names.length === 0) return '';
|
|
if (names.length === 1) return names[0].charAt(0).toUpperCase();
|
|
|
|
const firstInitial = names[0].charAt(0);
|
|
const lastInitial = names[names.length - 1].charAt(0);
|
|
|
|
return `${firstInitial}${lastInitial}`.toUpperCase();
|
|
}, []);
|
|
}
|