Skip to content

Commit

Permalink
fix: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaostrovskii Dmitrii committed Feb 20, 2024
1 parent 70bf041 commit 45d4d92
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions libs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@ export function getBasePath(alias: string, relativePath: string): string {

export function pruneEmptyQueryParams(url: string): string {
const querySeparator = '?';
const queryParametersSeparator = '&';
const queryParamsSeparator = '&';

if (!url || !url.includes(querySeparator)) {
return url;
}

const splitedUrl = url.split(querySeparator);

const path = splitedUrl[0];
const query = splitedUrl[1];
const [path, query] = url.split(querySeparator);

const prunedQuery = query
.split(queryParametersSeparator)
.split(queryParamsSeparator)
.filter((x) => !x.trimEnd().endsWith('='))
.join(queryParametersSeparator)
.join(queryParamsSeparator)
.slice(0);

return prunedQuery.length ? `${path}${querySeparator}${prunedQuery}` : path;
Expand Down

0 comments on commit 45d4d92

Please sign in to comment.