github-pages-deploy-action/node_modules/@octokit/endpoint/dist-src/util/add-query-parameters.js

22 lines
622 B
JavaScript
Raw Normal View History

2020-01-28 13:08:03 +08:00
export function addQueryParameters(url, parameters) {
const separator = /\?/.test(url) ? "&" : "?";
const names = Object.keys(parameters);
if (names.length === 0) {
return url;
}
return (url +
separator +
names
2020-06-07 00:27:02 +08:00
.map(name => {
2020-01-28 13:08:03 +08:00
if (name === "q") {
2020-06-07 00:27:02 +08:00
return ("q=" +
parameters
.q.split("+")
.map(encodeURIComponent)
.join("+"));
2020-01-28 13:08:03 +08:00
}
return `${name}=${encodeURIComponent(parameters[name])}`;
})
.join("&"));
}