Files
test_polis/laravel/resources/js/hooks/use-initials.tsx
2026-02-04 23:23:42 +07:00

18 lines
556 B
TypeScript

import { useCallback } from 'react';
export type GetInitialsFn = (fullName: string) => string;
export function useInitials(): GetInitialsFn {
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();
}, []);
}