/**
 * Created by PanJiaChen on 16/11/18.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  // const valid_map = ['admin', 'editor']
  // return valid_map.indexOf(str.trim()) >= 0
  return true
}

/**
 * 校验手机号
 * @param {string} phone
 * @returns {Boolean}
 */
export function validPhone(phone) {
  return /^1[3456789]\d{9}$/.test(phone)
}

/**
 * 校验邮箱
 * @param {string} mail
 * @returns {Boolean}
 */
export function validMail(mail) {
  return /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(mail)
}

/**
 * 校验是否是数字,包含负数
 * @param {string} number
 * @returns {Boolean}
 */
export function validNumber(number) {
  return /^-?\d+(\.\d+)?$/.test(number)
}

/**
 * 校验是否是汉字
 * @param {string} character
 * @returns {Boolean}
 */
export function validCharacter(character) {
  return /^[\u4E00-\u9FA5]+$/.test(character)
}

/**
 * 校验是否是null undefined ''
 * @param {null undefined '' } value
 * @returns {Boolean}
 */
export function validSpecialEmpty(value) {
  if (value === null || value === undefined || value === '') {
    return true
  } else {
    return false
  }
}
