{"size": 687, "ext": "js", "max_stars_repo_path": "common/forms/lib/matchCountryPhone.js", "max_stars_repo_name": "basarevych/next-dashboard", "max_stars_repo_stars_event_min_datetime": "2019-07-12T07:05:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T08:19:32.000Z", "max_issues_repo_path": "common/forms/lib/matchCountryPhone.js", "max_issues_repo_name": "basarevych/next-dashboard", "max_issues_repo_issues_event_min_datetime": "2019-11-14T10:55:27.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-10T04:44:43.000Z", "max_forks_repo_path": "common/forms/lib/matchCountryPhone.js", "max_forks_repo_name": "basarevych/next-dashboard", "max_forks_repo_forks_event_min_datetime": "2019-05-06T12:29:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-28T22:16:19.000Z"}
{"max_stars_count": 69, "max_issues_count": 6, "max_forks_count": 22, "avg_line_length": 24.5357142857, "max_line_length": 68, "alphanum_fraction": 0.4701601164}
const { allCountries, iso2Lookup } = require("../../src/countries");

module.exports = function(country, schema) {
  const info = allCountries[iso2Lookup[country]];
  const dialCode = info ? info.dialCode.split("") : [];
  const format = info && info.format;
  const re =
    !!format &&
    "^" +
      format
        .split("")
        .map(char =>
          /[0-9]/.test(char)
            ? char
            : char === "."
            ? dialCode.length
              ? dialCode.shift()
              : "\\d"
            : "\\" + char
        )
        .join("") +
      "$";
  return schema.matches(
    new RegExp(re || `^\\+${dialCode.join("")}`),
    "ERROR_INVALID_PHONE"
  );
};
