-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# download | ||
|
||
Trigger browser download, supporting downloading via file `url`, `Blob`, `File`. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { download } from 'rattail' | ||
|
||
download('/hello.txt', 'hello.txt') | ||
download(new Blob(['hello']), 'hello.txt') | ||
download(new File(['helle'], 'hello.txt', { type: 'text/plain' }), 'hello.txt') | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| ---------- | ------------------------ | -------- | | ||
| `value` | `string \| Blob \| File` | | | ||
| `filename` | `string` | | |
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,20 @@ | ||
# download | ||
|
||
触发浏览器下载,支持通过 `文件地址`、`Blob`、`File`。 | ||
|
||
### 使用 | ||
|
||
```ts | ||
import { download } from 'rattail' | ||
|
||
download('/hello.txt', 'hello.txt') | ||
download(new Blob(['hello']), 'hello.txt') | ||
download(new File(['helle'], 'hello.txt', { type: 'text/plain' }), 'hello.txt') | ||
``` | ||
|
||
### 参数 | ||
|
||
| 参数 | 类型 | 默认值 | | ||
| ---------- | ------------------------ | ------ | | ||
| `value` | `string \| Blob \| File` | | | ||
| `filename` | `string` | | |
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,13 @@ | ||
import { isString } from '../general' | ||
|
||
export function download(val: string | Blob | File, filename: string = 'file') { | ||
const a = document.createElement('a') | ||
a.style.display = 'none' | ||
a.href = isString(val) ? val : URL.createObjectURL(val) | ||
a.download = filename | ||
|
||
document.body.appendChild(a) | ||
a.click() | ||
URL.revokeObjectURL(a.href) | ||
document.body.removeChild(a) | ||
} |
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