first commit
This commit is contained in:
28
src/clientsdk/querySerializer.ts
Normal file
28
src/clientsdk/querySerializer.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
export const customQuerySerializer = (queryParams: any) => {
|
||||
const search: string[] = [];
|
||||
|
||||
const serialize = (name: string, value: any) => {
|
||||
if (value === undefined || value === null) return;
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((v, i) => {
|
||||
serialize(`${name}[${i}]`, v);
|
||||
});
|
||||
} else if (typeof value === 'object' && value !== null && !(value instanceof Date)) {
|
||||
Object.entries(value).forEach(([key, v]) => {
|
||||
serialize(`${name}[${key}]`, v);
|
||||
});
|
||||
} else {
|
||||
const val = value instanceof Date ? value.toISOString() : String(value);
|
||||
search.push(`${encodeURIComponent(name)}=${encodeURIComponent(val)}`);
|
||||
}
|
||||
};
|
||||
|
||||
if (queryParams && typeof queryParams === 'object') {
|
||||
for (const key in queryParams) {
|
||||
serialize(key, queryParams[key]);
|
||||
}
|
||||
}
|
||||
|
||||
return search.join('&');
|
||||
};
|
||||
Reference in New Issue
Block a user