npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

deep-cleaner-js

v2.1.1

Published

A powerful TypeScript/JavaScript library for deeply cleaning objects and arrays by removing null, undefined, empty strings, zeros, and empty structures

Readme

🧹 deep-cleaner-js

npm License: MIT TypeScript Coverage Zero Dependencies

deep-cleaner-js — a powerful, zero-dependency TypeScript/JavaScript library for deeply cleaning nested objects and arrays.
Remove null, undefined, empty strings, zeros, and empty structures safely — without losing data integrity.


✨ Features

✅ Deep recursive cleaning of objects and arrays
🧠 Handles circular references safely
⚙️ Fully configurable behavior
💪 Written in TypeScript with full type definitions
🔒 Non-destructive (doesn’t mutate the original object)
⚡ Blazing-fast performance (optimized recursion)
🧰 Preserves Date, RegExp, Map, Set, Buffer, and Function
🧩 Zero dependencies — pure, portable, and lightweight


📦 Installation

# npm
npm install deep-cleaner-js

# yarn
yarn add deep-cleaner-js

# pnpm
pnpm add deep-cleaner-js

🪶 CDN

<script src="https://unpkg.com/deep-cleaner-js/dist/index.umd.js"></script>
<script>
  const result = deepCleaner.deepClean({ a: null, b: 2 });
  console.log(result); // { b: 2 }
</script>

🚀 Quick Start

JavaScript

import { deepClean } from "deep-cleaner-js";

const input = {
  name: "John",
  email: "",
  meta: {
    score: 0,
    address: null,
    active: true,
  },
  tags: [null, "dev", undefined],
};

const cleaned = deepClean(input, {
  removeNull: true,
  removeUndefined: true,
  cleanEmptyString: true,
  cleanZero: false,
});

console.log(cleaned);
// {
//   name: "John",
//   meta: { score: 0, active: true },
//   tags: ["dev"]
// }

TypeScript

import { deepClean, DeepCleanOptions } from "deep-cleaner-js";

const options: DeepCleanOptions = {
  removeNull: true,
  removeUndefined: true,
  cleanEmptyString: true,
  cleanZero: false,
};

const cleaned = deepClean({ user: "", id: 0 }, options);

⚙️ API Reference

deepClean(input, options?)

| Option | Type | Default | Description | |--------|------|----------|-------------| | removeNull | boolean | false | Removes properties or items that are null. | | removeUndefined | boolean | false | Removes properties or items that are undefined. | | cleanEmptyString | boolean | false | Removes empty strings (""). | | cleanZero | boolean | false | Removes zero (0) values. |

Returns: A deeply cleaned clone of the input.


🧠 Advanced Examples

Nested Objects

deepClean({
  user: {
    name: "",
    address: { city: null, zip: undefined },
    scores: [10, null, 0],
  },
}, {
  removeNull: true,
  removeUndefined: true,
  cleanEmptyString: true,
});

Output:

{ user: { scores: [10, 0] } }

Circular References

const a = { name: "A" };
a.self = a;
const result = deepClean(a);
console.log(result.self === result); // true ✅

Special Types Preserved

const data = {
  date: new Date(),
  regex: /abc/i,
  fn: () => {},
  buffer: Buffer.from("123"),
};

deepClean(data); // Keeps all intact ✅

⚖️ Comparison with Other Libraries

| Feature / Library | deep-cleaner-js | clean-deep | lodash | deepdash | |-------------------|:---------------:|:-----------:|:-------:|:---------:| | Removes null/undefined | ✅ | ✅ | ⚙️ (custom) | ⚙️ | | Removes empty strings | ✅ | ✅ | ⚙️ | ⚙️ | | Removes zero values | ✅ | ❌ | ⚙️ | ⚙️ | | Handles circular refs | ✅ | ❌ | ⚙️ | ⚙️ | | Preserves Date/Map/Set | ✅ | ❌ | ⚙️ | ⚙️ | | TypeScript support | ✅ | ⚠️ Partial | ⚠️ | ⚠️ | | Zero dependencies | ✅ | ❌ | ❌ | ❌ |

🧬 Architecture Overview

src/
 ├── index.ts          # Entry point
 └── types.ts          # TypeScript interfaces
 tests/
 ├── cleanData.test.js          # tests
  • Recursion is safe and stack-optimized
  • Circulars handled with WeakMap
  • Deep cloning ensures immutability

🧪 Testing

Over 50 comprehensive test cases ensure 100% coverage.

npm test

🤝 Contributing

Pull requests are welcome!
Open an issue to discuss major changes.

git clone https://github.com/MohammadRostami71/deep-cleaner-js.git
cd deep-cleaner-js
npm install
npm test

📄 License

MIT © 2025 — Created with ❤️ by Mohammad Rostami


🌐 Links