Files
wehub-resource-sync 98e40dac97
CLI Smoke Test / smoke-test-linux (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-linux (24) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (24) (push) Has been cancelled
Expo App TypeScript typecheck / typecheck (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:40:49 +08:00

27 lines
671 B
TypeScript

interface NameParts {
firstName: string | null;
lastName: string | null;
}
export function separateName(fullName: string | null | undefined): NameParts {
if (!fullName || typeof fullName !== 'string') {
return { firstName: null, lastName: null };
}
const trimmedName = fullName.trim();
if (!trimmedName) {
return { firstName: null, lastName: null };
}
const parts = trimmedName.split(/\s+/);
if (parts.length === 1) {
return { firstName: parts[0], lastName: null };
}
const firstName = parts[0];
const lastName = parts.slice(1).join(' ');
return { firstName, lastName };
}