Sifa professional network frontend (Next.js, React, TailwindCSS) sifa.id/
at main 32 lines 999 B view raw
1/** 2 * Sanitize raw user input into a valid AT Protocol identifier (handle or DID). 3 * 4 * Handles common mistakes: 5 * - Pasting a full Bluesky profile URL 6 * - Pasting a raw HTTPS URL to a PDS domain 7 * - Using an at:// URI 8 * - Prefixing with @ 9 * - Entering a bare username without .bsky.social 10 */ 11export function sanitizeHandleInput(raw: string): string { 12 let identifier = raw 13 .trim() 14 .replace(/^https?:\/\/bsky\.app\/profile\//i, '') 15 .replace(/^at:\/\//i, '') 16 .replace(/^@/, '') 17 .replace(/^https?:\/\//i, ''); 18 if (!identifier.startsWith('did:')) { 19 identifier = identifier.split('/')[0] ?? identifier; 20 } 21 identifier = identifier.replace(/\.$/, ''); 22 if (!identifier.startsWith('did:')) { 23 identifier = identifier.toLowerCase(); 24 } 25 26 // Auto-append .bsky.social for bare usernames (no dots, not a DID) 27 if (identifier && !identifier.startsWith('did:') && !identifier.includes('.')) { 28 identifier = `${identifier}.bsky.social`; 29 } 30 31 return identifier; 32}