{"size": 860, "ext": "js", "max_stars_repo_path": "server/utils/index.js", "max_stars_repo_name": "andrewgremlich/reflect", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/utils/index.js", "max_issues_repo_name": "andrewgremlich/reflect", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/utils/index.js", "max_forks_repo_name": "andrewgremlich/reflect", "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": 16.2264150943, "max_line_length": 63, "alphanum_fraction": 0.5686046512}
const md5 = require("md5");
const { v4: uuidv4 } = require("uuid");

const matchKeys = (a, b) => {
  let keysMatch = true;

  Object.keys(b).forEach((key) => {
    if (!Object.keys(a).includes(key)) {
      keysMatch = false;
    }
  });

  return keysMatch;
};

const unsuccessful = (message) => ({ message, loaded: false });

const successful = (message, options, additionalItems) => {
  let baseResponse = {
    message,
    loaded: true,
  };

  if (options?.makeMd5) {
    baseResponse = {
      ...baseResponse,
      md5: md5(baseResponse),
    };
  }

  if (options?.makeId) {
    baseResponse = {
      ...baseResponse,
      id: uuidv4(),
    };
  }

  if (additionalItems) {
    baseResponse = {
      ...baseResponse,
      ...additionalItems,
    };
  }

  return baseResponse;
};

module.exports = {
  matchKeys,
  successful,
  unsuccessful,
};
