var a=t=>{try{return new URL(t),!0}catch{return!1}},c=t=>{if(a(t))return t;try{if(t.includes(".")&&!t.includes(" "))return new URL(`https://${t}`).toString()}catch{}return t},u=t=>{if(a(t))return new URL(t);try{if(t.includes(".")&&!t.includes(" "))return new URL(`https://${t}`)}catch{}return null},l=t=>{if(a(t))return t;try{if(t.includes(".")&&!t.includes(" "))return new URL(`https://${t}`).toString()}catch{}return null},p=t=>{let e={};return new URL(t).searchParams.forEach(function(r,n){e[n]=r}),e},m=t=>{let e={};return new URL(t).searchParams.forEach(function(r,n){if(n in e){let s=e[n];Array.isArray(s)?s.push(r):e[n]=[s,r]}else e[n]=r}),e},g=t=>{if(!t)return{};try{let e=new URL(t).searchParams,r={};for(let[n,s]of e.entries())s&&s!==""&&(r[n]=s);return r}catch{return{}}},h=["utm_source","utm_medium","utm_campaign","utm_term","utm_content","ref"],d=(t,e)=>{if(!t)return"";try{let r=new URL(t);for(let[n,s]of Object.entries(e))s?r.searchParams.set(n,s.replace("+"," ")):r.searchParams.delete(n);return r.toString()}catch{return""}},i=[{display:"UTM Source",key:"utm_source",examples:"google, twitter"},{display:"UTM Medium",key:"utm_medium",examples:"social, email"},{display:"UTM Campaign",key:"utm_campaign",examples:"summer sale"},{display:"UTM Term",key:"utm_term",examples:"blue shoes"},{display:"UTM Content",key:"utm_content",examples:"logo link"},{display:"Referral (ref)",key:"ref",examples:"google, twitter"}],U=t=>{try{let e=new URL(t);return i.forEach(r=>e.searchParams.delete(r.key)),e.toString()}catch{return t}},f=t=>t?t.replace(/(^\w+:|^)\/\//,"").replace("www.","").replace(/\/$/,""):"",y=(t,e,r)=>{if(e==="dub.co")return t;let n=new URL(t.startsWith("/")?`https://dub.co${t}`:t);return r&&Object.entries(r).forEach(([s,o])=>{n.searchParams.set(s,o)}),n.toString()},w=t=>{try{let e=new URL(t,"https://dummy-base.local"),r=e.pathname+e.search;return r=r.startsWith("/")?r.slice(1):r,r}catch{return t}},x=t=>{try{let e=new URL(t);return`https://${e.hostname}${e.pathname}`}catch{return t}};function R(t,e){let r=new URL(t,typeof window<"u"?window.location.origin:"http://localhost");return e&&Object.entries(e).forEach(([n,s])=>{s!=null&&s!==""&&r.searchParams.append(n,String(s))}),r.toString()}var L=t=>{var e;try{let n=new URL(t).pathname.split(".").pop();return n?n.toUpperCase():null}catch{let r=(e=t.split(".").pop())==null?void 0:e.split("?")[0];return r?r.toUpperCase():null}};export{a,c as b,u as c,l as d,p as e,m as f,g,h,d as i,i as j,U as k,f as l,y as m,w as n,x as o,R as p,L as q};
