Skip to content

Instantly share code, notes, and snippets.

@ox
Created July 19, 2013 03:35
Show Gist options
  • Save ox/6034927 to your computer and use it in GitHub Desktop.
Save ox/6034927 to your computer and use it in GitHub Desktop.
var genKeyBuilder = function(key) {
return function (data) {
return key.replace(/(:(\w+))/g, function (_, _, inner) {
return data[inner]
})
}
}
console.log(genKeyBuilder('/:controller/:action/:id')({controller: 'foo', action: 'bar', id: '123'}))
// #=> /foo/bar/123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment