1.0.1 • Published 4 years ago

@seregpie/save-file v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

saveFile

saveFile(value, fileName)

Saves a file inside a browser.

argumentdescription
valueThe value to load from. Supported value types are String, Promise, URL, Blob, File, Response.
fileNameA string as the file name. If not specified, the file name is suggested in various ways.

Returns a promise.

setup

npm

npm i @seregpie/save-file

ES module

import saveFile from '@seregpie/save-file';

Node

let saveFile = require('@seregpie/save-file');

browser

<script src="https://unpkg.com/@seregpie/save-file"></script>

The function is globally available as saveFile.

usage

let text = [
  'Twinkle, twinkle, little star,',
  'How I wonder what you are!',
  'Up above the world so high,',
  'Like a diamond in the sky.'
].join('\n');
let blob = new Blob([text], {type: 'text/plain;charset=utf-8'});
await saveFile(blob, 'lullaby.txt');

let res = await fetch('/path/to/image.jpg', {
  method: 'GET',
  headers: {'Authorization': `Bearer ${token}`},
});
await saveFile(res);