import { hasUriEncodedChars } from "./utils.js"; function encode(obj, pfx) { let k, i, tmp, str = ""; for (k in obj) { if ((tmp = obj[k]) !== void 0) { if (Array.isArray(tmp)) { for (i = 0; i < tmp.length; i++) { str && (str += "&"); str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp[i]); } } else { str && (str += "&"); str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp); } } } return (pfx || "") + str; } function toValue(mix) { if (!mix) return ""; const str = hasUriEncodedChars(mix) ? decodeURIComponent(mix) : decodeURIComponent(encodeURIComponent(mix)); if (str === "false") return false; if (str === "true") return true; return +str * 0 === 0 && +str + "" === str ? +str : str; } function decode(str, pfx) { let tmp, k; const out = {}, arr = (pfx ? str.substr(pfx.length) : str).split("&"); while (tmp = arr.shift()) { const equalIndex = tmp.indexOf("="); if (equalIndex !== -1) { k = tmp.slice(0, equalIndex); k = decodeURIComponent(k); const value = tmp.slice(equalIndex + 1); if (out[k] !== void 0) { out[k] = [].concat(out[k], toValue(value)); } else { out[k] = toValue(value); } } else { k = tmp; k = decodeURIComponent(k); out[k] = ""; } } return out; } export { decode, encode }; //# sourceMappingURL=qss.js.map