sculp-js 1.8.3 → 1.8.4

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.
Files changed (63) hide show
  1. package/lib/cjs/array.js +1 -1
  2. package/lib/cjs/async.js +1 -1
  3. package/lib/cjs/base64.js +1 -1
  4. package/lib/cjs/clipboard.js +1 -1
  5. package/lib/cjs/cloneDeep.js +1 -1
  6. package/lib/cjs/cookie.js +1 -1
  7. package/lib/cjs/date.js +1 -1
  8. package/lib/cjs/dom.js +1 -1
  9. package/lib/cjs/download.js +29 -5
  10. package/lib/cjs/easing.js +1 -1
  11. package/lib/cjs/file.js +1 -1
  12. package/lib/cjs/func.js +1 -1
  13. package/lib/cjs/index.js +1 -1
  14. package/lib/cjs/isEqual.js +1 -1
  15. package/lib/cjs/math.js +1 -1
  16. package/lib/cjs/number.js +1 -1
  17. package/lib/cjs/object.js +1 -1
  18. package/lib/cjs/path.js +1 -1
  19. package/lib/cjs/qs.js +1 -1
  20. package/lib/cjs/random.js +1 -1
  21. package/lib/cjs/string.js +1 -1
  22. package/lib/cjs/tooltip.js +1 -1
  23. package/lib/cjs/tree.js +1 -1
  24. package/lib/cjs/type.js +1 -1
  25. package/lib/cjs/unique.js +1 -1
  26. package/lib/cjs/url.js +1 -1
  27. package/lib/cjs/validator.js +1 -1
  28. package/lib/cjs/variable.js +3 -2
  29. package/lib/cjs/watermark.js +1 -1
  30. package/lib/cjs/we-decode.js +1 -1
  31. package/lib/es/array.js +1 -1
  32. package/lib/es/async.js +1 -1
  33. package/lib/es/base64.js +1 -1
  34. package/lib/es/clipboard.js +1 -1
  35. package/lib/es/cloneDeep.js +1 -1
  36. package/lib/es/cookie.js +1 -1
  37. package/lib/es/date.js +1 -1
  38. package/lib/es/dom.js +1 -1
  39. package/lib/es/download.js +30 -6
  40. package/lib/es/easing.js +1 -1
  41. package/lib/es/file.js +1 -1
  42. package/lib/es/func.js +1 -1
  43. package/lib/es/index.js +1 -1
  44. package/lib/es/isEqual.js +1 -1
  45. package/lib/es/math.js +1 -1
  46. package/lib/es/number.js +1 -1
  47. package/lib/es/object.js +1 -1
  48. package/lib/es/path.js +1 -1
  49. package/lib/es/qs.js +1 -1
  50. package/lib/es/random.js +1 -1
  51. package/lib/es/string.js +1 -1
  52. package/lib/es/tooltip.js +1 -1
  53. package/lib/es/tree.js +1 -1
  54. package/lib/es/type.js +1 -1
  55. package/lib/es/unique.js +1 -1
  56. package/lib/es/url.js +1 -1
  57. package/lib/es/validator.js +1 -1
  58. package/lib/es/variable.js +4 -3
  59. package/lib/es/watermark.js +1 -1
  60. package/lib/es/we-decode.js +1 -1
  61. package/lib/index.d.ts +11 -2
  62. package/lib/umd/index.js +31 -6
  63. package/package.json +1 -1
package/lib/cjs/array.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/async.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/base64.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/cookie.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/date.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -55,17 +55,41 @@ function downloadBlob(blob, filename, callback) {
55
55
  }
56
56
  /**
57
57
  * 根据URL下载文件(解决跨域a.download不生效问题)
58
+ *
59
+ * 可定制下载成功的状态码status(浏览器原生状态码)
60
+ *
61
+ * 支持下载操作成功、失败后的回调
58
62
  * @param {string} url
59
63
  * @param {string} filename
60
- * @param {Function} callback
64
+ * @param {CrossOriginDownloadParams} options
61
65
  */
