DEV Community

Manu Kumar Pal
Manu Kumar Pal

Posted on

🧹 Clean Your JavaScript Objects Like a Pro with clean-object-keys

Hey community! πŸ‘‹ If you're building or maintaining JavaScript apps and want clean, efficient, and valid payloads, check out clean-object-keys β€” a tiny utility to remove null, undefined, and empty strings ("") from your objects.

πŸ” What It Does

It cleans up your objects by removing noise before you send them to APIs, save configs, or process data.

const { cleanObject } = require("clean-object-keys");

const messy = {
  name: "Alex",
  email: "",
  phone: undefined,
  age: null,
};

const clean = cleanObject(messy);
// Output: { name: "Alex" }

Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Why Devs Love It

βœ… Clean request payloads
βœ… Sanitize form inputs
βœ… Works with nested objects
βœ… No dependencies
βœ… Super lightweight

πŸ“¦ Install & Use

npm install clean-object-keys
Enter fullscreen mode Exit fullscreen mode

πŸ”— NPM Package: https://www.npmjs.com/package/clean-object-keys

Then import and go!

const { cleanObject } = require("clean-object-keys");
Enter fullscreen mode Exit fullscreen mode

🀝 Contribute or Star

Created by Manu Kumar Pal, this package is open-source and ready for your PRs, ideas, or stars ⭐.

Top comments (0)