Live video on the AT Protocol
1import { AppBskyActorDefs } from "@atproto/api";
2
3/**
4 * formats a user's handle for display, falling back to DID if handle is invalid
5 */
6export function formatHandle(
7 profile: Pick<AppBskyActorDefs.ProfileViewBasic, "handle" | "did">,
8 prefix: string = "",
9): string {
10 if (profile.handle === "handle.invalid") {
11 return profile.did;
12 }
13 return prefix + profile.handle;
14}
15
16/**
17 * convenience function for formatting a user's handle with @ prefix for display,
18 * falling back to DID if handle is invalid
19 */
20export function formatHandleWithAt(
21 profile: Pick<AppBskyActorDefs.ProfileViewBasic, "handle" | "did">,
22): string {
23 return formatHandle(profile, "@");
24}