empty-trim
v1.0.0
Published
Remove empty subobjects from your objects({})
Downloads
3
Readme
empty-trim
A module to remove empty subobjects from given object recursively.
Installation
With npm
npm install empty-trim
Example
var trim = require('trim-empty');
var obj = {
level1:{
level2:{
level3:{
name: "Foo"
},
emptyOne: {
inner: {}
}
},
anotherLevel2: "bar"
}
};
trim(obj);
/*
Object now:
obj => {
level1:{
level2:{
level3:{
name: "Foo"
}
},
anotherLevel2: "bar"
}
}
*/
API
trim(object);
Removes all empty objects({}) recursively. If object becomes empty after its children are removed, it'll remove empty parent too.