AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

use-initials.tsx 715B

1234567891011121314151617181920212223242526
  1. import { useCallback } from 'react';
  2. export type GetInitialsFn = (fullName: string) => string;
  3. function getInitial(name: string): string {
  4. return Array.from(name)[0] ?? '';
  5. }
  6. export function useInitials(): GetInitialsFn {
  7. return useCallback((fullName: string): string => {
  8. const names = fullName.trim().split(/\s+/u).filter(Boolean);
  9. if (names.length === 0) {
  10. return '';
  11. }
  12. if (names.length === 1) {
  13. return getInitial(names[0]).toUpperCase();
  14. }
  15. const firstInitial = getInitial(names[0]);
  16. const lastInitial = getInitial(names[names.length - 1]);
  17. return `${firstInitial}${lastInitial}`.toUpperCase();
  18. }, []);
  19. }