function getQueryString(e){let t;try{t=new URL(e,"http://example.com").search.substring(1)}catch(e){}if(t)return t}function buildQueryString(e){let t="";const r=Object.entries(e);let n;for(;n=r.shift();){let[e,s]=n;if(Array.isArray(s)||s&&s.constructor===Object){const t=Object.entries(s).reverse();for(const[n,s]of t)r.unshift([`${e}[${n}]`,s])}else void 0!==s&&(null===s&&(s=""),t+="&"+[e,s].map(encodeURIComponent).join("="))}return t.substr(1)}function safeDecodeURIComponent(e){try{return decodeURIComponent(e)}catch(t){return e}}function setPath(e,t,r){const n=t.length,s=n-1;for(let o=0;o<n;o++){let n=t[o];!n&&Array.isArray(e)&&(n=e.length.toString()),n=["__proto__","constructor","prototype"].includes(n)?n.toUpperCase():n;const c=!isNaN(Number(t[o+1]));e[n]=o===s?r:e[n]||(c?[]:{}),Array.isArray(e[n])&&!c&&(e[n]={...e[n]}),e=e[n]}}function getQueryArgs(e){return(getQueryString(e)||"").replace(/\+/g,"%20").split("&").reduce(((e,t)=>{const[r,n=""]=t.split("=").filter(Boolean).map(safeDecodeURIComponent);return r&&setPath(e,r.replace(/\]/g,"").split("["),n),e}),Object.create(null))}function addQueryArgs(e="",t){if(!t||!Object.keys(t).length)return e;let r=e;const n=e.indexOf("?");return-1!==n&&(t=Object.assign(getQueryArgs(e),t),r=r.substr(0,n)),r+"?"+buildQueryString(t)}export{addQueryArgs as a,buildQueryString as b,getQueryArgs as g};