function FileUtils() {
  function createJsonFile(jsonData, fileName) {
    const json = JSON.stringify(jsonData, null, 2);
    const file = new File([json], fileName, {
      type: "text/json;charset=utf-8",
    });
    return file;
  }

  function downloadFile(file) {
    console.log(file)
    const url = URL.createObjectURL(file);
    const link = document.createElement("a");
    link.setAttribute("href", url);
    link.setAttribute("download", file.name);
    link.style.visibility = "hidden";
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
  }

  return {
    createJsonFile,
    downloadFile,
  };
}

FileUtils = new FileUtils();

export default FileUtils;
