UNPKG

box-ui-elements-mlh

Version:
42 lines (33 loc) 853 B
/** * @flow * @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: string, queryParams: Object): string { if (!queryParams) { return url; } const uri = new Uri(url); Object.keys(queryParams).forEach(key => { const 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 };