Skip to content

Commit

Permalink
Adding the check for undefined, boolean and null string
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthikeyan Govindaraj committed Apr 5, 2018
1 parent 681cf80 commit 61d69cc
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 22 deletions.
89 changes: 68 additions & 21 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ function nestedEmptyCheck(obj) {
return true;
}

else if(obj === undefined) {
return true;
}

else if(typeof obj === "boolean"){
return false;
}

else if(typeof obj === "number"){
return false;
}

else if((typeof obj === "string") && obj != ''){
else if((typeof obj === "string") && obj.trim() != ''){
return false;
} else if((typeof obj === "string") && obj.trim() === ''){
return true;
}

else if(Array.isArray(obj)){
Expand Down
6 changes: 6 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ var i = {a: [], b:{ }};
var j = {a: [], b:{ aa:[11], bb:{}}};
var k ={ system: [ { a: [1,2], c: [5,6], }, 2]}
var l = {source: {}, type: "", pool: {}, acquireConnectionTimeout: '', system: [ { a: [], c: [] }, ] }
var m = {a:" "}
var n = {a:true}


test('isEmptyObj Testing', function(assert) {
assert.equal(isEmptyObj(a), true);
Expand All @@ -29,5 +32,8 @@ test('isEmptyObj Testing', function(assert) {
assert.equal(isEmptyObj(j), false);
assert.equal(isEmptyObj(k), false);
assert.equal(isEmptyObj(l), true);
assert.equal(isEmptyObj(m), true);
assert.equal(isEmptyObj(n), false);
assert.end()
})

0 comments on commit 61d69cc

Please sign in to comment.