Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
feat(remove-object-nullish): removendo objetos que são undefined ou n…
Browse files Browse the repository at this point in the history
…ull dos parametros
  • Loading branch information
andrefelipeschulle committed Aug 2, 2024
1 parent 6aae191 commit 9cb856e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@brainylab/fetch-wrapper",
"version": "0.5.2",
"version": "0.5.3",
"keywords": [
"fetch",
"wrapper",
Expand Down
17 changes: 16 additions & 1 deletion src/utils/object-to-url-params.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
function cleanObject(
obj: Record<string, string | number | string[] | number[] | undefined | null>,
): Record<string, string | number | string[] | number[]> {
const cleanedObj: Record<string, string | number | string[] | number[]> = {};
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, string | number | string[] | number[]>,
): 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[];
Expand Down

0 comments on commit 9cb856e

Please sign in to comment.