Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/gedcom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,21 @@ function pointerToId(pointer: string): string {

/** Extracts the first and last name from a GEDCOM name field. */
function extractName(name: string): { firstName?: string; lastName?: string } {
const arr = name.split('/');
if (arr.length === 1) {
return { firstName: arr[0].trim() };
const matches = name.match(/\/([^\/]+)\//);
if (matches) {
const lastName = matches[1].trim();
// Replace the last name part (including slashes) and trim the result
let firstName = name.replace(matches[0], '').trim();
// Replace any occurrence of double spaces with a single space
firstName = firstName.replace(/\s\s+/g, ' ');
return {
firstName: firstName || undefined,
lastName: lastName
};
} else {
// If no last name is found, just return the trimmed and cleaned firstName
return { firstName: name.trim().replace(/\s\s+/g, ' ') };
}
return { firstName: arr[0].trim(), lastName: arr[1].trim() };
}

/** Maps month abbreviations used in GEDCOM to month numbers. */
Expand Down