cd

clean-deep

Remove falsy, empty or nullable values from objects

Showing:

Popularity

Downloads/wk

106K

GitHub Stars

130

Maintenance

Last Commit

1yr ago

Contributors

13

Package

Dependencies

3

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

clean-deep

Removes 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.

Status

npm version build status

Installation

Install the package via npm:

$ npm install clean-deep --save

Usage

Arguments

  1. object (Object): The source object.
  2. [options] (Object): An optional object with the following options:
OptionDefault valueDescription
cleanKeys[]Remove specific keys, ie: ['foo', 'bar', ' ']
cleanValues[]Remove specific values, ie: ['foo', 'bar', ' ']
emptyArraystrueRemove empty arrays, ie: []
emptyObjectstrueRemove empty objects, ie: {}
emptyStringstrueRemove empty strings, ie: ''
NaNValuesfalseRemove NaN values, ie: NaN
nullValuestrueRemove null values, ie: null
undefinedValuestrueRemove undefined values, ie: undefined

(Object): Returns the cleansed object.

Example

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' } }

Tests

$ npm test

Release

npm version [<newversion> | major | minor | patch] -m "Release %s"

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial