Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

omit-empty

jonschlinkert298.7kMIT1.0.0TypeScript support: definitely-typed

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

clear, delete, empty, find, has, hasown, javascript, js, key, keys, node, node-js, object, omit, properties, property, remove, util, utilities, utility, value

readme

omit-empty NPM version NPM monthly downloads NPM total downloads Linux Build Status

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

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.

Install

Install with npm:

$ npm install --save omit-empty

Heads up!

Breaking changes in v1.0.0! See the Release History.

Usage

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

<summary>Contributing</summary>

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

<summary>Running Tests</summary>

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:

$ npm install && npm test
<summary>Building docs</summary>

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

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

You might also be interested in these projects:

Contributors

Commits Contributor
31 jonschlinkert
1 kakadiadarpan

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.8.0, on December 10, 2018.

changelog

Release history

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

<summary>Guiding Principles</summary>
  • Changelogs are for humans, not machines.
  • There should be an entry for every single version.
  • The same types of changes should be grouped.
  • Versions and sections should be linkable.
  • The latest version comes first.
  • The release date of each versions is displayed.
  • Mention whether you follow Semantic Versioning.
<summary>Types of changes</summary>

Changelog entries are classified using the following labels (from keep-a-changelog):

  • Added for new features.
  • Changed for changes in existing functionality.
  • Deprecated for soon-to-be removed features.
  • Removed for now removed features.
  • Fixed for any bug fixes.
  • Security in case of vulnerabilities.

[1.0.0] - 2018-12-10

Changed

  • refactored completely
  • support was removed for exclude and excludeType
  • options.noZero was renamed to options.omitZero

0.4.1 - 2016-06-01

  • adds support for excluding types or keys

0.4.0 - 2016-06-01

0.3.6 - 2016-04-09

  • make array value handling stricter

0.3.5 - 2016-04-09

  • ensure empty arrays are omitted

0.3.4 - 2016-03-27

  • ensure zero-length function values aren't omitted

0.3.3 - 2016-03-19

  • bugfix: do not omit Date objects.
  • Merge pull request #2 from stnever/do-not-omit-dates

0.3.2 - 2015-12-24

  • update deps

[0.3.1] - 2015-03-24

  • first commit