change-string-case/node_modules/@octokit/endpoint/dist-src/util/add-query-parameters.js

17 lines
455 B
JavaScript
Raw Permalink Normal View History

2023-10-26 04:27:07 +08:00
function addQueryParameters(url, parameters) {
const separator = /\?/.test(url) ? "&" : "?";
const names = Object.keys(parameters);
if (names.length === 0) {
return url;
}
return url + separator + names.map((name) => {
if (name === "q") {
return "q=" + parameters.q.split("+").map(encodeURIComponent).join("+");
2022-11-04 00:55:07 +08:00
}
2023-10-26 04:27:07 +08:00
return `${name}=${encodeURIComponent(parameters[name])}`;
}).join("&");
2022-11-04 00:55:07 +08:00
}
2023-10-26 04:27:07 +08:00
export {
addQueryParameters
};