Forked clean-deep with new
fn
option for removing functions/methods. Traverses arrays and objects.
Removes methods (functions) empty objects, arrays, empty strings, NaN, null, and undefined values from objects. Does not alter the original object.
Download the repo to your root directory, and install via npm:
npm i -S clean-deep-pbbbl
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: '' |
fn |
true | Remove functions, ie: ()=>{}, function(){} - ony in pbbbl-clean-deep |
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 = {
ant: "bug",
bear: "",
cat: [],
dog: {},
eel: null,
fox: undefined,
goat: ()=>{
return true
},
horse: function(){
return true,
},
iguana: {
ant: "boz",
bear: "",
cat: ["cheeta","lion","",null],
dog: true,
eel: false
},
};
const output = cleanDeep(object);
/* output ==>
{
ant: "bug",
iguana: {
ant: "boz",
cat: ["cheeta","lion"],
dog: true,
eel: false
},
}
*/
$ npm test
MIT