Remove falsy, empty or nullable values from objects
npm install clean-deepRemoves empty _objects_, _arrays_, empty _strings_, _NaN_, _null_ and _undefined_ values from objects. Does not alter the original object.
As of version 3.0.0, _clean-deep_ traverses arrays as well as objects.
[![npm version][npm-image]][npm-url] [![build status][workflow-image]][workflow-url]
Install the package via npm:
```
$ npm install clean-deep --save
1. object _(Object)_: The source object.[options]
2. _(Object)_: An optional object with the following options:
Option | Default value | Description
----------------- | ------------- | -----------------------------------
_cleanKeys_ | _[]_ | Remove specific keys, ie: ['foo', 'bar', ' ']['foo', 'bar', ' ']
_cleanValues_ | _[]_ | Remove specific values, ie: []
_emptyArrays_ | _true_ | Remove empty arrays, ie: {}
_emptyObjects_ | _true_ | Remove empty objects, ie: ''
_emptyStrings_ | _true_ | Remove empty strings, ie: NaN
_NaNValues_ | _false_ | Remove NaN values, ie: null
_nullValues_ | _true_ | Remove null values, ie: undefined
_undefinedValues_ | _true_ | Remove undefined values, ie:
_(Object)_: Returns the cleansed object.
`javascript
const cleanDeep = require('clean-deep');
const object = {
bar: {},
baz: null,
biz: 'baz',
foo: '',
net: [],
nit: undefined,
qux: {
baz: 'boz',
txi: ''
}
};
cleanDeep(object);
// => { biz: 'baz', qux: { baz: 'boz' } }
`
`javascript`
$ npm test
`sh``
npm version [
MIT
[npm-image]: https://img.shields.io/npm/v/clean-deep.svg?style=flat-square
[npm-url]: https://npmjs.org/package/clean-deep
[workflow-image]: https://github.com/nunofgs/clean-deep/workflows/Node%20CI/badge.svg
[workflow-url]: https://github.com/nunofgs/clean-deep/actions