Skip to content

Instantly share code, notes, and snippets.

@ridvansumset
Last active March 6, 2022 10:38
Show Gist options
  • Save ridvansumset/d65ae44b24647a6a69342254ac20622c to your computer and use it in GitHub Desktop.
Save ridvansumset/d65ae44b24647a6a69342254ac20622c to your computer and use it in GitHub Desktop.
getFullPath(path, params = null, query = null) {
let ret = path;
if (params) {
for (const key in params) {
if (Object.prototype.hasOwnProperty.call(params, key)) {
ret = ret.replace(`:${key}`, params[key]);
}
}
}
if (query) {
ret += '?';
let i = 0;
for (const key in query) {
if (Object.prototype.hasOwnProperty.call(query, key)) {
if (i > 0) {
ret += '&';
}
ret += `${key}=${encodeURIComponent(query[key])}`;
i += 1;
}
}
}
return ret;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment