Full name or phrase to abbreviate; punctuation is stripped and whitespace collapsed.
maxLetters (default 2) and optional locale for grapheme segmentation and casing.
Uppercased initials via Intl.Segmenter when available; "?" for empty input after cleaning.
formatInitials("John Doe"); // "JD"
formatInitials("John Henry Doe"); // "JD" (first + last word when maxLetters is 2)
formatInitials("John Henry Doe", { maxLetters: 3 }); // "JHD"
formatInitials("John Ronald Reuel Tolkien"); // "JT"
formatInitials("John Ronald Reuel Tolkien", { maxLetters: 3 }); // "JRR"
formatInitials("Élodie Durand"); // "ÉD"
formatInitials("ilker", { locale: "tr" }); // "İL"
formatInitials("李小龍"); // "李小"
formatInitials(""); // "?"
Builds initials from a name using Unicode-aware grapheme segmentation.
Defaults to
maxLetters = 2. Returns"?"for empty or whitespace-only input. Throws whenmaxLettersis not finite or is less than1.