53 lines
1.5 KiB
Plaintext
53 lines
1.5 KiB
Plaintext
"use strict";
|
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
const utils = require("./utils.cjs");
|
|
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 = utils.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;
|
|
}
|
|
exports.decode = decode;
|
|
exports.encode = encode;
|
|
//# sourceMappingURL=qss.cjs.map
|