62
- function crossOriginDownload(url, filename, callback) {
66
+ function crossOriginDownload(url, filename, options) {
67
+ const { successCode = 200, successCallback, failCallback } = type.isNullOrUnDef(options) ? { successCode: 200, successCallback: void 0, failCallback: void 0 } : options;
63
68
  const xhr = new XMLHttpRequest();
64
69
  xhr.open('GET', url, true);
65
70
  xhr.responseType = 'blob';
66
71
  xhr.onload = function () {
67
- if (xhr.status === 200)
68
- downloadBlob(xhr.response, filename, callback);
72
+ if (xhr.status === successCode)
73
+ downloadBlob(xhr.response, filename, successCallback);
74
+ else if (type.isFunction(failCallback)) {
75
+ const status = xhr.status;
76
+ const responseType = xhr.getResponseHeader('Content-Type');
77
+ if (type.isString(responseType) && responseType.includes('application/json')) {
78
+ const reader = new FileReader();
79
+ reader.onload = () => {
80
+ failCallback({ status, response: reader.result });
81
+ };
82
+ reader.readAsText(xhr.response);
83
+ }
84
+ else {
85
+ failCallback(xhr);
86
+ }
87
+ }
88
+ };
89
+ xhr.onerror = e => {
90
+ if (type.isFunction(failCallback)) {
91
+ failCallback({ status: 0, code: 'ERROR_CONNECTION_REFUSED' });
92
+ }
69
93
  };
70
94
  xhr.send();
71
95
  }
package/lib/cjs/easing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/file.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/math.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/number.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/object.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/qs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/random.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/string.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/tree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/unique.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -49,7 +49,8 @@ function parseVariableRegExp(leftMatchSymbol, rightMatchSymbol) {
49
49
  * default match symbol {} same as /{\s*([^{}\s]*)\s*}/g
50
50
  */
51
51
  function parseVarFromString(str, leftMatchSymbol = '{', rightMatchSymbol = '}') {
52
- return Array.from(str.matchAll(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol))).map(el => el?.[1]);
52
+ // @ts-ignore
53
+ return Array.from(str.matchAll(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol))).map(el => type.isNullOrUnDef(el) ? void 0 : el[1]);
53
54
  }
54
55
  /**
55
56
  * 替换字符串中的插值变量
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/array.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/async.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/base64.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/cookie.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/date.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,10 +1,10 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
- import { isFunction } from './type.js';
7
+ import { isFunction, isString, isNullOrUnDef } from './type.js';
8
8
  import { urlSetParams } from './url.js';
9
9
 
10
10
  /**
@@ -53,17 +53,41 @@ function downloadBlob(blob, filename, callback) {
53
53
  }
54
54
  /**
55
55
  * 根据URL下载文件(解决跨域a.download不生效问题)
56
+ *
57
+ * 可定制下载成功的状态码status(浏览器原生状态码)
58
+ *
59
+ * 支持下载操作成功、失败后的回调
56
60
  * @param {string} url
57
61
  * @param {string} filename
58
- * @param {Function} callback
62
+ * @param {CrossOriginDownloadParams} options
59
63
  */
60
- function crossOriginDownload(url, filename, callback) {
64
+ function crossOriginDownload(url, filename, options) {
65
+ const { successCode = 200, successCallback, failCallback } = isNullOrUnDef(options) ? { successCode: 200, successCallback: void 0, failCallback: void 0 } : options;
61
66
  const xhr = new XMLHttpRequest();
62
67
  xhr.open('GET', url, true);
63
68
  xhr.responseType = 'blob';
64
69
  xhr.onload = function () {
65
- if (xhr.status === 200)
66
- downloadBlob(xhr.response, filename, callback);
70
+ if (xhr.status === successCode)
71
+ downloadBlob(xhr.response, filename, successCallback);
72
+ else if (isFunction(failCallback)) {
73
+ const status = xhr.status;
74
+ const responseType = xhr.getResponseHeader('Content-Type');
75
+ if (isString(responseType) && responseType.includes('application/json')) {
76
+ const reader = new FileReader();
77
+ reader.onload = () => {
78
+ failCallback({ status, response: reader.result });
79
+ };
80
+ reader.readAsText(xhr.response);
81
+ }
82
+ else {
83
+ failCallback(xhr);
84
+ }
85
+ }
86
+ };
87
+ xhr.onerror = e => {
88
+ if (isFunction(failCallback)) {
89
+ failCallback({ status: 0, code: 'ERROR_CONNECTION_REFUSED' });
90
+ }
67
91
  };
68
92
  xhr.send();
69
93
  }
package/lib/es/easing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/file.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/isEqual.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/math.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/number.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/object.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/qs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/random.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/string.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/tooltip.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/tree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/unique.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,10 +1,10 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
- import { objectHas } from './type.js';
7
+ import { isNullOrUnDef, objectHas } from './type.js';
8
8
 
9
9
  /**
10
10
  * 去除字符串中重复字符
@@ -47,7 +47,8 @@ function parseVariableRegExp(leftMatchSymbol, rightMatchSymbol) {
47
47
  * default match symbol {} same as /{\s*([^{}\s]*)\s*}/g
48
48
  */
49
49
  function parseVarFromString(str, leftMatchSymbol = '{', rightMatchSymbol = '}') {
50
- return Array.from(str.matchAll(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol))).map(el => el?.[1]);
50
+ // @ts-ignore
51
+ return Array.from(str.matchAll(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol))).map(el => isNullOrUnDef(el) ? void 0 : el[1]);
51
52
  }
