Skip to content

mfhevia/deep-clean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deep clean

Simple library to recursively clean an object. The returned object will not have null values, empty strings or empty objects. Original object will not be modify.

Installation:

npm install deep-clean --save

Usage example:

const cleaner = require('deep-clean');

const objToClean = {
    key1: { 
        str: 'str' 
    },
    key2: { 
        emptyObj: {},
        emptyStr: '',
        valid: 43,
        nullValue: null,
        deepEmptyObj: { 
            empty: {}
        }
    },
    key3: 14,
    key4: { 
        a: {}
    }
};

const cleanedObj = cleaner(objToTest);

/* 
    cleanedObj will be a copy obj to Test but without {}, '' or null properties
    cleanedObj = {
        key1: { 
            str: 'str' 
        },
        key2: {
            valid: 43
        },
        key3: 14 
    }
*/

Testing

npm run test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published