mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
22 lines
622 B
JavaScript
22 lines
622 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("&"));
|
|
}
|