mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
Use URLSearchParams for parser
This commit is contained in:
@@ -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 New Issue
Block a user