Name
Format person names with various display options.
formatName
Formats a person's name with various display options including full name, initials, and abbreviated forms. Supports camelCase, snake_case, and a simple name string property.
import { formatName } from "@tilt-legal/cubitt-components/utilities/formatters";
formatName({ firstName: "John", lastName: "Doe" }); // "John Doe"
formatName({ first_name: "John", last_name: "Doe" }); // "John Doe"
formatName({ name: "John Doe" }); // "John Doe"
formatName(null); // "Unknown"| Property | Type | Default | Description |
|---|---|---|---|
format | NameFormat | "full" | Display format for the name |
includeMiddle | boolean | false | Include middle name in output |
fallback | string | "Unknown" | String to return when no name available |
Available formats
| Format | Example Output | Description |
|---|---|---|
full | "John Doe" | First and last name |
first | "John" | First name only |
last | "Doe" | Last name only |
lastFirst | "Doe, John" | Last name, first name |
initials | "JD" | Initials only |
firstInitial | "John D." | First name + last initial |
lastInitial | "J. Doe" | First initial + last name |
const name = { firstName: "John", lastName: "Doe" };
formatName(name, { format: "full" }); // "John Doe"
formatName(name, { format: "lastFirst" }); // "Doe, John"
formatName(name, { format: "initials" }); // "JD"
formatName(name, { format: "firstInitial" }); // "John D."
formatName(name, { format: "lastInitial" }); // "J. Doe"With middle name
const name = { firstName: "John", middleName: "Robert", lastName: "Doe" };
formatName(name); // "John Doe"
formatName(name, { includeMiddle: true }); // "John Robert Doe"
formatName(name, { format: "initials", includeMiddle: true }); // "JRD"getInitials
Convenience function that returns initials from a name object.
import { getInitials } from "@tilt-legal/cubitt-components/utilities/formatters";
getInitials({ firstName: "John", lastName: "Doe" }); // "JD"
getInitials({ first_name: "Jane" }); // "J"
getInitials(null); // "?"| Property | Type | Default | Description |
|---|---|---|---|
includeMiddle | boolean | false | Include middle name initial |
fallback | string | "?" | String to return for no name |