Skip to content

Instantly share code, notes, and snippets.

@claudiohilario
Last active January 16, 2020 16:52
Show Gist options
  • Save claudiohilario/5aa9691c92dac28617c0a423e1f8c251 to your computer and use it in GitHub Desktop.
Save claudiohilario/5aa9691c92dac28617c0a423e1f8c251 to your computer and use it in GitHub Desktop.
formatUrlParams -> Formatar parâmetros URL
/**
* @example
*
* const path = '/user/:user_id/test/:test_id';
*
* const params = {
* user_id: 50000,
* test_id: 3,
* }
*/
function formatParams(path, params) {
let finalPath = path;
for(param in params) {
finalPath = finalPath.replace(`:${param}`, params[param]);
}
return finalPath;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment