{"size": 780, "ext": "js", "max_stars_repo_path": "util/index.js", "max_stars_repo_name": "arthurkao/express-mongoose-rest-api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "util/index.js", "max_issues_repo_name": "arthurkao/express-mongoose-rest-api", "max_issues_repo_issues_event_min_datetime": "2020-08-29T03:10:15.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-29T03:31:34.000Z", "max_forks_repo_path": "util/index.js", "max_forks_repo_name": "arthurkao/express-mongoose-rest-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 5, "max_forks_count": null, "avg_line_length": 26.8965517241, "max_line_length": 112, "alphanum_fraction": 0.5320512821}
module.exports = {
  parseExpressQueryObj : (obj) => {
    let result = {};
    if(obj.constructor != Object || Object.keys(obj).length === 0) return result;
    Object.keys(obj).map(key => {
      let value = obj[key];
      try {
        value = JSON.parse(value);
      }catch(err){
        //error parsing o[key]. skip
        value = obj[key];
      }
      result[key] = value;
    });
    return result;
  },
  filterObjByKeys: (obj, keys = []) => {
    if(keys.length === 0){
      keys = Object.keys(obj);
    }
    return Object.keys(obj).filter(key => keys.includes(key)).reduce((o, key) => ({...o, [key]: obj[key]}), {});
  },
  isMongoId: (id) => {
    const checkForHexRegExp = new RegExp("^[0-9a-fA-F]{24}$");
    return !!id && checkForHexRegExp.test(id);
  }
};

