hsu-utils 0.0.36 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hsu-utils.js +2 -2
- package/dist/hsu-utils.min.js +1 -1
- package/dist/hsu-utils.min.js.LICENSE.txt +1 -1
- package/es/DownloadFile/index.d.ts +1 -1
- package/es/DownloadFile/index.js +16 -13
- package/lib/DownloadFile/index.d.ts +1 -1
- package/lib/DownloadFile/index.js +25 -13
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
export default function downloadFile(file: ArrayBuffer | Blob | string, fileName?: string): void
|
1
|
+
export default function downloadFile(file: ArrayBuffer | Blob | string, fileName?: string): Promise<void>;
|
package/es/DownloadFile/index.js
CHANGED
@@ -26,17 +26,20 @@ function downloadFileByUrl(url, fileName) {
|
|
26
26
|
});
|
27
27
|
}
|
28
28
|
export default function downloadFile(file, fileName) {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
30
|
+
if (typeof file === 'string') {
|
31
|
+
yield downloadFileByUrl(file, fileName);
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
const blob = Typeof(file) === 'blob' ? file : new Blob([file]);
|
35
|
+
const downloadElement = document.createElement('a');
|
36
|
+
const href = window.URL.createObjectURL(blob);
|
37
|
+
downloadElement.href = href;
|
38
|
+
downloadElement.download = decodeURIComponent(fileName || '');
|
39
|
+
document.body.appendChild(downloadElement);
|
40
|
+
downloadElement.click();
|
41
|
+
document.body.removeChild(downloadElement);
|
42
|
+
window.URL.revokeObjectURL(href);
|
43
|
+
}
|
44
|
+
});
|
42
45
|
}
|
@@ -1 +1 @@
|
|
1
|
-
export default function downloadFile(file: ArrayBuffer | Blob | string, fileName?: string): void
|
1
|
+
export default function downloadFile(file: ArrayBuffer | Blob | string, fileName?: string): Promise<void>;
|
@@ -67,18 +67,30 @@ function downloadFileByUrl(url, fileName) {
|
|
67
67
|
});
|
68
68
|
}
|
69
69
|
function downloadFile(file, fileName) {
|
70
|
-
|
71
|
-
|
72
|
-
return
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
71
|
+
var blob, downloadElement, href;
|
72
|
+
return __generator(this, function (_a) {
|
73
|
+
switch (_a.label) {
|
74
|
+
case 0:
|
75
|
+
if (!(typeof file === 'string')) return [3, 2];
|
76
|
+
return [4, downloadFileByUrl(file, fileName)];
|
77
|
+
case 1:
|
78
|
+
_a.sent();
|
79
|
+
return [3, 3];
|
80
|
+
case 2:
|
81
|
+
blob = (0, __1.Typeof)(file) === 'blob' ? file : new Blob([file]);
|
82
|
+
downloadElement = document.createElement('a');
|
83
|
+
href = window.URL.createObjectURL(blob);
|
84
|
+
downloadElement.href = href;
|
85
|
+
downloadElement.download = decodeURIComponent(fileName || '');
|
86
|
+
document.body.appendChild(downloadElement);
|
87
|
+
downloadElement.click();
|
88
|
+
document.body.removeChild(downloadElement);
|
89
|
+
window.URL.revokeObjectURL(href);
|
90
|
+
_a.label = 3;
|
91
|
+
case 3: return [2];
|
92
|
+
}
|
93
|
+
});
|
94
|
+
});
|
83
95
|
}
|
84
96
|
exports.default = downloadFile;
|