api: remove undefined in API.Q
Signed-off-by: Varun Patil <varunpatil@ucla.edu>pull/563/head
parent
b6d251ebf5
commit
a0ff17df96
|
@ -43,10 +43,20 @@ export class API {
|
||||||
) {
|
) {
|
||||||
if (!query) return url;
|
if (!query) return url;
|
||||||
|
|
||||||
|
if (typeof query === "object") {
|
||||||
|
// Clean up undefined and null
|
||||||
|
Object.keys(query).forEach((key) => {
|
||||||
|
if (query[key] === undefined || query[key] === null) {
|
||||||
|
delete query[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Convert to search params
|
||||||
|
query = new URLSearchParams(<any>query);
|
||||||
|
}
|
||||||
|
|
||||||
if (query instanceof URLSearchParams) {
|
if (query instanceof URLSearchParams) {
|
||||||
query = query.toString();
|
query = query.toString();
|
||||||
} else if (typeof query === "object") {
|
|
||||||
query = new URLSearchParams(query as any).toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!query) return url;
|
if (!query) return url;
|
||||||
|
|
Loading…
Reference in New Issue