/** The code in an invite link (`…/go?community=CODE`), or a bare code. */ export function inviteCode(input: string): string | null { const text = input.trim() let code = text if (/^[a-z]+:\/\//i.test(text)) { try { code = new URL(text).searchParams.get('community') ?? '' } catch { return null } } return /^[A-Za-z0-9]{1,64}$/.test(code) ? code : null } /** * The link that opens an invite, in the app on a phone that has it and here * otherwise: on this page's own server, whose `/go` opens the invite (the * viewer on cartopolis.org, this page on a server of one's own), as the app's * `place_link::invite_link` names the server it is signed in to. */ export function inviteLink(code: string, origin = location.origin): string { return `${origin}/go?community=${code}` }