1.0.7 • Published 2 years ago

file-downloader-js v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Introduction

File Downloader JS is a simple package that allows you to download a file from the browser

Install with npm

npm install file-downloader-js --save

Install with yarn

yarn add file-downloader-js

Basic usage

Binary download using fetch

import fileDownloader from "file-downloader-js";

function download(url: string, filename: string) {
  fetch(url)
    .then((res) => res.blob())
    .then((blob) => {
      fileDownloader(blob, filename);
    });
}

Binary download using axios

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

CSV Data download example

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

License

MIT

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago