Skip to content

Instantly share code, notes, and snippets.

@JonathanDn
Last active March 24, 2017 11:07
Show Gist options
  • Save JonathanDn/641e3eba4f30afc3fd82f0fe62d3a462 to your computer and use it in GitHub Desktop.
Save JonathanDn/641e3eba4f30afc3fd82f0fe62d3a462 to your computer and use it in GitHub Desktop.
URL constructing function with ascending arguments
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):
urlFormat(str, 1stArg?, 2ndArg?, 3rdArg?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment