File Downloader JS is a simple package that allows you to download a file from the browser
npm install file-downloader-js --save
yarn add file-downloader-js
import fileDownloader from "file-downloader-js";
function download(url: string, filename: string) {
fetch(url)
.then((res) => res.blob())
.then((blob) => {
fileDownloader(blob, filename);
});
}
import fileDownloader from "file-downloader-js";
import Axios from "axios";
function download(url: string, filename: string) {
Axios.get(url, {
responseType: "blob"
}).then((res) => {
fileDownloader(res.data, filename);
}
}
import fileDownloader from "file-downloader-js";
let dataRecords = [
["ID", "Name", "Age"],
[1, "Nour", 34],
[2, "Mila", 1]
];
let data = dataRecords.map((record) => record.join(",")).join("\r\n");
let filename = "data.csv";
let mime = "text/csv";
let bom = new Uint8Array([0xef, 0xbb, 0xbf]);
fileDownloader(data, filename, mime, bom);
Your contribution is welcome! If you find a bug or if you have a suggestion, please fork this repo and make a pull request. Thank you!