easy-file-saver

Very Easily Save a File

Usage no npm install needed!

<script type="module">
  import easyFileSaver from 'https://cdn.skypack.dev/easy-file-saver';
</script>

README

easy-file-saver

Very Easily Save a File

demo

https://danieljdufour.com/easy-file-saver/

install

npm install easy-file-saver

or

<script src="https://unpkg.com/easy-file-saver"></script>

usage

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" });

features

saveFile supports the following conversions: | data source | output formats | | ---------------- | -------------- | | 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, .txt |

any formats missing?

Post an issue at https://github.com/DanielJDufour/easy-file-saver or submit a Pull Request!