Files
drip/lib/import-export/replace-with-null.js
2022-07-31 18:23:17 +00:00

13 lines
354 B
JavaScript

const isObject = (obj) => obj === Object(obj)
export default function replaceWithNullIfAllPropertiesAreNull(obj) {
Object.keys(obj).forEach((key) => {
if (!isObject(obj[key])) return
if (Object.values(obj[key]).every((val) => val === null)) {
obj[key] = null
return
}
replaceWithNullIfAllPropertiesAreNull(obj[key])
})
}