Files
med-notes/.pnpm-store/v10/files/0d/3bdf944164720e55694df2100429bd4091fc41f791b4a70ec29fbcfbc3fedb42e663fc81dda7d54107ced9365c4017da55634c166ae683262fe4577bde7f4b
2025-05-09 05:30:08 +02:00

53 lines
1.4 KiB
Plaintext

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