'use strict';

function verifyNumberPercentage(val) {
  let v = val.replace(/(^\s*)|(\s*$)/g, "");
  v = v.replace(/[^\d]/g, "");
  v = v.replace(/^0/g, "");
  v = v.replace(/^[1-9]\d\d{1,3}$/, "100");
  return v;
}
function verifyNumberPercentageFloat(val) {
  let v = verifyNumberIntegerAndFloat(val);
  v = v.replace(/^[1-9]\d\d{1,3}$/, "100");
  v = v.replace(/^100\.$/, "100");
  return v;
}
function verifyNumberIntegerAndFloat(val) {
  let v = val.replace(/(^\s*)|(\s*$)/g, "");
  v = v.replace(/[^\d.]/g, "");
  v = v.replace(/^0{2}$/g, "0");
  v = v.replace(/^\./g, "");
  v = v.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  v = v.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
  return v;
}
function verifiyNumberInteger(val) {
  let v = val.replace(/(^\s*)|(\s*$)/g, "");
  v = v.replace(/[\.]*/g, "");
  v = v.replace(/(^0[\d]*)$/g, "0");
  v = v.replace(/^0\d$/g, "0");
  v = v.replace(/[^\d]/g, "");
  return v;
}
function verifyCnAndSpace(val) {
  let v = val.replace(/[\u4e00-\u9fa5\s]+/g, "");
  v = v.replace(/(^\s*)|(\s*$)/g, "");
  return v;
}
function verifyEnAndSpace(val) {
  let v = val.replace(/[a-zA-Z]+/g, "");
  v = v.replace(/(^\s*)|(\s*$)/g, "");
  return v;
}
function verifyAndSpace(val) {
  let v = val.replace(/(^\s*)|(\s*$)/g, "");
  return v;
}
function verifyNumberComma(val) {
  let v = verifyNumberIntegerAndFloat(val);
  v = v.toString().split(".");
  v[0] = v[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  v = v.join(".");
  return v;
}
function verifyTextColor(val, text = "", color = "red") {
  let v = text.replace(new RegExp(val, "gi"), `<span style='color: ${color}'>${val}</span>`);
  return v;
}
function verifyNumberCnUppercase(val, unit = "\u4EDF\u4F70\u62FE\u4EBF\u4EDF\u4F70\u62FE\u4E07\u4EDF\u4F70\u62FE\u5143\u89D2\u5206", v = "") {
  val += "00";
  let lookup = val.indexOf(".");
  if (lookup >= 0) val = val.substring(0, lookup) + val.substr(lookup + 1, 2);
  unit = unit.substr(unit.length - val.length);
  for (let i = 0; i < val.length; i++) {
    v += "\u96F6\u58F9\u8D30\u53C1\u8086\u4F0D\u9646\u67D2\u634C\u7396".substr(val.substr(i, 1), 1) + unit.substr(i, 1);
  }
  v = v.replace(/零角零分$/, "\u6574").replace(/零[仟佰拾]/g, "\u96F6").replace(/零{2,}/g, "\u96F6").replace(/零([亿|万])/g, "$1").replace(/零+元/, "\u5143").replace(/亿零{0,3}万/, "\u4EBF").replace(/^元/, "\u96F6\u5143");
  return v;
}
function verifyPhone(val) {
  if (!/^1[3456789][0-9]{9}$/.test(val)) return false;
  else return true;
}
function verifyTelPhone(val) {
  if (!/\d{3}-\d{8}|\d{4}-\d{7}/.test(val)) return false;
  else return true;
}
function verifyAccount(val) {
  if (!/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/.test(val)) return false;
  else return true;
}
function verifyPassword(val) {
  if (!/^[a-zA-Z]\w{5,15}$/.test(val)) return false;
  else return true;
}
function verifyPasswordPowerful(val) {
  if (!/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&\.*]+$)(?![\d!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*]{6,16}$/.test(val)) return false;
  else return true;
}
function verifyPasswordStrength(val) {
  let v = "";
  if (/^(?:\d+|[a-zA-Z]+|[!@#$%^&\.*]+){6,16}$/.test(val)) v = "\u5F31";
  if (/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*]{6,16}$/.test(val)) v = "\u4E2D";
  if (/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&\.*]+$)(?![\d!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*]{6,16}$/.test(val)) v = "\u5F3A";
  return v;
}
function verifyIPAddress(val) {
  if (!/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(val)) return false;
  else return true;
}
function verifyEmail(val) {
  if (!/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(val)) return false;
  else return true;
}
function verifyIdCard(val) {
  if (!/^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(val)) return false;
  else return true;
}
function verifyFullName(val) {
  if (!/^[\u4e00-\u9fa5]{1,6}(·[\u4e00-\u9fa5]{1,6}){0,2}$/.test(val)) return false;
  else return true;
}
function verifyPostalCode(val) {
  if (!/^[1-9][0-9]{5}$/.test(val)) return false;
  else return true;
}
function verifyUrl(val) {
  if (typeof val !== "string" || !val.trim()) return false;
  const strictUrlRegex = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4])))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
  return strictUrlRegex.test(val);
}
function verifyCarNum(val) {
  if (!/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/.test(
    val
  ))
    return false;
  else return true;
}
function judgementIdCard(idCard) {
  if (!(idCard == null ? void 0 : idCard.trim())) return null;
  let entity = {};
  let currentDate = /* @__PURE__ */ new Date();
  let yearNow = currentDate.getFullYear();
  let birthDateCode = idCard.substring(6, 14);
  let genderCode = parseInt(idCard.substring(16, 17), 10);
  entity.sex = genderCode % 2 === 0 ? 2 : 1;
  entity.age = yearNow - parseInt(birthDateCode.substring(0, 4));
  entity.birthday = `${birthDateCode.substring(0, 4)}-${birthDateCode.substring(4, 6)}-${birthDateCode.substring(6, 8)}`;
  return entity;
}

exports.judgementIdCard = judgementIdCard;
exports.verifiyNumberInteger = verifiyNumberInteger;
exports.verifyAccount = verifyAccount;
exports.verifyAndSpace = verifyAndSpace;
exports.verifyCarNum = verifyCarNum;
exports.verifyCnAndSpace = verifyCnAndSpace;
exports.verifyEmail = verifyEmail;
exports.verifyEnAndSpace = verifyEnAndSpace;
exports.verifyFullName = verifyFullName;
exports.verifyIPAddress = verifyIPAddress;
exports.verifyIdCard = verifyIdCard;
exports.verifyNumberCnUppercase = verifyNumberCnUppercase;
exports.verifyNumberComma = verifyNumberComma;
exports.verifyNumberIntegerAndFloat = verifyNumberIntegerAndFloat;
exports.verifyNumberPercentage = verifyNumberPercentage;
exports.verifyNumberPercentageFloat = verifyNumberPercentageFloat;
exports.verifyPassword = verifyPassword;
exports.verifyPasswordPowerful = verifyPasswordPowerful;
exports.verifyPasswordStrength = verifyPasswordStrength;
exports.verifyPhone = verifyPhone;
exports.verifyPostalCode = verifyPostalCode;
exports.verifyTelPhone = verifyTelPhone;
exports.verifyTextColor = verifyTextColor;
exports.verifyUrl = verifyUrl;
