{"size": 1058, "ext": "js", "max_stars_repo_path": "server/api/utils/objectHelper.js", "max_stars_repo_name": "hashtag-cloudy/really-cloudy", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/api/utils/objectHelper.js", "max_issues_repo_name": "hashtag-cloudy/really-cloudy", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/api/utils/objectHelper.js", "max_forks_repo_name": "hashtag-cloudy/really-cloudy", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.0, "max_line_length": 81, "alphanum_fraction": 0.4877126654}
'use strict';
const _ = require('lodash');

const objectHelper = {

    findInObject: function (contact, filter) {

        const traverse = (obj, path = '', result = []) => {

            _.forOwn(obj, (value, key) => {

                const p = (path && (path + '.')) + key;
                if (filter(value, key, p)) {
                    result.push(p);
                }
                // traverse objects but not arrays
                // arrays are replaced entirely
                else if (_.isObject(value) && !_.isArray(value)) {
                    return traverse(value, p, result);
                }
            });

            return result;
        };

        return traverse(contact);
    },

    findArrays: function (obj) {

        return this.findInObject(obj, _.isArray);
    },

    findNulls: function (obj) {

        return this.findInObject(obj, _.isNull);
    },

    findDiff: function (obj1, obj2) {

        return this.findInObject(obj1, (value, key, path) => !_.has(obj2, path));
    }
};

module.exports = objectHelper;
