@daysnap/utils
Version:
28 lines (25 loc) • 533 B
JavaScript
import {
isJSONString
} from "./chunk-IIIHPNUB.js";
// src/parseQuery.ts
function parseQuery(v, k) {
let searchStr = "";
if (!v) {
searchStr = window.location.search;
} else {
const url = new URL(v);
searchStr = url.search;
}
const query = new URLSearchParams(decodeURIComponent(searchStr));
if (k) {
return query.get(k);
}
const res = {};
for (const [key, value] of query.entries()) {
res[key] = isJSONString(value) ? JSON.parse(value) : value;
}
return res;
}
export {
parseQuery
};