text: /**
   * @desc 正则格式校验
   * @param value {string} required 校验值
   * @param rules {string | array} required 校验格式：ipv4、ipv4段(ipv4segment)、ipv6、域名(domain)、ipv6段(ipv6segment)
   * @todo 提供封装公共方法，如若新增规则添加至checkObj中
   * @example
   * validateFormat(value, ['ipv4', 'domain'])
   * */
  
  const checkRules = {
    'ipv4': '/^((\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$/',
    'ipv4segment': '/^((\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}(\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])([-]{1}(\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))$|^((\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}(\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])([\\/]{1}(1[6-9]|2[0-9]|3[0-2]))$/',
    'ipv6': '/^([\\da-fA-F]{1,4}:(:)?){3,7}([\\da-zA-Z]{1,4})$|^(\\[){1}([\\da-fA-F]{1,4}:(:)?){3,7}([\\da-zA-Z]{1,4})(\\]){1}(:[0-9]+)?(\\/[\\w- .\\/?%&=]*)?$|^(http(s)?:\\/\\/)+(\\[){1}([\\da-fA-F]{1,4}:(:)?){3,7}([\\da-zA-Z]{1,4})(\\]){1}(:[0-9]+)?(\\/[\\w- .\\/?%&=]*)?$/',
    'domain': '/^((http(s)?\\:\\/\\/)?(www\\.)?)?([\\w\\-]+\\.[\\w]+)+(\\:[0-9]+){0,1}(\\/[\\w\\#]*\\/?(\\-?\\w+)*)*((\\?|\\.).*)*$/',
    'ipv6segment': '/^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d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4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])$/',
    'router': '/^(\\/[\\w- .\\/?%&=]*)?$/'
  };
  export const validateFormat = (value, rules) => {
    if (Object.is(typeof rules, 'string')) {
      return eval(checkRules[rules]).test(value)
    } else if (Array.isArray(rules)) {
      return rules.some(val => eval(checkRules[val]).test(value))
    } else {
      throw TypeError('类型错误: string | array');
    }
  };
  
  export default validateFormat
  