datasquirel/utils/functions/serialize-query.js

19 lines
437 B
JavaScript
Raw Normal View History

2024-10-18 04:49:04 +00:00
// @ts-check
2024-10-18 05:45:25 +00:00
/** @type {import("@/package-shared/types").SerializeQueryFnType} */
2024-10-18 04:49:04 +00:00
function serializeQuery({ query }) {
let str = "?";
const keys = Object.keys(query);
/** @type {string[]} */
const queryArr = [];
keys.forEach((key) => {
2024-10-18 06:02:16 +00:00
if (!key || !query[key]) return;
2024-10-18 04:49:04 +00:00
queryArr.push(`${key}=${query[key]}`);
});
str += queryArr.join("&");
return str;
}
module.exports = serializeQuery;