Skip to content

Documentation / @andrew_l/toolkit / getInitials

Function: getInitials()

getInitials(fullName): string

Extracts the initials from a full name while ignoring titles or prefixes (e.g., Dr., Mr., Mrs.), as well as any words starting with special characters (e.g., !, @, #). Handles names with multiple words, ignores special characters, and ensures proper handling of Unicode characters.

Parameters

fullName: string

The full name from which to extract initials.

Returns

string

  • The extracted initials in uppercase, or an empty string if the input is invalid.

Examples

ts
getInitials("John Doe");
// Returns: "JD"
ts
getInitials("Dr. Alice Wonderland");
// Returns: "AW"
ts
getInitials("José María de la Cruz");
// Returns: "JC"
ts
getInitials("Mr. Albert Einstein");
// Returns: "AE"
ts
getInitials("Invalid Name");
// Returns: "IN"
ts
getInitials("");
// Returns: ""