Recursively omit empty properties from an object. Omits empty objects, arrays, strings or zero.
Install with npm:
$ npm install omit-empty --save
var omitEmpty = require('omit-empty');
omitEmpty({a: 'a', b: ''});
//=> {a: 'a'}
omitEmpty({a: 'a', b: {c: 'c', d: ''}});
//=> {a: 'a', b: {c: 'c'}
omitEmpty({a: ['a'], b: []});
//=> {a: ['a']}
omitEmpty({a: 0, b: 1});
//=> {a: 0, b: 1}
// set the `noZero` flag
omitEmpty({a: 0, b: 1}, true);
//=> {b: 1}
You might also be interested in these projects:
- for-in: Iterate over the own and inherited enumerable properties of an objecte, and return an object… more | homepage
- for-own: Iterate over the own enumerable properties of an object, and return an object with properties… more | homepage
- is-plain-object: Returns true if an object was created by the
Object
constructor. | homepage - reduce-object: Reduces an object to a value that is the accumulated result of running each property… more | homepage
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Install dev dependencies:
$ npm install -d && npm test
Jon Schlinkert
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb, v0.9.0, on April 09, 2016.