Use URLSearchParams for parser
This commit is contained in:
parent
df5eba629a
commit
9841fa3c63
1 changed files with 15 additions and 1 deletions
|
@ -1,3 +1,17 @@
|
||||||
|
import isUndefined from 'lodash/isUndefined';
|
||||||
|
import omitBy from 'lodash/omitBy';
|
||||||
|
|
||||||
export const parseSearchParams = (searchParams: Record<any, any>) => {
|
export const parseSearchParams = (searchParams: Record<any, any>) => {
|
||||||
return JSON.parse(JSON.stringify(searchParams));
|
const params = new URLSearchParams();
|
||||||
|
const paramsWithoutUndefined = omitBy(searchParams, isUndefined);
|
||||||
|
|
||||||
|
Object.entries(paramsWithoutUndefined).forEach(([key, value]) => {
|
||||||
|
if (!Array.isArray(value)) {
|
||||||
|
params.append(key, value.toString());
|
||||||
|
} else {
|
||||||
|
value.forEach((value) => params.append(key, value.toString()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return params.toString();
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue