Skip to content

Commit

Permalink
rewrite function 'appendQueryString'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiNyzhnyk committed Jun 10, 2022
1 parent bc3f65e commit 88c3316
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/utilities.js
Expand Up @@ -478,13 +478,11 @@ utilities.assignVendorExtensions = function(target, source) {
* @return {string}
*/
utilities.appendQueryString = function (url, qsName, qsValue) {
const urlObj = Url.parse(url);
if (qsName && qsValue) {
urlObj.query = Querystring.parse(qsName + '=' + qsValue);
urlObj.search = '?' + encodeURIComponent(qsName) + '=' + encodeURIComponent(qsValue);
} else {
urlObj.search = '';
}
if (!qsName || !qsValue) {
return url;
}

const query = new URLSearchParams({[qsName]: qsValue});

return urlObj.format(urlObj);
return `${url}?${query.toString()}`;
};

0 comments on commit 88c3316

Please sign in to comment.