Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jonschlinkert/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.
https://github.com/jonschlinkert/omit-empty

empty javascript jonschlinkert keys object omit remove utility

Last synced: 3 days ago
JSON representation

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.

Awesome Lists containing this project

README

        

# omit-empty [![NPM version](https://img.shields.io/npm/v/omit-empty.svg?style=flat)](https://www.npmjs.com/package/omit-empty) [![NPM monthly downloads](https://img.shields.io/npm/dm/omit-empty.svg?style=flat)](https://npmjs.org/package/omit-empty) [![NPM total downloads](https://img.shields.io/npm/dt/omit-empty.svg?style=flat)](https://npmjs.org/package/omit-empty) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/omit-empty.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/omit-empty)

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

Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save omit-empty
```

## Heads up!

Breaking changes in v1.0.0! See the [Release History](#CHANGELOG.md).

## Usage

```js
const omitEmpty = require('omit-empty');

console.log(omitEmpty({ a: 'a', b: '' }));
//=> { a: 'a' }

console.log(omitEmpty({ a: 'a', b: { c: 'c', d: '' } }));
//=> { a: 'a', b: { c: 'c' } }

console.log(omitEmpty({ a: ['a'], b: [] }));
//=> { a: ['a'] }

console.log(omitEmpty({ a: 0, b: 1 }));
//=> { a: 0, b: 1 }

// set omitZero to true, to evaluate "0" as falsey
console.log(omitEmpty({ a: 0, b: 1 }, { omitZero: true }));
//=> { b: 1 }
```

## About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

Building docs

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Related projects

You might also be interested in these projects:

* [is-plain-object](https://www.npmjs.com/package/is-plain-object): Returns true if an object was created by the `Object` constructor. | [homepage](https://github.com/jonschlinkert/is-plain-object "Returns true if an object was created by the `Object` constructor.")
* [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject "Returns true if the value is an object and not an array or null.")
* [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.")

### Contributors

| **Commits** | **Contributor** |
| --- | --- |
| 31 | [jonschlinkert](https://github.com/jonschlinkert) |
| 1 | [kakadiadarpan](https://github.com/kakadiadarpan) |

### Author

**Jon Schlinkert**

* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)

### License

Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on December 10, 2018._