/omit-empty

Recursively omit empty properties from an object. Omits empty objects, arrays, strings, and optionally zero. Similar results to what you would expect with `compact` for arrays.

Primary LanguageJavaScriptMIT LicenseMIT

omit-empty NPM version NPM downloads Build Status

Recursively omit empty properties from an object. Omits empty objects, arrays, strings or zero.

Install

Install with npm:

$ npm install omit-empty --save

Usage

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}

Related projects

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

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with verb:

$ npm install verb && npm run docs

Or, if verb is installed globally:

$ verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb, v0.9.0, on April 09, 2016.