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)