// 函数防抖  Function of the debounce

export const debounce = (fn, interval = 500) => {
  let timeout = null;
  return function () {
      clearTimeout(timeout);
      timeout = setTimeout(() => {
          fn.apply(this, arguments);
      }, interval);
  };
}

// 函数节流  Function of the throttle

export const throttle = (fn, interval = 500) => {
  let canRun = true;
  return function () {
      if (!canRun) return;
      canRun = false;
      setTimeout(() => {
          fn.apply(this, arguments);
          canRun = true;
      }, interval);
  };
}

export const isTrue = function (bool) {
  return new Promise((resolve,reject) => {
    if(bool) resolve()
  })
}
//
export const transformDate = (timestamp)=>{
    if (timestamp) {
        let _time = new Date(typeof timestamp === 'string' ? timestamp : timestamp * 1000).toDateString()
        _time = _time.split(' ')
        return _time[1]+ '. ' + _time[2] + ' ' + _time[3];
    }
    return ''
}
