Last active
January 16, 2020 16:52
-
-
Save claudiohilario/5aa9691c92dac28617c0a423e1f8c251 to your computer and use it in GitHub Desktop.
formatUrlParams -> Formatar parâmetros URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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