-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
export function getShortenName(fullName: string) { | ||
const names = fullName.split(' ') | ||
const firstName = names[0] | ||
const lastName = names[names.length - 1] | ||
// TDD By ChatGPT | ||
export function getShortenName(fullName: string): string { | ||
// Remove text inside square brackets (including brackets themselves) | ||
const sanitized = fullName.replace(/\[.*?\]/g, '').trim() | ||
|
||
// Split the sanitized name into parts | ||
const parts = sanitized.split(/\s+/) | ||
|
||
if (parts.length < 2) { | ||
// If there's only one part, return it as is (optional, depending on requirements) | ||
return parts[0] || '' | ||
} | ||
|
||
// Extract first name and last name (or last relevant part) | ||
const firstName = parts[0] | ||
const lastName = parts[parts.length - 1] | ||
|
||
if (firstName === lastName) { | ||
// If first name is the same as last name, return first name only | ||
return firstName | ||
} | ||
|
||
// Return first name and abbreviated last name | ||
return `${firstName} ${lastName.charAt(0)}.` | ||
} |