/**
 *@author       冯朝晖
 *@date         2020-02-10 19:11
 *@Copyright    天源迪科信息技术股份有限公司
 *@Description
 */
export function isTyIcon(icon) {
  const prefix = ['LiRa', 'LiRo', 'SuMo', 'LSMo']
  return prefix.some(function (item) {
    return icon.startsWith(item)
  })
}
export function dealIcon(options) {
  const arr = ['icon', 'leftIcon', 'closeIcon', 'voidIcon', 'rightIcon', 'activeIcon', 'inactiveIcon', 'tipIcon']
  for (let i = 0; i < arr.length; i++) {
    const key = arr[i]
    if (options.properties[key]) {
      const value = options.properties[key].value
      if (value && isTyIcon(value)) {
        options.properties[key].value = `prefix ht ht-${value}`
      }
      options.properties[key].observer = function (icon) {
        if (isTyIcon(icon)) {
          icon = `prefix ht ht-${icon}`
          this.setData({[key]: icon})
        }
      }
    }
  }
}
export function isDef(value) {
  return value !== undefined && value !== null
}
export function isNumber(value) {
  return /^\d+(\.\d+)?$/.test(value)
}
export function isObj(x) {
  const type = typeof x
  return x !== null && (type === 'object' || type === 'function')
}

export function addUnit(value) {
  if (!isDef(value)) {
    return undefined
  }

  value = String(value)
  return isNumber(value) ? `${value}px` : value
}
