Created
January 12, 2018 13:19
-
-
Save jmarmolejos/a2e46b6ffcdc484706c478f018386bbd 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
const buildUrl = function(url, params) { | |
let _url = url | |
if (url.indexOf('?') === -1) { | |
_url = url + '?' | |
} | |
let queries = [] | |
Object.keys(params).forEach(function(key) { | |
queries.push(`${key}=${params[key]}`) | |
}) | |
return _url + queries.join('&') | |
} | |
console.log(buildUrl('/booking' ,{ foo: 'bar', bar: 'baz' })) // returns /booking?foo=bar&bar=baz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment