Skip to content

Commit

Permalink
feat(utilities): new stringifyQueryParams() function
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoemp committed Nov 13, 2024
1 parent 1464d1e commit f38ce61
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions libs/utilities/src/lib/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,23 @@ export function extractFileNameFromURL(url: string): {
extension: matches[2],
};
}

/**
* returns a string representing query parameters and their values without empty values.
* @param params
*/
export function stringifyQueryParams(params: Record<string, any>) {
if (!params) {
return '';
}

const strArray: string[] = [];

for (const key of Object.keys(params)) {
if (params[key] !== undefined) {
strArray.push(`${key}=${params[key]}`);
}
}

return strArray.length > 0 ? `?${strArray.join('&')}` : '';
}

0 comments on commit f38ce61

Please sign in to comment.