-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27857 from teneeto/ts-migration/local-file-download
[No QA] [TS migration] Migrate 'localFileDownload' lib to TypeScript
- Loading branch information
Showing
4 changed files
with
18 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
src/libs/localFileDownload/index.js → src/libs/localFileDownload/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import * as FileUtils from '../fileDownload/FileUtils'; | ||
import LocalFileDownload from './types'; | ||
|
||
/** | ||
* Creates a Blob with the given fileName and textContent, then dynamically | ||
* creates a temporary anchor, just to programmatically click it, so the file | ||
* is downloaded by the browser. | ||
* | ||
* @param {String} fileName | ||
* @param {String} textContent | ||
*/ | ||
export default function localFileDownload(fileName, textContent) { | ||
const localFileDownload: LocalFileDownload = (fileName, textContent) => { | ||
const blob = new Blob([textContent], {type: 'text/plain'}); | ||
const url = URL.createObjectURL(blob); | ||
const link = document.createElement('a'); | ||
link.download = FileUtils.appendTimeToFileName(`${fileName}.txt`); | ||
link.href = url; | ||
link.click(); | ||
} | ||
}; | ||
|
||
export default localFileDownload; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type LocalFileDownload = (fileName: string, textContent: string) => void; | ||
|
||
export default LocalFileDownload; |