
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
deep-cleaner-es6
Advanced tools
Delete nested key-value pairs on an object with a provided key, or remove undefined, null, empty strings, empty arrays, and empty nested objects from an object.
Delete nested key-value pairs by a specified key or remove empty objects, empty strings, null, and undefined values from an object.
This module was created primarily with JSON in mind. The module is light-weight and dependency free.
Compiled for ES6 compatibility
npm install --save deep-cleaner
To remove empty values on an object:
> var cleaner = require('deep-cleaner');
> var obj = {
... a: 'value',
... emptyString: '',
... emptyArray: [],
... emptyObject: {},
... isNull: null,
... isUndefined: undefined
... b: {
... a: 'nother value',
... anotherEmptyString: '',
... arr: [
... {c: null},
... {d: 'value'}
... ]
... }
... }
> cleaner(obj);
> console.log(obj);
{ aValue: 'value', b: { a: 'nother value', arr: [ {}, {d: 'value'} ] } }
To remove a key-value pair, pass in the name of the key as the second parameter:
> var dirtyObject = {
... a: {
... b: {
... dirty: "value"
... }
... },
... dirty: "value",
... some_list: [
... {
... dirty: "value",
... clean: "value"
... },
... {
... dirty: "value",
... clean: "value"
... },
... {
... dirty: "value",
... clean: "value"
... },
... ]
... }
> cleaner(dirtyObject, 'dirty');
> console.log(dirtyObject);
{ a: { b: {} }, some_list: [ {
clean: "value" }, { clean: "value" }, { clean: "value" } ] }
You can also pass in an array of keys.
> var obj = {
... a: {
... a: 'foo',
... b: 'bar',
... c: 'baz'
... },
... b: 'quux',
... c: 'plugh',
... d: 'grault'
... }
> cleaner(obj, ['b','c']);
> console.log(obj);
{ a: { a: 'foo' }, d: 'grault' }
As of v1.2.0, deep-cleaner also works on objects with circular references!
> var foo = { bar: null, baz: '' };
> foo.bar = foo;
> cleaner(foo);
> console.log(foo);
{ bar: [Circular] }
deepCleaner(obj[, key])Removes "empty" values from obj. A Value is considered "empty" if it is:
objObject - The object to be cleaned.
keyString?|Array? - A key or array of keys to be removed from obj. If key is not
specified, then deepCleaner will default to removing empty values, otherwise, only
obj[key] will be removed (or obj[key[0]],..., obj[key[n]] if key is an array of keys).
Pull requests are welcome! If you notice a bug or want to add a feature, please feel free to contribute to this project.
Here are a few guidelines you should follow.
development branch. A new contribution might prompt me to make additional changes that I'd like packaged together in a single PR to master.Notice a bug but don't have time to fix it? Submit an issue! I strive to keep this package well maintained.
run npm test.
FAQs
Delete nested key-value pairs on an object with a provided key, or remove undefined, null, empty strings, empty arrays, and empty nested objects from an object.
We found that deep-cleaner-es6 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.