var o=e=>{try{return new URL(e),!0}catch{return!1}},i=(e,{returnNullIfInvalid:r=!1}={})=>{if(o(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{}return r?null:e},m=e=>{let r={};return new URL(e).searchParams.forEach(function(t,n){r[n]=t}),r},u=e=>{let r={};return new URL(e).searchParams.forEach(function(t,n){if(n in r){let s=r[n];Array.isArray(s)?s.push(t):r[n]=[s,t]}else r[n]=t}),r},l=e=>{if(!e)return{};try{let r=new URL(e).searchParams,t={};for(let[n,s]of r.entries())s&&s!==""&&(t[n]=s);return t}catch{return{}}},p=["utm_source","utm_medium","utm_campaign","utm_term","utm_content","ref"],g=(e,r)=>{if(!e)return"";try{let t=new URL(e);for(let[n,s]of Object.entries(r))s===""?t.searchParams.delete(n):t.searchParams.set(n,s);return t.toString()}catch{return""}},c=[{display:"UTM Source",key:"utm_source",examples:"twitter, facebook"},{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:"logolink"},{display:"Referral (ref)",key:"ref",examples:"twitter, facebook"}],f=e=>{try{let r=new URL(e);return c.forEach(t=>r.searchParams.delete(t.key)),r.toString()}catch{return e}},U=e=>e?e.replace(/(^\w+:|^)\/\//,"").replace("www.","").replace(/\/$/,""):"",d=(e,r,t)=>{if(r==="dub.co")return e;let n=new URL(e.startsWith("/")?`https://dub.co${e}`:e);return t&&Object.entries(t).forEach(([s,a])=>{n.searchParams.set(s,a)}),n.toString()};export{o as a,i as b,m as c,u as d,l as e,p as f,g,c as h,f as i,U as j,d as k};
