datasquirel/utils/functions/serialize-query.js

19 lines
441 B
JavaScript
Raw Normal View History

2024-10-18 04:49:04 +00:00
// @ts-check
2024-10-19 16:45:42 +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;