export type BioSegment = { kind: "text"; text: string } | { kind: "mention"; handle: string }; const MENTION = /(? { const segments: BioSegment[] = []; let last = 0; for (const match of text.matchAll(MENTION)) { if (match.index > last) segments.push({ kind: "text", text: text.slice(last, match.index) }); segments.push({ kind: "mention", handle: match[1].toLowerCase() }); last = match.index + match[0].length; } if (last < text.length) segments.push({ kind: "text", text: text.slice(last) }); return segments; };