Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Avatar): add fallback workaround to graphemer import class #1745

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ export interface Props {
*/
variant?: 'icon' | 'initials' | 'image';
}

/**
* Use graphemer to take a name part, and select the first grapheme (emoji, surrogate pair, ASCII character)
*/
function produceAbbreviation(fromName: string): string {
const splitter = new Graphemer();
// @see https://github.com/flmnt/graphemer/issues/11
// @ts-expect-error handles case where this library adds .default to the export inappropriately in CJS context
const G = Graphemer['default'] ? Graphemer.default : Graphemer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: might be able to use in and avoid the TS error

Suggested change
const G = Graphemer['default'] ? Graphemer.default : Graphemer;
const G = 'default' in Graphemer ? Graphemer.default : Graphemer;

Although I can't imagine any of this makes TS happy 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript HATES this one simple trick

😅

const splitter = new G();
return fromName ? splitter.splitGraphemes(fromName)[0] : '?';
}

Expand Down