Created
April 2, 2017 08:04
-
-
Save delvedor/0a9d8f8383e6e6bf76418678df194c9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
/some/:id/path => /some/{id}/path | |
/another/:example/for/:you => /another/{example}/for/{you} | |
*/ | |
function formatParamUrl (url) { | |
var start = url.indexOf('/:') | |
if (start === -1) return url | |
var end = url.indexOf('/', ++start) | |
if (end === -1) { | |
return url.slice(0, start) + '{' + url.slice(++start) + '}' | |
} else { | |
return formatParamUrl(url.slice(0, start) + '{' + url.slice(++start, end) + '}' + url.slice(end)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment