'use strict';

"use strict";
function fileToBase64(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.addEventListener("load", (evt) => resolve(evt.target.result));
    reader.addEventListener("error", reject);
    reader.readAsDataURL(file);
  });
}
function formatFileSize(size) {
  if (size < 1024) {
    return `${size}Bytes`;
  } else if (size < 1024 * 1024) {
    return `${(size / 1024).toFixed(0)}KB`;
  } else if (size < 1024 * 1024 * 1024) {
    return `${(size / 1024 / 1024).toFixed(0)}MB`;
  } else {
    return `${(size / 1024 / 1024 / 1024).toFixed(0)}GB`;
  }
}
function dataURLtoBlob(base64Buf) {
  const arr = base64Buf.split(",");
  const typeItem = arr[0];
  const mime = typeItem.match(/:(.*?);/)[1];
  const bstr = window.atob(arr[1]);
  let n = bstr.length;
  const u8arr = new Uint8Array(n);
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n);
  }
  return new Blob([u8arr], { type: mime });
}
const matchAcceptType = (file, accept) => {
  if (!accept) return true;
  const fileName = file.name.toLowerCase();
  const fileType = file.type.toLowerCase();
  const acceptTypes = accept.toLowerCase().split(",").map((type) => type.trim());
  return acceptTypes.some((acceptType) => {
    if (acceptType.startsWith(".")) {
      return fileName.endsWith(acceptType);
    }
    if (acceptType.includes("/*")) {
      const [mainType] = acceptType.split("/");
      const [fileMainType] = fileType.split("/");
      return mainType === fileMainType;
    }
    if (acceptType.includes("/")) {
      return fileType === acceptType;
    }
    return fileName.endsWith(`.${acceptType}`);
  });
};

exports.dataURLtoBlob = dataURLtoBlob;
exports.fileToBase64 = fileToBase64;
exports.formatFileSize = formatFileSize;
exports.matchAcceptType = matchAcceptType;
//# sourceMappingURL=file.js.map
