const onDebounce = (fn, delay) => {
  let timer;
  return function(...args) {
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(
      () => {
        typeof fn === "function" && fn.apply(null, [...args]);
        clearTimeout(timer);
      },
      delay > 0 ? delay : 100
    );
  };
};
const loadImage = (url) => {
  return new Promise((resolve, reject) => {
    const newImg = new Image();
    newImg.src = url;
    newImg.onerror = () => {
      reject("failure");
    };
    newImg.onload = (e) => {
      resolve(e.target);
    };
  });
};
const isTencentCosPic = (url) => {
  return url.includes("wlmvp-cos.weiling.cn");
};
const isBase64 = (str) => {
  return str.indexOf("data:") != -1 && str.indexOf("base64") != -1;
};
const getVantDateValue = (time) => {
  time = time instanceof Date ? time : new Date(parseInt(time));
  return [
    time.getFullYear(),
    `${time.getMonth() + 1 > 9 ? "" : "0"}${time.getMonth() + 1}`,
    `${time.getDate() + 1 > 9 ? "" : "0"}${time.getDate() + 1}`
  ];
};
export { isBase64 as a, getVantDateValue as g, isTencentCosPic as i, loadImage as l, onDebounce as o };
