deep-clean

1.0.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i deep-clean

Weekly Downloads

371

Version

1.0.2

License

ISC

Unpacked Size

3.63 kB

Total Files

4

Last publish

Collaborators

  • mfhevia