clean-deep
Advanced tools
Comparing version 3.1.0 to 3.2.0
# Changelog | ||
## [v3.2.0](https://github.com/nunofgs/clean-deep/releases/tag/v3.2.0) (2019-12-04) | ||
- add cleanKeys option [\#35](https://github.com/nunofgs/clean-deep/pull/35) ([kalimantos](https://github.com/kalimantos)) | ||
- Fixed wrong wording [\#32](https://github.com/nunofgs/clean-deep/pull/32) ([lindekaer](https://github.com/lindekaer)) | ||
## [v3.1.0](https://github.com/nunofgs/clean-deep/releases/tag/v3.1.0) (2019-10-15) | ||
@@ -4,0 +8,0 @@ - Add custom values support [\#31](https://github.com/nunofgs/clean-deep/pull/31) ([nunofgs](https://github.com/nunofgs)) |
{ | ||
"name": "clean-deep", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Remove falsy, empty or nullable values from objects", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -28,2 +28,3 @@ # clean-deep | ||
----------------- | ------------- | ----------------------------------- | ||
_cleanKeys_ | _[]_ | Remove specific keys, ie: `['foo', 'bar', ' ']` | ||
_cleanValues_ | _[]_ | Remove specific values, ie: `['foo', 'bar', ' ']` | ||
@@ -34,3 +35,3 @@ _emptyArrays_ | _true_ | Remove empty arrays, ie: `[]` | ||
_nullValues_ | _true_ | Remove null values, ie: `null` | ||
_undefinedValues_ | _true_ | Remove null values, ie: `undefined` | ||
_undefinedValues_ | _true_ | Remove undefined values, ie: `undefined` | ||
@@ -37,0 +38,0 @@ _(Object)_: Returns the cleansed object. |
@@ -15,2 +15,3 @@ | ||
module.exports = function cleanDeep(object, { | ||
cleanKeys = [], | ||
cleanValues = [], | ||
@@ -24,5 +25,10 @@ emptyArrays = true, | ||
return transform(object, (result, value, key) => { | ||
// Exclude specific keys. | ||
if (cleanKeys.includes(key)) { | ||
return; | ||
} | ||
// Recurse into arrays and objects. | ||
if (Array.isArray(value) || isPlainObject(value)) { | ||
value = cleanDeep(value, { cleanValues, emptyArrays, emptyObjects, emptyStrings, nullValues, undefinedValues }); | ||
value = cleanDeep(value, { cleanKeys, cleanValues, emptyArrays, emptyObjects, emptyStrings, nullValues, undefinedValues }); | ||
} | ||
@@ -29,0 +35,0 @@ |
@@ -178,2 +178,28 @@ | ||
}); | ||
it('should remove specified keys if `cleanKeys` is passed', () => { | ||
const object = { | ||
foo: { | ||
alsoMe: { | ||
biz: 123, | ||
}, | ||
bar: undefined, | ||
biz: 123, | ||
qux: [ | ||
undefined, | ||
{}, | ||
true | ||
], | ||
removeMe: true, | ||
}, | ||
removeMe: true, | ||
}; | ||
expect(cleanDeep(object, { cleanKeys: ['removeMe', 'alsoMe'] })).toEqual({ | ||
foo: { | ||
biz: 123, | ||
qux: [true] | ||
} | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13814
239
79