52
53
  /**
53
54
  * 替换字符串中的插值变量
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/index.d.ts CHANGED
@@ -332,13 +332,22 @@ declare function downloadHref(href: string, filename: string, callback?: Functio
332
332
  * @param {Function} callback
333
333
  */
334
334
  declare function downloadBlob(blob: Blob, filename: string, callback?: Function): void;
335
+ type CrossOriginDownloadParams = {
336
+ successCode?: number;
337
+ successCallback?: Function;
338
+ failCallback?: Function;
339
+ };
335
340
  /**
336
341
  * 根据URL下载文件(解决跨域a.download不生效问题)
342
+ *
343
+ * 可定制下载成功的状态码status(浏览器原生状态码)
344
+ *
345
+ * 支持下载操作成功、失败后的回调
337
346
  * @param {string} url
338
347
  * @param {string} filename
339
- * @param {Function} callback
348
+ * @param {CrossOriginDownloadParams} options
340
349
  */
341
- declare function crossOriginDownload(url: string, filename: string, callback?: Function): void;
350
+ declare function crossOriginDownload(url: string, filename: string, options?: CrossOriginDownloadParams): void;
342
351
  type FileType = 'json' | 'csv' | 'xls' | 'xlsx';
343
352
  /**
344
353
  * 将指定数据格式通过 A 链接的方式下载
package/lib/umd/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.8.3
2
+ * sculp-js v1.8.4
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1222,17 +1222,41 @@
1222
1222
  }
1223
1223
  /**
1224
1224
  * 根据URL下载文件(解决跨域a.download不生效问题)
1225
+ *
1226
+ * 可定制下载成功的状态码status(浏览器原生状态码)
1227
+ *
1228
+ * 支持下载操作成功、失败后的回调
1225
1229
  * @param {string} url
1226
1230
  * @param {string} filename
1227
- * @param {Function} callback
1231
+ * @param {CrossOriginDownloadParams} options
1228
1232
  */
1229
- function crossOriginDownload(url, filename, callback) {
1233
+ function crossOriginDownload(url, filename, options) {
1234
+ const { successCode = 200, successCallback, failCallback } = isNullOrUnDef(options) ? { successCode: 200, successCallback: void 0, failCallback: void 0 } : options;
1230
1235
  const xhr = new XMLHttpRequest();
1231
1236
  xhr.open('GET', url, true);
1232
1237
  xhr.responseType = 'blob';
1233
1238
  xhr.onload = function () {
1234
- if (xhr.status === 200)
1235
- downloadBlob(xhr.response, filename, callback);
1239
+ if (xhr.status === successCode)
1240
+ downloadBlob(xhr.response, filename, successCallback);
1241
+ else if (isFunction(failCallback)) {
1242
+ const status = xhr.status;
1243
+ const responseType = xhr.getResponseHeader('Content-Type');
1244
+ if (isString(responseType) && responseType.includes('application/json')) {
1245
+ const reader = new FileReader();
1246
+ reader.onload = () => {
1247
+ failCallback({ status, response: reader.result });
1248
+ };
1249
+ reader.readAsText(xhr.response);
1250
+ }
1251
+ else {
1252
+ failCallback(xhr);
1253
+ }
1254
+ }
1255
+ };
1256
+ xhr.onerror = e => {
1257
+ if (isFunction(failCallback)) {
1258
+ failCallback({ status: 0, code: 'ERROR_CONNECTION_REFUSED' });
1259
+ }
1236
1260
  };
1237
1261
  xhr.send();
1238
1262
  }
@@ -2629,7 +2653,8 @@
2629
2653
  * default match symbol {} same as /{\s*([^{}\s]*)\s*}/g
2630
2654
  */
2631
2655
  function parseVarFromString(str, leftMatchSymbol = '{', rightMatchSymbol = '}') {
2632
- return Array.from(str.matchAll(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol))).map(el => el?.[1]);
2656
+ // @ts-ignore
2657
+ return Array.from(str.matchAll(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol))).map(el => isNullOrUnDef(el) ? void 0 : el[1]);
2633
2658
  }
2634
2659
  /**
2635
2660
  * 替换字符串中的插值变量
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sculp-js",
3
- "version": "1.8.3",
3
+ "version": "1.8.4",
4
4
  "packageManager": "npm@8.19.2",
5
5
  "description": "js utils library, includes function library、class library",
6
6
  "scripts": {