import{tryDecodeURIComponent as d}from"./string.js";class f{parse(n){const e={};if(!n)return e;const r=n.startsWith("?")?n.substring(1).split("&"):n.split("&");for(const c of r){const[t,i]=c.split("=");if(t&&i){const o=d(t),s=d(i);if(o in e)Array.isArray(e[o])?e[o].push(s):e[o]=[e[o],s];else{const a=[",","|"].find(p=>s.includes(p));e[o]=a?s.split(a):s}}}return e}stringify(n,e={encode:!0,sort:!0}){const r=[];for(const[c,t]of Object.entries(n))if(Object.prototype.hasOwnProperty.call(n,c)){const i=e.encode?encodeURIComponent(c):c;if(Array.isArray(t)){for(const o of t)if(o){const s=e.encode?encodeURIComponent(o):o;r.push(`${i}=${s}`)}}else if(t){const o=e.encode?encodeURIComponent(t):t;r.push(`${i}=${o}`)}}return e.sort&&r.sort(),r.join("&")}}const l=new f;export{l as queryString};
