Skip to content

Commit

Permalink
Parameterize URLs with a single String#replace
Browse files Browse the repository at this point in the history
  • Loading branch information
maranomynet committed Feb 18, 2016
1 parent 7a184cb commit 74062cd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions mithril.js
Original file line number Diff line number Diff line change
Expand Up @@ -2048,16 +2048,14 @@
}

function parameterizeUrl(url, data) {
var tokens = url.match(/:[a-z]\w+/gi)

if (tokens && data) {
forEach(tokens, function (token) {
if (data) {
url = url.replace(/:[a-z]\w+/gi, function(token){
var key = token.slice(1)
url = url.replace(token, data[key])
var value = data[key]
delete data[key]
return value
})
}

return url
}

Expand Down

0 comments on commit 74062cd

Please sign in to comment.