function regValue(type, integerNum, pointNum) {
  /**
   *  整数不限长度 ----integer
   *
   * 整数位数  integerNum
   *
   * 小数位数  pointNum
   *
   *
   */
  let regInteger = new RegExp("^(-)*(\\d{1," + integerNum + "}).*$");
  let regPoint = new RegExp(
    "^(-)*(\\d{1," + integerNum + "}).*\\.(\\d{1," + pointNum + "}).*$"
  );
  if (type == "integer") {
    return {
      formatter: (value) => {
        return typeof value == "string"
          ? value?.replace(/^(-)*(\d+).*$/, "$1$2")
          : value;
      },
      parser: (value) => {
        return typeof value == "string"
          ? value?.replace(/^(-)*(\d+).*$/, "$1$2")
          : value;
      },
    };
  } else if (!type) {
    return {
      formatter: (value) => {
        if (value.indexOf(".") == -1 || !pointNum) {
          return typeof value == "string"
            ? value?.replace(regInteger, "$1$2")
            : value;
        } else {
          return typeof value == "string"
            ? value?.replace(regPoint, "$1$2.$3")
            : value;
        }
      },
      parser: (value) => {
        if (value.indexOf(".") == -1 || !pointNum) {
          return typeof value == "string"
            ? value?.replace(regInteger, "$1$2")
            : value;
        } else {
          return typeof value == "string"
            ? value?.replace(regPoint, "$1$2.$3")
            : value;
        }
      },
    };
  }
}

export default regValue;
