lib/validators.js
function vNumber(func, type, str, range) {
    let success   = true;
    let checkType = true;
    let errmsg;
    // 先验证类型
    if (!func(str)) {
      errmsg = localData.em_type({
        desc,
        str,
        type,
      });
      checkType = false;
      success = false;
    }
    // 再验证类型范围
    // if (range && range.min === undefined) {
    //   range.min = 0;
    // }
    if (range && (range.min === undefined || range.min < -NUMBER_MAX)) {
      range.min = -NUMBER_MAX;
    }
    if (range && (range.max === undefined || range.max > NUMBER_MAX)) {
      range.max = NUMBER_MAX;
    }
    if (success && checkType && range && (range.min !== undefined || range.max !== undefined)) {
      if (range && range.min !== undefined && range.min > Number(str)) {
        success = false;
      }
      if (success && range && range.max !== undefined && range.max < Number(str)) {
        success = false;
      }
      if (!success) {
        errmsg = localData.em_minmax({
          desc,
          type,
          opDesc: 'value',
          minOp : '>=',
          min   : range.min,
          maxOp : '<=',
          max   : range.max,
        });
      }
    }
    return { success, errmsg };
  }
function vNumber(func, type, str, range) {
    let success   = true;
    let checkType = true;
    let errmsg;
    // 先验证类型
    if (!func(str)) {
      errmsg = localData.em_type({
        desc,
        str,
        type,
      });
      checkType = false;
      success = false;
    }
    // 再验证类型范围
    // if (range && range.min === undefined) {
    //   range.min = 0;
    // }
    if (range && (range.min === undefined || range.min < -NUMBER_MAX)) {
      range.min = -NUMBER_MAX;
    }
    if (range && (range.max === undefined || range.max > NUMBER_MAX)) {
      range.max = NUMBER_MAX;
    }
    if (success && checkType && range && (range.min !== undefined || range.max !== undefined)) {
      if (range && range.min !== undefined && range.min > Number(str)) {
        success = false;
      }
      if (success && range && range.max !== undefined && range.max < Number(str)) {
        success = false;
      }
      if (!success) {
        errmsg = localData.em_minmax({
          desc,
          type,
          opDesc: 'value',
          minOp : '>=',
          min   : range.min,
          maxOp : '<=',
          max   : range.max,
        });
      }
    }
    return { success, errmsg };
  }
function vNumber ( func , type , str , range ) { let success = true ; let checkType = true ; let errmsg ; // 先验证类型 if ( ! func ( str ) ) { errmsg = localData . em_type ( { desc , str , type , } ) ; checkType = false ; success = false ; } // 再验证类型范围 // if (range && range.min === undefined) { //   range.min = 0; // } if ( range && ( range . min === undefined || range . min < - NUMBER_MAX ) ) { range . min = - NUMBER_MAX ; } if ( range && ( range . max === undefined || range . max > NUMBER_MAX ) ) { range . max = NUMBER_MAX ; } if ( success && checkType && range && ( range . min !== undefined || range . max !== undefined ) ) { if ( range && range . min !== undefined && range . min > Number ( str ) ) { success = false ; } if ( success && range && range . max !== undefined && range . max < Number ( str ) ) { success = false ; } if ( ! success ) { errmsg = localData . em_minmax ( { desc , type , opDesc : 'value' , minOp : '>=' , min : range . min , maxOp : '<=' , max : range . max , } ) ; } } return { success , errmsg } ; }
func to validator number
@param {Function} func = {v.isInt,v.isFloat,v.isNumeric}
@param {String} type = {int,float,number}
@param {String} str
@param {Object} range
@returns {boolean}
 /* eslint-disable no-shadow
func to validator number