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},m=t=>{let e={};return new URL(t).searchParams.forEach(function(r,s){e[s]=r}),e},g=t=>{let e={};return new URL(t).searchParams.forEach(function(r,s){if(s in e){let n=e[s];Array.isArray(n)?n.push(r):e[s]=[n,r]}else e[s]=r}),e},p=t=>{if(!t)return{};try{let e=new URL(t).searchParams,r={};for(let[s,n]of e.entries())n&&n!==""&&(r[s]=n);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[s,n]of Object.entries(e))n?r.searchParams.set(s,n.replace("+"," ")):r.searchParams.delete(s);return r.toString()}catch{return""}},o=[{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"}],f=t=>{try{let e=new URL(t);return o.forEach(r=>e.searchParams.delete(r.key)),e.toString()}catch{return t}},U=t=>t?t.replace(/(^\w+:|^)\/\//,"").replace("www.","").replace(/\/$/,""):"",y=(t,e,r)=>{if(e==="dub.co")return t;let s=new URL(t.startsWith("/")?`https://dub.co${t}`:t);return r&&Object.entries(r).forEach(([n,i])=>{s.searchParams.set(n,i)}),s.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}},R=t=>{try{let e=new URL(t);return`https://${e.hostname}${e.pathname}`}catch{return t}};function x(t,e){let r=new URL(t,typeof window<"u"?window.location.origin:"http://localhost");return e&&Object.entries(e).forEach(([s,n])=>{n!=null&&n!==""&&r.searchParams.append(s,String(n))}),r.toString()}export{a,c as b,u as c,l as d,m as e,g as f,p as g,h,d as i,o as j,f as k,U as l,y as m,w as n,R as o,x as p};
