Check empty object, array, string,.. for nodejs
npm install jsempty#JSEmpty for NodeJS
Check empty or null value of object, array, string,.. for NodeJS
$ npm install jsempty
var jsEmpty = require('jsempty');
jsEmpty(params [, options])
var params = {
name:'MrTam',
email:null
};
if(jsEmpty(params)){
console.log('is empty');
}else{
console.log('not empty');
}
// return is empty
`
Example 2
`
var params = {
name:'MrTam',
email:null
};
if(jsEmpty(params, ['email'])){
console.log('is empty');
}else{
console.log('not empty');
}
// return not empty
`
Example 3
`
var params = {
name:'MrTam',
email:null,
birthday: {
day: 10,
month: 8,
year: null
}
};
if(jsEmpty(params, ['email'])){
console.log('is empty');
}else{
console.log('not empty');
}
// return is empty
`
Example 4
`
var params = {
name:'MrTam',
email:null,
birthday: {
day: 10,
month: 8,
year: null
}
};
if(jsEmpty(params, {'email':'email', birthday:['year']})){
console.log('is empty');
}else{
console.log('not empty');
}
// return not empty
`
Example 5
`
var params = {
name:'MrTam',
email:null,
birthday: {
day: 10,
month: 8,
year: null
}
};
if(jsEmpty(params, ['email', 'year'])){
console.log('is empty');
}else{
console.log('not empty');
}
// return not empty
``