Skip to content

Instantly share code, notes, and snippets.

@rettuce
Last active October 20, 2022 07:52
Show Gist options
  • Save rettuce/4522a3a8c06e2f4aaae61d7cb289b7b0 to your computer and use it in GitHub Desktop.
Save rettuce/4522a3a8c06e2f4aaae61d7cb289b7b0 to your computer and use it in GitHub Desktop.

Revisions

  1. rettuce revised this gist Oct 20, 2022. No changes.
  2. rettuce revised this gist Oct 20, 2022. No changes.
  3. rettuce created this gist Oct 20, 2022.
    28 changes: 28 additions & 0 deletions jsonSave.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    fileSave( output_obj:Object ) {
    let saveFileOptions = {
    suggestedName: "xxxxxx.json",
    types: [
    {
    description: "JSON Files",
    accept: {
    "application/json": [".json"],
    },
    },
    ],
    };

    (async () => {
    let blob = new Blob([JSON.stringify(output_obj, null, " ")], {
    type: "application/json",
    });
    const handle = await window.showSaveFilePicker(saveFileOptions);
    await this.writeFile(handle, blob);
    console.log("save comp!!");
    })();
    }

    async writeFile(fileHandle, contents) {
    const writable = await fileHandle.createWritable();
    await writable.write(contents);
    await writable.close();
    }