Skip to content

Commit 66258a6

Browse files
committed
added deleteNullProperties
1 parent 2836931 commit 66258a6

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

documentation/api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ The utility library provides general functionality, which makes it easy to retri
297297
* {mixed} **Breinify.UTL.getNested(obj, str1, str2, ...)**:<br/>
298298
Gets the value behind obj.str1.str2...
299299
300+
* **Breinify.UTL.deleteNullProperties(obj)**:<br/>
301+
Removed null and empty objects from the passed obj
302+
300303
* {string} **Breinify.UTL.uuid()**:<br/>
301304
Creates a uuid.
302305

src/BreinifyUtil.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,27 @@
499499
return new Date().toString();
500500
},
501501

502+
deleteNullProperties: function (input) {
503+
if (!$.isPlainObject(input)) {
504+
return input;
505+
}
506+
507+
for (var property in input) {
508+
if (input.hasOwnProperty(property)) {
509+
if (input[property] === null) {
510+
delete input[property];
511+
} else if ($.isPlainObject(input[property])) {
512+
this.deleteNullProperties(input[property]);
513+
if ($.isEmptyObject(input[property])) {
514+
delete input[property];
515+
}
516+
} else {
517+
// nothing to do
518+
}
519+
}
520+
}
521+
},
522+
502523
getNested: function (obj /*, level1, level2, ... levelN*/) {
503524
if (!$.isPlainObject(obj) || obj === null) {
504525
return null;

src/snippets/suffix-global.js.snippet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
localDateTime: function() { return new Date().toString(); },
102102
uuid: function() { return null; },
103103
getNested: function() { return null; },
104+
deleteNullProperties: function(data) { return data; },
104105
endsWith: function() { return false; },
105106
_jquery: function() { return null; }
106107
};

0 commit comments

Comments
 (0)