/** Turns what was typed into the address of a Sonda server, or null when it is not one. */ export function normalizeAddress(input) { const text = String(input ?? '').trim() if (text === '') return null const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? text : `https://${text}` let url try { url = new URL(withScheme) } catch { return null } if (url.protocol !== 'https:' && url.protocol !== 'http:') return null if (url.hostname === '') return null // The app lives at the root of the server: a path, a query or a fragment typed by mistake is dropped. return url.origin }