url-utils.ts
1 export const getHostname = (url: string) => { 2 try { 3 return new URL(url).hostname.replace(/^www\./, ''); 4 } catch (e) { 5 return ''; 6 } 7 }; 8 9 export const isValidURL = (url: string) => { 10 try { 11 new URL(url); 12 return true; 13 } catch { 14 return false; 15 } 16 }; 17 18 export const copyShareLinkToClipboard = (subplebbitAddress: string, cid: string) => { 19 const shareLink = `https://pleb.bz/p/${subplebbitAddress}/c/${cid}?redirect=plebchan.eth.limo`; 20 21 if (navigator.clipboard) { 22 navigator.clipboard.writeText(shareLink); 23 } else { 24 alert('Your browser does not support clipboard API'); 25 } 26 };