@workday/canvas-kit-preview-react
Version:
Canvas Kit Preview is made up of components that have the full design and a11y review, are part of the DS ecosystem and are approved for use in product. The API's could be subject to change, but not without strong communication and migration strategies.
12 lines (9 loc) • 414 B
text/typescript
export const getInitialsFromName = (name: string) => {
// Trim and split by one or more whitespace characters
const nameParts = name.trim().split(/\s+/).filter(Boolean);
const first = nameParts[0];
const firstInitial = first?.[0] || '';
const last = nameParts.length > 1 ? nameParts[nameParts.length - 1] : undefined;
const lastInitial = last?.[0] || '';
return `${firstInitial}${lastInitial}`;
};