@pbbbl/clean
v0.13.0
Published
Fork of clean-deep by nonofgs with option to remove functions
Downloads
4
Readme
@pbbbl/clean
Forked clean-deep with new
fns
option for removing methods/functions. Traverses arrays and objects.
Removes functions, empty objects*, _arrays*, empty strings, NaN, null, and undefined values from objects. Does not alter the original object.
Installation
Download the repo to your root directory, and install via npm:
npm i -S clean-deep-pbbbl
Usage
Arguments
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: ''
|
| fns
| 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.
Example
const clean = 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: ["cheetah","lion","",null],
dog: true,
eel: false
},
set edit(key,value){
this[key] = value;
}
get secondIguana(){
return {
name: "jerry",
toes: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
}
}
};
object.edit.cat = ["house-cat"];
const output = clean(object);
/* output ==>
{
ant: "bug",
iguana: {
ant: "boz",
cat: ["cheetah","lion"],
dog: true,
eel: false
},
}
*/
Tests
$ npm test
Release
License
MIT