{"size": 1208, "ext": "js", "max_stars_repo_path": "node-with-config-service/src/config/util.js", "max_stars_repo_name": "teamzerolabs/config-service-reference", "max_stars_repo_stars_event_min_datetime": "2020-02-01T01:26:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-27T21:19:28.000Z", "max_issues_repo_path": "node-with-config-service/src/config/util.js", "max_issues_repo_name": "teamzerolabs/config-service-reference", "max_issues_repo_issues_event_min_datetime": "2021-05-11T01:59:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-22T10:28:40.000Z", "max_forks_repo_path": "node-with-config-service/src/config/util.js", "max_forks_repo_name": "teamzerolabs/config-service-reference", "max_forks_repo_forks_event_min_datetime": "2020-04-14T13:38:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-14T13:38:33.000Z"}
{"max_stars_count": 6, "max_issues_count": 4, "max_forks_count": 1, "avg_line_length": 23.2307692308, "max_line_length": 84, "alphanum_fraction": 0.696192053}
function isNullOrUndefined(value) {
  return value === undefined || value === null;
}

/**
 * Retrieves environment variable and throws if missing without default
 *
 * @param name name of environment variable
 * @param defaultVal
 */
function parseEnv(name, defaultVal) {
  let env = process.env[name];
  if (!env) {
    if (isNullOrUndefined(defaultVal)) {
      throw new Error(`Missing environment variable for ${name}`);
    }
    env = defaultVal;
  }

  return env;
}

/**
 * Retrieves environment variable as a number and throws if missing without default
 *
 * @param name name of environment variable
 * @param defaultVal
 */
function parseEnvNumber(name, defaultVal) {
  const number = parseInt(parseEnv(name, `${defaultVal}`));
  if (isNaN(number)) {
    throw new Error(`Bad environment variable for ${name}: Not a Number`);
  }
  return number;
}

/**
 * Retrieves environment variable as a boolean and throws if missing without default
 *
 * @param name name of environment variable
 * @param defaultVal
 */
function parseEnvBoolean(name, defaultVal) {
  return parseEnv(name, `${defaultVal}`).toLowerCase() === "true";
}

module.exports = {
  parseEnv,
  parseEnvNumber,
  parseEnvBoolean
};
