mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
fix: clean undefined values before posting form
This commit is contained in:
14
apps/client/app/utils/object.ts
Normal file
14
apps/client/app/utils/object.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export function deepClean<T>(obj: T): T {
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(deepClean).filter((v) => v !== undefined && v !== null) as T;
|
||||
}
|
||||
|
||||
if (obj && typeof obj === "object") {
|
||||
return Object.entries(obj).reduce((acc, [key, value]) => {
|
||||
const cleaned = deepClean(value);
|
||||
if (cleaned !== undefined) acc[key as keyof T] = cleaned;
|
||||
return acc;
|
||||
}, {} as T);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
Reference in New Issue
Block a user