Live video on the AT Protocol

Introduce a helper function to format handle

+22
+22
js/components/src/utils/format-handle.ts
··· 1 + import { AppBskyActorDefs } from "@atproto/api"; 2 + 3 + /** 4 + * formats a user's handle for display, falling back to DID if handle is invalid 5 + */ 6 + export function formatHandle( 7 + profile: Pick<AppBskyActorDefs.ProfileViewBasic, "handle" | "did">, 8 + ): string { 9 + if (profile.handle === "handle.invalid") { 10 + return profile.did; 11 + } 12 + return profile.handle; 13 + } 14 + 15 + /** 16 + * formats a user's handle with @ prefix for display, falling back to DID if handle is invalid 17 + */ 18 + export function formatHandleWithAt( 19 + profile: Pick<AppBskyActorDefs.ProfileViewBasic, "handle" | "did">, 20 + ): string { 21 + return `@${formatHandle(profile)}`; 22 + }