tiny-clean-object
v1.4.0
Published
A tiny and fast utility to clean deep object
Downloads
529
Maintainers
Readme
tiny-clean-object
A tiny and fast utility to clean deep object
Installation
npm install tiny-clean-object
Example:
import {cleanObject} from 'tiny-clean-object';
const object = {
a: 'ok',
b: 123,
c: null,
d: undefined,
e: NaN,
f: Infinity,
g: {
deep: 'ok',
deep2: {
obj: {},
arr: [],
empty: '',
},
deep3: null,
deep4: NaN,
},
h: [],
i: {},
k: '',
};
cleanObject(object, {deep: true, emptyObjects: true});
Result
{
"a": "ok",
"b": 123,
"g": {
"deep": "ok",
"deep2": {
"arr": []
}
},
"h": []
}
Options
| Option | Default value | Description |
| --------------------- | ------------- | -------------------------------- |
| deep | false | Recursive. Clean deep object |
| skipNull | false | Skip keys with null as the value |
| emptyStrings | true | Remove empty strings, ie: ''
|
| emptyInvalidNumbers | true | Remove NaN
and Infinity
|
| emptyArrays | false | Remove empty arrays, ie: []
|
| emptyObjects | false | Remove empty objects, ie: {}
|
License
MIT