File Saver
A simple fn to save a file to disk.
Table of Contents
Installation
You can install this package from NPM:
npm add save-as-file
Or with Yarn:
yarn add save-as-file
CDN
For CDN, you can use unpkg:
https://unpkg.com/save-as-file/dist/bundles/save-as-file.umd.min.js
The global namespace for save-as-file is saveAsFile
:
const json = JSON.stringify({ping: true});
const file = new File([json], {type: 'application/json'});
saveAsFile(file, 'test.json');
Usage
ES6
Save a File to disk:
import saveFile from 'save-as-file';
const json = JSON.stringify({ping: true});
const file = new File([json], {type: 'application/json'});
saveFile(file, 'test.json');
CommonJS
Save a File to disk:
const saveFile = require('save-as-file');
const json = JSON.stringify({ping: true});
const file = new File([json], {type: 'application/json'});
saveFile(file, 'test.json');
Browser Support
You can expect this lib to run wherever the href download attribute is supported.
Contribute
If you wish to contribute, please use the following guidelines: