Skip to content

Cleans an object or an array based on the rules(optional) provided

License

Notifications You must be signed in to change notification settings

jigarjain/object-clean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

object-clean

Cleans an object or an array based on the rules(optional) provided

Version

0.1.0

Installation

$ npm i object-clean --save

Example 1 (Default options)

var objectClean = require('object-clean');

var data = {
    name: 'Jigar Jain',
    gender: 'Male',
    age: null,
    hobbies: [],
    experience: [
        {
            company: 'XYZ',
            years: 1
        },
        {
            company: 'ABC',
            years: null
        },
        {}
    ],
    hasPets: false
}

var cleanedData = objectClean(data);
console.log(cleanedData);
// {
//    name: 'Jigar Jain',
//    gender: 'Male',
//    experience: [
//       {
//            company: 'XYZ',
//            years: 1
//        },
//        {
//            company: 'ABC'
//        }
//    ]
// }

Example 2 (Passing custom rules)

var objectClean = require('object-clean');

var data = {
    name: 'Jigar Jain',
    gender: 'Male',
    pets: null,
    hobbies: [],
    experience: [
        {
            company: 'XYZ',
            years: 1
        },
        {
            company: 'ABC',
            years: null
        },
        {}
    ],
    hasPets: false
}

var res = objectClean(data, [null, false]);

console.log(res);

// {
//     name: 'Jigar Jain',
//     gender: 'Male',
//     hobbies: [],
//     experience: [
//         {
//             company: 'XYZ',
//             years: 1
//         },
//         {
//             company: 'ABC'
//         },
//         {}
//     ]
// }

Test

$ git clone [email protected]:jigarjain/object-clean.git
$ cd object-clean/
$ npm i
$ npm test

ToDo:

  • Cloning the input data & working on it instead of directly modifying it

Contribute

Want to contribute? Great! Submit a pull request with a new feature, bug fix or enahncement. Make sure to run grunt eslint & grunt mochaTest before submitting any pull request

License

MIT

About

Cleans an object or an array based on the rules(optional) provided

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published