Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix name extraction #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Loading