# filter-empty

> Filter empty values from objects and arrays

Latest version **0.1.12** (published 2020-09-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install filter-empty
pnpm add filter-empty
yarn add filter-empty
bun add filter-empty
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.12 |
| Published | 2020-09-12 |
| First published | 2019-10-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 6 |
| Author | Paul Savignano |
| Maintainers | paulsavignano |
| Keywords | filter-empty, typescript, graphql, filter, objects, arrays, clean |

## Links

- npm: https://www.npmjs.com/package/filter-empty
- Repository: https://github.com/PaulSavignano/filter-empty
- Homepage: https://github.com/PaulSavignano/filter-empty#readme
- Issues: https://github.com/PaulSavignano/filter-empty/issues
- Funding: https://www.patreon.com/PaulSavignano
- npm.io page: https://npm.io/package/filter-empty

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 0.1.12 (latest) — 2020-09-12
- 0.1.11 — 2020-09-10
- 0.1.10 — 2020-09-09
- 0.1.9 — 2020-09-09
- 0.0.9 — 2020-09-09
- 0.0.8 — 2020-01-04
- 0.0.7 — 2019-10-19
- 0.0.6 — 2019-10-16
- 0.0.5 — 2019-10-16
- 0.0.3 — 2019-10-16
- 0.0.2 — 2019-10-16
- 0.0.1 — 2019-10-15

## README

<h1 align="center">filter-empty</h1>

<div align="center">

Filter empty values from objects and/or arrays.

[![NPM Version](https://img.shields.io/npm/v/filter-empty.svg?style=flat)](https://www.npmjs.com/package/filter-empty)
[![NPM Downloads](https://img.shields.io/npm/dm/filter-empty.svg?style=flat)](https://npmcharts.com/compare/filter-empty?minimal=true)
[![CircleCI](https://img.shields.io/circleci/build/github/PaulSavignano/filter-empty/master.svg)](https://circleci.com/gh/PaulSavignano/filter-empty/tree/master)
[![codecov.io](https://codecov.io/gh/PaulSavignano/filter-empty/branch/master/graph/badge.svg)](https://codecov.io/gh/PaulSavignano/filter-empty)
![build](https://github.com/PaulSavignano/filter-empty/workflows/release/badge.svg)
[![BundleSize](https://img.shields.io/bundlephobia/minzip/filter-empty.svg)](https://bundlephobia.com/result?p=filter-empty)
[![Dependencies](https://david-dm.org/PaulSavignano/filter-empty/master/status.svg)](https://david-dm.org/PaulSavignano/filter-empty/master)
[![DevDependencies](https://david-dm.org/PaulSavignano/filter-empty/master/dev-status.svg)](https://david-dm.org/PaulSavignano/filter-empty/master?type=dev)
[![PeerDependencies](https://david-dm.org/PaulSavignano/filter-empty/master/peer-status.svg)](https://david-dm.org/PaulSavignano/filter-empty/master?type=peer)
[![Patreon](https://img.shields.io/badge/patreon-support%20the%20author-blue.svg)](https://www.patreon.com/PaulSavignano)

</div>

Filter-Empty is a Typescript library for removing empty values from objects.

## Features

- Filters empty values from objects and arrays.
- Creates new mutation free objects
- Recurses nested props.
- [![BundleSize](https://img.shields.io/bundlephobia/minzip/filter-empty.svg)](https://bundlephobia.com/result?p=filter-empty) [![BundleSize](https://img.shields.io/bundlephobia/min/filter-empty.svg)](https://bundlephobia.com/result?p=filter-empty).

## Benefits

- New objects free of null, undefined, empty arrays, and empty strings.
- Removal of empty nested props.
- Light, fast, and dependency free lib.

## Motivation

Working with graphql and its great type safty results in null values for some props. Sometime in consuming these props on the client it's better to remove the empty props rather than implementing conditionals.

<br />

## Installation

```
npm install -S filter-empty
```

## Usage

Here is an example to get you started:

```jsx
import filterEmpty from 'filter-empty'

const objToFilter = {
  level1: {
    level2: {
      level3: {
        key1: 'This value is ok',
        key2: null,
        key3: ['', null, 'This is also ok'],
      },
    },
  },
}

const filtered = filterEmpty(objToFilter)

// result
// {
//   level1: {
//     level2: {
//       level3: {
//         key1: 'This value is ok'
//         key3: ['This is also ok']
//       }
//     }
//   }
// }
```

## Examples

[Codesandbox](https://codesandbox.io/s/filter-empty-mtlwh?fontsize=14)

[Codesandbox Typescript](https://codesandbox.io/s/filter-empty-typescript-cplo8?fontsize=14)

## Contributing

1. Fork the repository.

2. Clone the fork to your local machine and add upstream remote:

```sh
git clone https://github.com/<your username>/filter-empty.git
cd filter-empty
git remote add upstream https://github.com/PaulSavignano/filter-empty.git
```

3. Synchronize your local `next` branch with the upstream one:

```sh
git checkout next
git pull upstream next
```

4. Install the dependencies:

```sh
npm install
```

5. Create a new branch:

```sh
git checkout -b my-branch
```

6. Make changes, commit and push to your fork:

```sh
git push -u origin HEAD
```

7. Go to [the repository](https://github.com/PaulSavignano/filter-empty) and make a Pull Request.

---
_Source: https://npm.io/package/filter-empty · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
