# @thyself/clean-empty-values

> Fast object empty values cleaner.

Latest version **1.1.5** (published 2024-02-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @thyself/clean-empty-values
pnpm add @thyself/clean-empty-values
yarn add @thyself/clean-empty-values
bun add @thyself/clean-empty-values
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2024-02-23 |
| First published | 2024-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ofri Peretz |
| Maintainers | the_offricial |
| Keywords | thyself, clean-empty-values, clean-objects |

## Links

- npm: https://www.npmjs.com/package/@thyself/clean-empty-values
- Repository: https://github.com/theoffricial/thyself
- Homepage: https://github.com/theoffricial/thyself/tree/main/packages/cev
- Issues: https://github.com/theoffricial/thyself/issues
- npm.io page: https://npm.io/package/@thyself/clean-empty-values

## Recent versions

- 1.1.5 (latest) — 2024-02-23
- 1.1.4 — 2024-02-22
- 1.1.3 — 2024-02-22
- 1.1.2 — 2024-02-22
- 1.1.1 — 2024-02-17
- 1.1.0 — 2024-02-10
- 1.0.2 — 2024-02-04
- 1.0.1 — 2024-02-04
- 1.0.0 — 2024-02-04
- 0.1.0 — 2024-02-03

## README

# clean-empty-values, or "cev"

Fast object empty values cleaner.

![NPM Downloads](https://img.shields.io/npm/dy/%40thyself%2Fclean-empty-values)
![Dependents (via libraries.io)](https://img.shields.io/librariesio/dependents/npm/%40thyself%2Fclean-empty-values)
![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/%40thyself/clean-empty-values)
![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/%40thyself/clean-empty-values)

## Features

- Dependency-free, super small and efficient package.
- Supports the following clean-ups: `undefined`, `null`, `NaN`, `empty-strings`, `emptyObjects`, `emptyArrays`.
- Supports a "clean in place" strategy that reduces memory consumption, with the `cleanInPlace` option.
- Supports nested-objects clean-up.
- Advanced TypeScript support for maximum flexibility on development time.
- Both CommonJS and ESM support.

## Install

```bash
# npm
npm i @thyself/clean-empty-values
# yarn
yarn add @thyself/clean-empty-values
# pnpm
pnpm add @thyself/clean-empty-values
```

## Usage

usage examples presented as jest tests for convenience

Simple usage

```ts
import { cleanEmptyValues } from '@thyself/clean-empty-values';
// value will be `{ y: null }`.
const value = cleanEmptyValues({ x: '', y: null }, { emptyStrings: true });
// value will be `{ x: '' }`.
const value = cleanEmptyValues({ x: '', y: null }, { null: true });
// value will be `{}`.
const value = cleanEmptyValues({ x: '', y: null }, { null: true, emptyStrings: true });

// value will be `{ y: { z: null, zyx: undefined } }`
const value = cleanEmptyValues({ x: '', y: { z: null, abc: '', zyx: undefined } }, { emptyStrings: true });

// value will be `{}`. Using "replaceInPlace" which optimizes memory usage.
const value = cleanEmptyValues({ x: '', y: null }, { null: true, emptyStrings: true, replaceInPlace: true });
```

See more examples by reviewing the [unit tests](https://github.com/theoffricial/thyself/blob/main/packages/cev/src/lib/clean-empty-values.spec.ts).

### Advanced TypeScript Support

Provides maximum flexibility and strongly-typed code.

```ts
import { cleanEmptyValues } from '@thyself/clean-empty-values';
type MyType = { y: { z: null | number } };
const myValue = cleanEmptyValues<MyType>({ x: '', y: { z: null, abc: '' } }, { emptyStrings: true });

myValue.x; // ❌ Type error, `"myValue.x` is NOT known "MyType".
myValue.y.abc; // ❌ Type error, `"myValue.y.abc` is NOT known by the "MyType"
myValue.y; // ✅ "myValue.y" is known by the Typescript compiler (tsc)
myValue.y.z; // ✅ "myValue.y.z" is known by the Typescript compiler (tsc)
myValue.y.z = 7; // ✅ "myValue.z" can be assigned to number.
myValue.y.z = '7'; // ❌ Type error, "myValue.y.z" must be assigned to `null | number`
```

## "replaceInPlace" option

This option is considered more advanced, that's why its default value is false.

"replace in place" meaning that instead of creating new helper objects and variables building the "cleaned" object, it does the replace over the original object reference and by that save memory and improves performance.

🚧 _WARNING! If you utilize the original object reference in other places in your code using this option might affect your code, so ensure you know what you're doing._ 🚧

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