diff --git a/package.json b/package.json index d8360b3..ffecf14 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@brainylab/fetch-wrapper", - "version": "0.5.2", + "version": "0.5.3", "keywords": [ "fetch", "wrapper", diff --git a/src/utils/object-to-url-params.ts b/src/utils/object-to-url-params.ts index f24cffe..1576caa 100644 --- a/src/utils/object-to-url-params.ts +++ b/src/utils/object-to-url-params.ts @@ -1,9 +1,24 @@ +function cleanObject( + obj: Record, +): Record { + const cleanedObj: Record = {}; + Object.keys(obj).forEach((key) => { + const value = obj[key]; + if (value !== undefined && value !== null) { + cleanedObj[key] = value; + } + }); + + return cleanedObj; +} + export function objectToUrlParams( obj: Record, ): string { + const cleanedObj = cleanObject(obj); const params = new URLSearchParams(); - Object.keys(obj).map((key) => { + Object.keys(cleanedObj).map((key) => { if (Object.prototype.hasOwnProperty.call(obj, key)) { if (Array.isArray(obj[key])) { const arr = obj[key] as string[] | number[];