Extract `saveURLAsFile`

This commit is contained in:
Daniel Gasienica 2018-04-26 15:26:49 -04:00
parent 4c0c55082f
commit 307ab0d3a5
1 changed files with 17 additions and 0 deletions

17
ts/util/saveURLAsFile.ts Normal file
View File

@ -0,0 +1,17 @@
/**
* @prettier
*/
export const saveURLAsFile = ({
filename,
url,
document,
}: {
filename: string;
url: string;
document: Document;
}): void => {
const anchorElement = document.createElement('a');
anchorElement.href = url;
anchorElement.download = filename;
anchorElement.click();
};