Very Easily Save a File
https://danieljdufour.com/easy-file-saver/
npm install easy-file-saver
or
<script src="https://unpkg.com/easy-file-saver"></script>
const saveFile = require("easy-file-saver");
const countries = [
{ name: "United States of America", abbreviation: "USA" },
{ name: "Canada", abbreviation: "CA" },
{ name: "Mexico", abbreviation: "MX" }
];
saveFile({ data: countries, debug: true, filename: "countries.csv" });
saveFile({ data: countries, debug: true, filename: "countries.tsv" });
saveFile({ data: countries, debug: true, filename: "countries.json" });
saveFile({ data: countries.map(c => `${c.name} (${c.abbreviation})`).join("\n"), debug: true, filename: "countries.txt" });
saveFile supports the following conversions:
data source | output formats |
---|---|
ArrayBuffer | .csv, .jpg, .json, .html, .pdf, .png, .tsv, .txt, .webp |
Array of Arrays | .csv, .json, .tsv |
Array of Objects | .csv, .json, .tsv |
Blob | .csv, .jpg, .json, .html, .png, .tsv, .txt, .webp |
Canvas | .jpg, .png, .webp |
Data URL | .csv, .jpg, .json, .html, .png, .tsv, .txt, .webp |
File | .csv, .jpg, .json, .html, .png, .tsv, .txt, .webp |
HTML Element | .html |
Image | .jpg, .png, .webp |
Object | .json |
String | .html, .js, .py, .txt |
Uint8Array | .csv, .jpg, .json, .html, .pdf, .png, .tsv, .txt, .webp |
Post an issue at https://github.com/DanielJDufour/easy-file-saver or submit a Pull Request!