fix: install clean-deep

This commit is contained in:
Christel Westerberg
2024-05-15 13:20:43 +02:00
parent 863d99ad44
commit cd33e17775
6 changed files with 55 additions and 27 deletions

View File

@@ -53,26 +53,3 @@ export async function getContentTypeByPathName(
return PageTypeEnum.CurrentBlocksPage
}
}
/**
* Function to remove empty objects from a fetched content type.
* Used since Contentstack returns empty objects for all non
* queried in modular blocks.
*/
export function removeEmptyObjects<T>(obj: T): T {
const copy = obj as any
for (let key in copy) {
if (typeof copy[key] === "object" && copy[key] !== null) {
copy[key] = removeEmptyObjects(copy[key])
if (Object.keys(copy[key]).length === 0 && !Array.isArray(copy[key])) {
delete copy[key]
}
}
}
if (Array.isArray(copy)) {
return copy.filter((item) => item != null).map(removeEmptyObjects) as T
}
return copy as T
}