Created
July 7, 2016 05:38
-
-
Save craigrbruce/c18a1ef69f9d1f07754ab580bac974c7 to your computer and use it in GitHub Desktop.
Revisions
-
craigrbruce created this gist
Jul 7, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ /** * Checks all fields of an object literal for values. * @param {Object} object - A POJO. * @param {Array<String>} omitProperies - An array of properties that you wish to omit from the checker e.g. "id". * @returns {Boolean} */ function isObjectDirty(object, omitProperties) { if(omitProperties) { object = _.omit(object, omitProperties); } return _.some(_.values(object), (value) => { if (_.isArray(value)) { return _.some(value, (item) => isObjectDirty(item, omitProperties)); } if (_.isPlainObject(value)) { return isObjectDirty(value, omitProperties); } return !!value }); }