1.0.1 • Published 5 years ago
@seregpie/save-file v1.0.1
saveFile
saveFile(value, fileName)Saves a file inside a browser.
| argument | description |
|---|---|
value | The value to load from. Supported value types are String, Promise, URL, Blob, File, Response. |
fileName | A 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-fileES 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);