Last active
March 24, 2017 11:07
-
-
Save JonathanDn/641e3eba4f30afc3fd82f0fe62d3a462 to your computer and use it in GitHub Desktop.
URL constructing function with ascending arguments
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
export function urlFormat(str) { | |
let urlConstruct = str; | |
for (var i = 1; i < arguments.length; i++) { | |
// g - global search, m - multiline | |
let regEx = new RegExp("\\{" + (i - 1) + '"\\}', 'gm') | |
urlConstruct = urlConstruct.replace(regEx, arguments[i]); | |
} | |
return urlConstruct; | |
} | |
// Will work like so(endless amount of args): | |
// url should look like this to work : http://{0}/{1}/{2} and so on... | |
urlFormat(str, 1stArg?, 2ndArg?, 3rdArg?) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment