mirror of
https://github.com/hanzoai/pack.git
synced 2026-09-30 23:43:13 +00:00
18 lines
520 B
TypeScript
18 lines
520 B
TypeScript
import { useCallback } from 'react';
|
|
|
|
export function useInitials() {
|
|
const getInitials = 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();
|
|
}, []);
|
|
|
|
return getInitials;
|
|
}
|