Skip to content

Instantly share code, notes, and snippets.

@bmount
Created August 22, 2013 05:40
Show Gist options
  • Select an option

  • Save bmount/6303548 to your computer and use it in GitHub Desktop.

Select an option

Save bmount/6303548 to your computer and use it in GitHub Desktop.
function urlTmpl (tmpl, obj) {
return tmpl.replace(/{{([a-zA-Z0-9]+)}}/g, function (s, v) { return obj[v] })
}
/*
> urlTmpl('shit is {{status}} and {{qualifier}}', { status: 'fucked up', qualifier: 'bullshit' })
"shit is fucked up and bullshit"
> urlTmpl('shit is {{status}} and {{qualifier}}', { status: 'fucked up', oops_qualifier: 'bullshit' })
"shit is fucked up and undefined"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment