Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
clean-deep
Advanced tools
The clean-deep npm package is used to deeply clean JavaScript objects by removing properties with specific values such as null, undefined, empty strings, empty arrays, and empty objects. This is useful for sanitizing data before processing or sending it over a network.
Remove null and undefined values
This feature removes properties with null and undefined values from the object.
const cleanDeep = require('clean-deep');
const obj = { a: null, b: undefined, c: 'value' };
const cleanedObj = cleanDeep(obj);
console.log(cleanedObj); // Output: { c: 'value' }
Remove empty strings
This feature removes properties with empty string values from the object.
const cleanDeep = require('clean-deep');
const obj = { a: '', b: 'value' };
const cleanedObj = cleanDeep(obj);
console.log(cleanedObj); // Output: { b: 'value' }
Remove empty arrays
This feature removes properties with empty array values from the object.
const cleanDeep = require('clean-deep');
const obj = { a: [], b: [1, 2, 3] };
const cleanedObj = cleanDeep(obj);
console.log(cleanedObj); // Output: { b: [1, 2, 3] }
Remove empty objects
This feature removes properties with empty object values from the object.
const cleanDeep = require('clean-deep');
const obj = { a: {}, b: { c: 'value' } };
const cleanedObj = cleanDeep(obj);
console.log(cleanedObj); // Output: { b: { c: 'value' } }
Custom values to remove
This feature allows you to specify custom values to be removed from the object.
const cleanDeep = require('clean-deep');
const obj = { a: 'remove me', b: 'keep me' };
const cleanedObj = cleanDeep(obj, { cleanValues: ['remove me'] });
console.log(cleanedObj); // Output: { b: 'keep me' }
The omit-deep package is used to deeply omit specified properties from an object. Unlike clean-deep, which removes properties based on their values, omit-deep removes properties based on their keys.
Lodash is a utility library that provides a wide range of functions for manipulating objects, arrays, and other data structures. It includes functions like _.omit and _.omitBy, which can be used to remove properties from objects, but it is more general-purpose compared to clean-deep.
The deep-clean package is similar to clean-deep in that it removes properties with specific values from objects. However, it may have different default behaviors and options for customization.
Removes empty objects, arrays, empty strings, NaN, null and undefined values from objects. Does not alter the original object.
As of version 3.0.0, clean-deep traverses arrays as well as objects.
Install the package via npm
:
$ npm install clean-deep --save
object
(Object): The source object.[options]
(Object): An optional object with the following options:Option | Default value | Description |
---|---|---|
cleanKeys | [] | Remove specific keys, ie: ['foo', 'bar', ' '] |
cleanValues | [] | Remove specific values, ie: ['foo', 'bar', ' '] |
emptyArrays | true | Remove empty arrays, ie: [] |
emptyObjects | true | Remove empty objects, ie: {} |
emptyStrings | true | Remove empty strings, ie: '' |
NaNValues | false | Remove NaN values, ie: NaN |
nullValues | true | Remove null values, ie: null |
undefinedValues | true | Remove undefined values, ie: undefined |
(Object): Returns the cleansed object.
const cleanDeep = require('clean-deep');
const object = {
bar: {},
baz: null,
biz: 'baz',
foo: '',
net: [],
nit: undefined,
qux: {
baz: 'boz',
txi: ''
}
};
cleanDeep(object);
// => { biz: 'baz', qux: { baz: 'boz' } }
$ npm test
npm version [<newversion> | major | minor | patch] -m "Release %s"
MIT
v3.4.0 (2020-08-19)
FAQs
Remove falsy, empty or nullable values from objects
The npm package clean-deep receives a total of 188,939 weekly downloads. As such, clean-deep popularity was classified as popular.
We found that clean-deep demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.