hsu-utils 0.0.33 → 0.0.35

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.32
3
+ * hsu-utils v0.0.34
4
4
  *
5
5
  * some front-end utils
6
6
  *
@@ -10,7 +10,7 @@ export function toChineseNum(num, options = {}) {
10
10
  };
11
11
  const cnIntUnits = {
12
12
  lowercase: ['', '万', '亿', '兆'],
13
- uppercase: ['', '', '亿', '兆']
13
+ uppercase: ['', '', '', '兆']
14
14
  };
15
15
  const maxNum = 9999999999999999.9999999999999999;
16
16
  let integerNum = undefined;
@@ -1 +1 @@
1
- export default function downloadFile(file: ArrayBuffer | string, fileName: string): void;
1
+ export default function downloadFile(file: ArrayBuffer | string, fileName?: string): void;
@@ -10,12 +10,19 @@ function downloadFileByUrl(url, fileName) {
10
10
  downloadFileByLocalPath(url, fileName);
11
11
  return;
12
12
  }
13
- const downloadElement = document.createElement('a');
14
- downloadElement.href = url;
15
- downloadElement.download = decodeURI(fileName || '');
16
- document.body.appendChild(downloadElement);
17
- downloadElement.click();
18
- document.body.removeChild(downloadElement);
13
+ fetch(url)
14
+ .then((response) => response.arrayBuffer())
15
+ .then((arrayBuffer) => {
16
+ downloadFile(arrayBuffer, fileName);
17
+ })
18
+ .catch(() => {
19
+ const downloadElement = document.createElement('a');
20
+ downloadElement.href = url;
21
+ downloadElement.download = decodeURIComponent(fileName || '');
22
+ document.body.appendChild(downloadElement);
23
+ downloadElement.click();
24
+ document.body.removeChild(downloadElement);
25
+ });
19
26
  }
20
27
  export default function downloadFile(file, fileName) {
21
28
  if (typeof file === 'string') {
@@ -26,7 +33,7 @@ export default function downloadFile(file, fileName) {
26
33
  const downloadElement = document.createElement('a');
27
34
  const href = window.URL.createObjectURL(blob);
28
35
  downloadElement.href = href;
29
- downloadElement.download = decodeURI(fileName || '');
36
+ downloadElement.download = decodeURIComponent(fileName || '');
30
37
  document.body.appendChild(downloadElement);
31
38
  downloadElement.click();
32
39
  document.body.removeChild(downloadElement);
@@ -14,7 +14,7 @@ function toChineseNum(num, options) {
14
14
  };
15
15
  var cnIntUnits = {
16
16
  lowercase: ['', '万', '亿', '兆'],
17
- uppercase: ['', '', '亿', '兆']
17
+ uppercase: ['', '', '', '兆']
18
18
  };
19
19
  var maxNum = 9999999999999999.9999999999999999;
20
20
  var integerNum = undefined;
@@ -1 +1 @@
1
- export default function downloadFile(file: ArrayBuffer | string, fileName: string): void;
1
+ export default function downloadFile(file: ArrayBuffer | string, fileName?: string): void;
@@ -12,12 +12,19 @@ function downloadFileByUrl(url, fileName) {
12
12
  downloadFileByLocalPath(url, fileName);
13
13
  return;
14
14
  }
15
- var downloadElement = document.createElement('a');
16
- downloadElement.href = url;
17
- downloadElement.download = decodeURI(fileName || '');
18
- document.body.appendChild(downloadElement);
19
- downloadElement.click();
20
- document.body.removeChild(downloadElement);
15
+ fetch(url)
16
+ .then(function (response) { return response.arrayBuffer(); })
17
+ .then(function (arrayBuffer) {
18
+ downloadFile(arrayBuffer, fileName);
19
+ })
20
+ .catch(function () {
21
+ var downloadElement = document.createElement('a');
22
+ downloadElement.href = url;
23
+ downloadElement.download = decodeURIComponent(fileName || '');
24
+ document.body.appendChild(downloadElement);
25
+ downloadElement.click();
26
+ document.body.removeChild(downloadElement);
27
+ });
21
28
  }
22
29
  function downloadFile(file, fileName) {
23
30
  if (typeof file === 'string') {
@@ -28,7 +35,7 @@ function downloadFile(file, fileName) {
28
35
  var downloadElement = document.createElement('a');
29
36
  var href = window.URL.createObjectURL(blob);
30
37
  downloadElement.href = href;
31
- downloadElement.download = decodeURI(fileName || '');
38
+ downloadElement.download = decodeURIComponent(fileName || '');
32
39
  document.body.appendChild(downloadElement);
33
40
  downloadElement.click();
34
41
  document.body.removeChild(downloadElement);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hsu-utils",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "description": "some front-end utils",
5
5
  "repository": "git@github.com:VitaTsui/hsu-utils.git",
6
6
  "author": "VitaHsu <vitahsu7@gmail.com>",