mirror of
https://code.forgejo.org/actions/setup-node.git
synced 2024-11-06 20:15:48 +00:00
21 lines
622 B
JavaScript
21 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("&"));
|
|
}
|