Parameterize URLs with a single String#replace
This commit is contained in:
parent
7a184cb3b7
commit
74062cda29
1 changed files with 4 additions and 6 deletions
10
mithril.js
10
mithril.js
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue