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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  *
3
- * hsu-utils v0.0.35
3
+ * hsu-utils v0.0.36
4
4
  *
5
5
  * some front-end utils
6
6
  *
@@ -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>;
@@ -26,17 +26,20 @@ function downloadFileByUrl(url, fileName) {
26
26
  });
27
27
  }
28
28
  export default function downloadFile(file, fileName) {
29
- if (typeof file === 'string') {
30
- downloadFileByUrl(file, fileName);
31
- return;
32
- }
33
- const blob = Typeof(file) === 'blob' ? file : new Blob([file]);
34
- const downloadElement = document.createElement('a');
35
- const href = window.URL.createObjectURL(blob);
36
- downloadElement.href = href;
37
- downloadElement.download = decodeURIComponent(fileName || '');
38
- document.body.appendChild(downloadElement);
39
- downloadElement.click();
40
- document.body.removeChild(downloadElement);
41
- window.URL.revokeObjectURL(href);
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
- if (typeof file === 'string') {
71
- downloadFileByUrl(file, fileName);
72
- return;
73
- }
74
- var blob = (0, __1.Typeof)(file) === 'blob' ? file : new Blob([file]);
75
- var downloadElement = document.createElement('a');
76
- var href = window.URL.createObjectURL(blob);
77
- downloadElement.href = href;
78
- downloadElement.download = decodeURIComponent(fileName || '');
79
- document.body.appendChild(downloadElement);
80
- downloadElement.click();
81
- document.body.removeChild(downloadElement);
82
- window.URL.revokeObjectURL(href);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hsu-utils",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "description": "some front-end utils",
5
5
  "repository": "git@github.com:VitaTsui/hsu-utils.git",
6
6
  "author": "VitaHsu <vitahsu7@gmail.com>",