Last active
May 14, 2018 00:59
-
-
Save jonathan-fulton/53b03db644353af05279f8fe3eea1a09 to your computer and use it in GitHub Desktop.
build-url: the bad way
This file contains hidden or 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
function buildUrl(url, options) { | |
var queryString = []; | |
var key; | |
var builtUrl; | |
if (url === null) { | |
builtUrl = ''; | |
} else if (typeof(url) === 'object') { | |
builtUrl = ''; | |
options = url; | |
} else { | |
builtUrl = url; | |
} | |
if (options) { | |
if (options.path) { | |
builtUrl += '/' + options.path; | |
} | |
if (options.queryParams) { | |
for (key in options.queryParams) { | |
if (options.queryParams.hasOwnProperty(key)) { | |
queryString.push(key + '=' + options.queryParams[key]); | |
} | |
} | |
builtUrl += '?' + queryString.join('&'); | |
} | |
if (options.hash) { | |
builtUrl += '#' + options.hash; | |
} | |
} | |
return builtUrl; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Borrowed directly from here: https://github.com/steverydz/build-url/blob/master/src/build-url.js