box-ui-elements-mlh
Version:
40 lines (33 loc) • 800 B
JavaScript
/**
*
* @file Utility functions for urls
* @author Box
*/
import Uri from 'jsuri';
/**
* Update URL query parameters
*
* @param {string} url - the url that contains the potential query parameter string
* @param {Object} queryParams
* @return {string}
*/
function updateQueryParameters(url, queryParams) {
if (!queryParams) {
return url;
}
var uri = new Uri(url);
Object.keys(queryParams).forEach(function (key) {
var value = queryParams[key];
if (!value) {
return;
}
if (uri.hasQueryParam(key)) {
uri.replaceQueryParam(key, value);
return;
}
uri.addQueryParam(key, value);
});
return uri.toString();
} // eslint-disable-next-line import/prefer-default-export
export { updateQueryParameters };
//# sourceMappingURL=url.js.map