change-string-case/node_modules/@octokit/endpoint/dist-src/util/add-query-parameters.js
2020-07-29 10:28:09 -06:00

18 lines
529 B
JavaScript

export 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("+"));
}
return `${name}=${encodeURIComponent(parameters[name])}`;
})
.join("&"));
}