{"size": 505, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "highhi/ifn", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "index.js", "max_issues_repo_name": "highhi/ifn", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "index.js", "max_forks_repo_name": "highhi/ifn", "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": 20.2, "max_line_length": 64, "alphanum_fraction": 0.6198019802}
const isEqual = require('lodash.isequal');

function isFunc(value) {
  return typeof value === 'function';
}

function ifn(conditions = [], defaultValue) {
  return value => {
    let result;

    for (const condition of conditions) {
      if (isEqual(value, condition[0])) {
        result = condition[1];
        break;
      }
    }

    if (isFunc(result)) return result();
    if (result) return result;
    return isFunc(defaultValue) ? defaultValue() : defaultValue;
  };
}

module.exports = ifn;
