util-helpers 4.16.0 → 4.16.2

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 (91) hide show
  1. package/README.md +3 -1
  2. package/dist/util-helpers.js +60 -46
  3. package/dist/util-helpers.js.map +1 -1
  4. package/dist/util-helpers.min.js +1 -1
  5. package/dist/util-helpers.min.js.map +1 -1
  6. package/esm/blobToDataURL.js +2 -2
  7. package/esm/calculateCursorPosition.js +2 -2
  8. package/esm/dataURLToBlob.js +1 -1
  9. package/esm/download.js +31 -16
  10. package/esm/fileReader.js +2 -2
  11. package/esm/filterTree.js +1 -3
  12. package/esm/findTreeNode.js +1 -3
  13. package/esm/findTreeNodes.js +1 -3
  14. package/esm/findTreeSelect.js +1 -3
  15. package/esm/index.js +2 -2
  16. package/esm/interface.doc.js +3 -2
  17. package/esm/isBankCard.js +1 -1
  18. package/esm/isBusinessLicense.js +1 -1
  19. package/esm/isChinese.js +3 -3
  20. package/esm/isHMCard.js +1 -1
  21. package/esm/isIdCard.js +2 -2
  22. package/esm/isPassport.js +1 -1
  23. package/esm/isPassword.js +2 -2
  24. package/esm/isSocialCreditCode.js +1 -1
  25. package/esm/isSwiftCode.js +1 -1
  26. package/esm/isTWCard.js +1 -1
  27. package/esm/isUrl.js +1 -1
  28. package/esm/isVehicle.js +1 -1
  29. package/esm/listToTree.js +1 -3
  30. package/esm/normalizeString.js +1 -1
  31. package/esm/parseIdCard.js +2 -5
  32. package/esm/safeDate.js +1 -1
  33. package/esm/setDataURLPrefix.js +2 -2
  34. package/esm/transformFieldNames.js +1 -3
  35. package/esm/treeToList.js +1 -3
  36. package/esm/utils/config.js +1 -1
  37. package/esm/validatePassword.js +1 -1
  38. package/lib/blobToDataURL.js +2 -2
  39. package/lib/calculateCursorPosition.js +2 -3
  40. package/lib/dataURLToBlob.js +1 -1
  41. package/lib/divide.js +1 -1
  42. package/lib/download.js +32 -17
  43. package/lib/fileReader.js +2 -2
  44. package/lib/findTreeNode.js +1 -1
  45. package/lib/findTreeNodes.js +1 -1
  46. package/lib/findTreeSelect.js +1 -1
  47. package/lib/formatMoney.js +2 -2
  48. package/lib/interface.doc.js +3 -2
  49. package/lib/isBankCard.js +1 -1
  50. package/lib/isBusinessLicense.js +1 -1
  51. package/lib/isChinese.js +3 -3
  52. package/lib/isHMCard.js +1 -1
  53. package/lib/isIdCard.js +2 -2
  54. package/lib/isPassport.js +1 -1
  55. package/lib/isPassword.js +2 -2
  56. package/lib/isSocialCreditCode.js +1 -1
  57. package/lib/isSwiftCode.js +1 -1
  58. package/lib/isTWCard.js +1 -1
  59. package/lib/isUrl.js +1 -2
  60. package/lib/isVehicle.js +1 -1
  61. package/lib/minus.js +1 -1
  62. package/lib/normalizeString.js +1 -1
  63. package/lib/parseIdCard.js +2 -2
  64. package/lib/plus.js +1 -1
  65. package/lib/safeDate.js +1 -1
  66. package/lib/setDataURLPrefix.js +2 -2
  67. package/lib/times.js +1 -1
  68. package/lib/transformFieldNames.js +1 -1
  69. package/lib/utils/config.js +1 -1
  70. package/lib/validatePassword.js +1 -1
  71. package/package.json +14 -14
  72. package/types/blobToDataURL.d.ts +2 -2
  73. package/types/calculateCursorPosition.d.ts +2 -2
  74. package/types/dataURLToBlob.d.ts +1 -1
  75. package/types/download.d.ts +6 -5
  76. package/types/isBankCard.d.ts +1 -1
  77. package/types/isBusinessLicense.d.ts +1 -1
  78. package/types/isChinese.d.ts +3 -3
  79. package/types/isHMCard.d.ts +1 -1
  80. package/types/isIdCard.d.ts +2 -2
  81. package/types/isPassport.d.ts +1 -1
  82. package/types/isPassword.d.ts +2 -2
  83. package/types/isSocialCreditCode.d.ts +1 -1
  84. package/types/isSwiftCode.d.ts +1 -1
  85. package/types/isTWCard.d.ts +1 -1
  86. package/types/isUrl.d.ts +1 -1
  87. package/types/isVehicle.d.ts +1 -1
  88. package/types/normalizeString.d.ts +1 -1
  89. package/types/parseIdCard.d.ts +1 -1
  90. package/types/setDataURLPrefix.d.ts +2 -2
  91. package/types/validatePassword.d.ts +1 -1
@@ -9,11 +9,11 @@ import fileReader from "./fileReader";
9
9
  *
10
10
  * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
11
11
  *
12
+ * @ignore
12
13
  * @static
13
14
  * @alias module:Processor.blobToDataURL
14
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL|FileReader.readAsDataURL()}
15
15
  * @since 4.1.0
16
- * @ignore
16
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL|FileReader.readAsDataURL()}
17
17
  * @deprecated 请使用 `fileReader` 方法
18
18
  * @param {Blob} blob Blob 或 File 对象
19
19
  * @returns {Promise<string>} data:URL 格式的 Base64 字符串。
@@ -8,8 +8,8 @@ import normalizeString from './normalizeString';
8
8
  * @static
9
9
  * @alias module:Other.calculateCursorPosition
10
10
  * @since 4.6.0
11
- * @see h5示例 {@link https://2950v9.csb.app/|点击查看}
12
- * @see react示例 {@link https://33ccy9.csb.app/|点击查看}
11
+ * @see {@link https://2950v9.csb.app/|h5示例}
12
+ * @see {@link https://33ccy9.csb.app/|react示例}
13
13
  * @param {number} prevPos 赋值前的光标位置,onChange/onInput的光标位置 e.target.selectionEnd
14
14
  * @param {string} prevCtrlValue 上一个格式化后的值
15
15
  * @param {string} rawValue 当前输入原值
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * @static
5
5
  * @alias module:Processor.dataURLToBlob
6
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64|Base64}
7
6
  * @since 4.1.0
7
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64|Base64}
8
8
  * @param {string} dataurl data: 协议的URL
9
9
  * @returns {Blob} Blob 对象
10
10
  * @example
package/esm/download.js CHANGED
@@ -5,6 +5,7 @@ import dataURLToBlob from "./dataURLToBlob";
5
5
  import isUrl from "./isUrl";
6
6
  import ajax from "./ajax";
7
7
  import { isBlob } from "./utils/type";
8
+ import isPromiseLike from "./isPromiseLike";
8
9
 
9
10
  /**
10
11
  * 下载文件
@@ -41,13 +42,13 @@ function saver(blobUrl, fileName) {
41
42
  /**
42
43
  * @callback TransformRequest
43
44
  * @param {AjaxOptions} options ajax 配置项
44
- * @returns {AjaxOptions}
45
+ * @returns {AjaxOptions | Promise<AjaxOptions>}
45
46
  */
46
47
 
47
48
  /**
48
49
  * @callback TransformResponse
49
50
  * @param {Blob} res 响应的Blob对象。如果你通过 transformRequest 修改了 responseType ,该参数将是该类型响应值。
50
- * @returns {Blob}
51
+ * @returns {Blob | Promise<Blob>}
51
52
  */
52
53
 
53
54
  /**
@@ -67,7 +68,8 @@ function saver(blobUrl, fileName) {
67
68
  * @static
68
69
  * @alias module:Other.download
69
70
  * @since 4.16.0
70
- * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展|多用途互联网邮件扩展}
71
+ * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展|MIME}
72
+ * @see {@link https://9ykc9s.csb.app/|在线示例}
71
73
  * @param {string|Blob|ArrayBuffer|Int8Array|Uint8Array|Uint8ClampedArray|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array|BigInt64Array|BigUint64Array} data 字符串、blob数据或url地址
72
74
  * @param {string|DownloadOptions} [options] 文件名称 或 配置项
73
75
  * @returns {Promise<void>}
@@ -107,21 +109,34 @@ function download(data, options) {
107
109
  payload = dataURLToBlob(data);
108
110
  } else if (dataType === 'url' || !dataType && isUrl(data)) {
109
111
  // url
110
- /** @type {AjaxOptions} */
111
- var defaultAjaxOptions = {
112
- responseType: 'blob'
112
+ // 包装为异步方法
113
+ /** @type {(opts: AjaxOptions)=>Promise<AjaxOptions>} */
114
+ var asyncTransformRequest = function asyncTransformRequest(opts) {
115
+ // 请求前配置调整
116
+ var tempOptions = typeof transformRequest === 'function' ? transformRequest(opts) : opts;
117
+ // @ts-ignore
118
+ return isPromiseLike(tempOptions) ? tempOptions : Promise.resolve(tempOptions);
113
119
  };
114
- // 请求前配置调整
115
- var ajaxOptions = typeof transformRequest === 'function' ? transformRequest(defaultAjaxOptions) : defaultAjaxOptions;
116
- return ajax(data, ajaxOptions).then(function (e) {
117
- /** @type {Blob} */
120
+ /** @type {(res: Blob)=>Promise<Blob>} */
121
+ var asyncTransformResponse = function asyncTransformResponse(res) {
122
+ var tempRes = typeof transformResponse === 'function' ? transformResponse(res) : res;
118
123
  // @ts-ignore
119
- // 响应结果调整
120
- var res = typeof transformResponse === 'function' ? transformResponse(e.target.response) : e.target.response;
121
- var currentFileName = fileName || data.split("?")[0].split("#")[0].split("/").pop();
122
- return download(res, {
123
- fileName: currentFileName,
124
- type: type || (isBlob(res) ? res.type : undefined)
124
+ return isPromiseLike(tempRes) ? tempRes : Promise.resolve(tempRes);
125
+ };
126
+
127
+ // 此处如果使用 async/await 语法糖,编译后的umd代码过大
128
+ return asyncTransformRequest({
129
+ responseType: 'blob'
130
+ }).then(function (ajaxOptions) {
131
+ return ajax(data, ajaxOptions).then(function (e) {
132
+ // @ts-ignore
133
+ return asyncTransformResponse(e.target.response).then(function (res) {
134
+ var currentFileName = fileName || data.split("?")[0].split("#")[0].split("/").pop();
135
+ return download(res, {
136
+ fileName: currentFileName,
137
+ type: type || (isBlob(res) ? res.type : undefined)
138
+ });
139
+ });
125
140
  });
126
141
  });
127
142
  } else {
package/esm/fileReader.js CHANGED
@@ -20,13 +20,13 @@ var FileReaderMethodMap = {
20
20
  */
21
21
 
22
22
  /**
23
- * 读取 Blob 或 File 对象<br/><br/>
23
+ * 读取 Blob 或 File 对象,转为 Base64/String/ArrayBuffer<br/><br/>
24
24
  *
25
25
  * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
26
26
  *
27
27
  * @static
28
28
  * @alias module:Processor.fileReader
29
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader|FileReader}
29
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader|FileReader}
30
30
  * @since 4.16.0
31
31
  * @param {Blob} blob Blob 或 File 对象
32
32
  * @param {'arrayBuffer'|'binaryString'|'dataURL'|'text'} [type='dataURL'] Blob 或 File 对象
package/esm/filterTree.js CHANGED
@@ -1,6 +1,4 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
4
2
  import { isObject } from "./utils/type";
5
3
 
6
4
  /**
@@ -1,7 +1,5 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
2
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/createForOfIteratorHelper";
5
3
  import { isObject } from "./utils/type";
6
4
 
7
5
  /**
@@ -1,7 +1,5 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
2
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/createForOfIteratorHelper";
5
3
  import { isObject } from "./utils/type";
6
4
 
7
5
  /**
@@ -1,6 +1,4 @@
1
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
2
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/createForOfIteratorHelper";
4
2
  import { isObject } from "./utils/type";
5
3
 
6
4
  /**
package/esm/index.js CHANGED
@@ -53,8 +53,8 @@ export { default as padZero } from './padZero';
53
53
  *
54
54
  * @module Math
55
55
  * @since 3.1.0
56
- * @see 参考 {@link https://github.com/camsong/blog/issues/9|JavaScript 浮点数陷阱及解法}
57
- * @see 参考 {@link https://2zbuy.csb.app/|JS浮点数计算测试}
56
+ * @see {@link https://github.com/camsong/blog/issues/9|JavaScript 浮点数陷阱及解法}
57
+ * @see {@link https://2zbuy.csb.app/|JS浮点数计算测试}
58
58
  * @example
59
59
  * // 从 4.12.0 版本开始,规范了有效数值。(注意:4.12.3 对有效数值重新定义)
60
60
  * // 有效数值即能通过 Number(value) 转为数字,且不能为 NaN 。
@@ -80,13 +80,13 @@ function ajax(url, options) {}
80
80
  /**
81
81
  * @callback TransformRequest
82
82
  * @param {AjaxOptions} options ajax 配置项
83
- * @returns {AjaxOptions}
83
+ * @returns {AjaxOptions | Promise<AjaxOptions>}
84
84
  */
85
85
 
86
86
  /**
87
87
  * @callback TransformResponse
88
88
  * @param {Blob} res 响应的Blob对象。如果你通过 transformRequest 修改了 responseType ,该参数将是该类型响应值。
89
- * @returns {Blob}
89
+ * @returns {Blob | Promise<Blob>}
90
90
  */
91
91
 
92
92
  /**
@@ -107,6 +107,7 @@ function ajax(url, options) {}
107
107
  * @alias module:Other.download
108
108
  * @since 4.16.0
109
109
  * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展|MIME}
110
+ * @see {@link https://9ykc9s.csb.app/|在线示例}
110
111
  * @param {string|Blob|TypedArray} data 字符串、blob数据或url地址
111
112
  * @param {string|DownloadOptions} [options] 文件名称 或 配置项
112
113
  * @returns {Promise<void>}
package/esm/isBankCard.js CHANGED
@@ -28,8 +28,8 @@ function sumCheckCode(numStr) {
28
28
  *
29
29
  * @static
30
30
  * @alias module:Validator.isBankCard
31
- * @see 参考 {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html|常用银行账号位数参考}
32
31
  * @since 1.1.0
32
+ * @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html|常用银行账号位数参考}
33
33
  * @param {*} value 要检测的值
34
34
  * @param {Object} [options] 配置项
35
35
  * @param {boolean} [options.loose=false] 宽松模式,8~30位数字
@@ -38,8 +38,8 @@ function sumCheckCode(preCode) {
38
38
  *
39
39
  * @static
40
40
  * @alias module:Validator.isBusinessLicense
41
- * @see 参考 {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html|GS15—2006 工商行政管理市场主体注册号编制规则}
42
41
  * @since 3.5.0
42
+ * @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html|GS15—2006 工商行政管理市场主体注册号编制规则}
43
43
  * @param {*} value 要检测的值
44
44
  * @param {Object} [options] 配置项
45
45
  * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
package/esm/isChinese.js CHANGED
@@ -32,9 +32,9 @@ var supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');
32
32
  * @static
33
33
  * @alias module:Validator.isChinese
34
34
  * @since 1.1.0
35
- * @see 参考 {@link http://www.unicode.org/reports/tr38/#BlockListing|4.4 Listing of Characters Covered by the Unihan Database}
36
- * @see 参考 {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射|Unicode字符平面映射}
37
- * @see 参考 {@link https://zh.wikipedia.org/wiki/Unicode區段|Unicode区段}
35
+ * @see {@link http://www.unicode.org/reports/tr38/#BlockListing|4.4 Listing of Characters Covered by the Unihan Database}
36
+ * @see {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射|Unicode字符平面映射}
37
+ * @see {@link https://zh.wikipedia.org/wiki/Unicode區段|Unicode区段}
38
38
  * @param {*} value 要检测的值
39
39
  * @param {Object} [options] 配置项
40
40
  * @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
package/esm/isHMCard.js CHANGED
@@ -9,7 +9,7 @@ var regHMCard = /^[hm]{1}([0-9]{10}|[0-9]{8})$/i;
9
9
  * @static
10
10
  * @alias module:Validator.isHMCard
11
11
  * @since 4.0.0
12
- * @see 参考 {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证|港澳居民来往内地通行证}
12
+ * @see {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证|港澳居民来往内地通行证}
13
13
  * @param {*} value 要检测的值
14
14
  * @returns {boolean} 是否为港澳居民来往内地通行证
15
15
  * @example
package/esm/isIdCard.js CHANGED
@@ -29,8 +29,8 @@ function check(id) {
29
29
  * @static
30
30
  * @alias module:Validator.isIdCard
31
31
  * @since 1.1.0
32
- * @see 参考 {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码|中华人民共和国公民身份号码}
33
- * @see 参考 {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
32
+ * @see {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码|中华人民共和国公民身份号码}
33
+ * @see {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
34
34
  * @param {*} value 要检测的值
35
35
  * @param {Object} [options] 配置项
36
36
  * @param {boolean} [options.loose=false] 宽松模式,支持15位身份证号码
package/esm/isPassport.js CHANGED
@@ -9,8 +9,8 @@ var reg = /^((e[\da-z])|(de)|(se)|(pe)|([khm][\da-z]))[\da-z]{7}$/i;
9
9
  *
10
10
  * @static
11
11
  * @alias module:Validator.isPassport
12
- * @see 参考 {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页|中华人民共和国护照#个人资料页}
13
12
  * @since 1.1.0
13
+ * @see {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页|中华人民共和国护照#个人资料页}
14
14
  * @param {*} value 要检测的值
15
15
  * @returns {boolean} 值是否为护照号
16
16
  * @example
package/esm/isPassword.js CHANGED
@@ -5,11 +5,11 @@ import validatePassword from './validatePassword';
5
5
  * <p><strong>注意:该校验只校验是否存在不同字符(大小写字母、数字、特殊符号),不判断长度。</strong></p>
6
6
  * <p><i>如果需要更细致的验证,请使用 <a href="#.validatePassword">validatePassword</a></i></p>
7
7
  *
8
- * @see 参考 {@link https://baike.baidu.com/item/ASCII#3|ASCII}
9
8
  * @static
10
9
  * @alias module:Validator.isPassword
11
- * @since 1.1.0
12
10
  * @requires module:Validator.validatePassword
11
+ * @since 1.1.0
12
+ * @see {@link https://baike.baidu.com/item/ASCII#3|ASCII}
13
13
  * @param {*} value 要检测的值
14
14
  * @param {Object} [options] 配置项
15
15
  * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
@@ -44,8 +44,8 @@ function sumCheckCode(preCode) {
44
44
  *
45
45
  * @static
46
46
  * @alias module:Validator.isSocialCreditCode
47
- * @see 参考 {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则|GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
48
47
  * @since 1.1.0
48
+ * @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则|GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
49
49
  * @param {*} value 要检测的值
50
50
  * @param {Object} [options] 配置项
51
51
  * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
@@ -6,8 +6,8 @@ var reg = /^[A-Z]{6}[A-Z\d]{2}(?:[A-Z\d]{3})?$/;
6
6
  *
7
7
  * @static
8
8
  * @alias module:Validator.isSwiftCode
9
- * @see 参考 {@link https://zh.wikipedia.org/wiki/ISO_9362|ISO 9362}
10
9
  * @since 4.9.0
10
+ * @see {@link https://zh.wikipedia.org/wiki/ISO_9362|ISO 9362}
11
11
  * @param {*} value 要检测的值
12
12
  * @returns {boolean} 值是否为 Swift Code
13
13
  * @example
package/esm/isTWCard.js CHANGED
@@ -12,7 +12,7 @@ var singleRegTWCard = /^[\da-z]{10,12}$/i;
12
12
  * @static
13
13
  * @alias module:Validator.isTWCard
14
14
  * @since 4.0.0
15
- * @see 参考 {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
15
+ * @see {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
16
16
  * @param {*} value 要检测的值
17
17
  * @param {Object} [options] 配置项
18
18
  * @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
package/esm/isUrl.js CHANGED
@@ -24,7 +24,7 @@ var regNonProtocal = new RegExp("^(?:".concat(serverReg, ")(?:").concat(portReg,
24
24
  * @static
25
25
  * @alias module:Validator.isUrl
26
26
  * @since 3.4.0
27
- * @see 参考 {@link https://zh.wikipedia.org/wiki/统一资源定位符|统一资源定位符}
27
+ * @see {@link https://zh.wikipedia.org/wiki/统一资源定位符|统一资源定位符}
28
28
  * @param {*} value 要检测的值
29
29
  * @returns {boolean} 值是否为url
30
30
  * @example
package/esm/isVehicle.js CHANGED
@@ -8,8 +8,8 @@ var reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕
8
8
  *
9
9
  * @static
10
10
  * @alias module:Validator.isVehicle
11
- * @see 参考 {@link https://baike.baidu.com/item/车牌号|车牌号}
12
11
  * @since 1.1.0
12
+ * @see {@link https://baike.baidu.com/item/车牌号|车牌号}
13
13
  * @param {*} value 要检测的值
14
14
  * @returns {boolean} 值是否为车牌号
15
15
  * @example
package/esm/listToTree.js CHANGED
@@ -1,6 +1,4 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
4
2
  import { isObject } from "./utils/type";
5
3
 
6
4
  /**
@@ -6,8 +6,8 @@ import convertToString from './utils/convertToString';
6
6
  *
7
7
  * @static
8
8
  * @alias module:Processor.normalizeString
9
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
10
9
  * @since 4.3.0
10
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
11
11
  * @param {*} value 待处理的值
12
12
  * @returns {string} 规整化的值
13
13
  * @example
@@ -1,7 +1,4 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- import _inherits from "@babel/runtime/helpers/inherits";
3
- import _setPrototypeOf from "@babel/runtime/helpers/setPrototypeOf";
4
- function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, void 0, groups); }; var _super = RegExp.prototype, _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); return _groups.set(_this, groups || _groups.get(re)), _setPrototypeOf(_this, BabelRegExp.prototype); } function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { var i = g[name]; if ("number" == typeof i) groups[name] = result[i];else { for (var k = 0; void 0 === result[i[k]] && k + 1 < i.length;) { k++; } groups[name] = result[i[k]]; } return groups; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) { result.groups = buildGroups(result, this); var indices = result.indices; indices && (indices.groups = buildGroups(indices, this)); } return result; }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if ("string" == typeof substitution) { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { var group = groups[name]; return "$" + (Array.isArray(group) ? group.join("$") : group); })); } if ("function" == typeof substitution) { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; return "object" != _typeof(args[args.length - 1]) && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); }); } return _super[Symbol.replace].call(this, str, substitution); }, _wrapRegExp.apply(this, arguments); }
1
+ import _wrapRegExp from "@babel/runtime/helpers/wrapRegExp";
5
2
  var regIdCard = /*#__PURE__*/_wrapRegExp(/^(\d{2})(\d{2})(\d{2})((?:\d{2})?\d{2})(\d{2})(\d{2})\d{2}(\d)(?:\d|X)?$/i, {
6
3
  province: 1,
7
4
  city: 2,
@@ -69,7 +66,7 @@ var Provinces = [
69
66
  * @static
70
67
  * @alias module:Processor.parseIdCard
71
68
  * @since 4.0.0
72
- * @see 参考 {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
69
+ * @see {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
73
70
  * @param {string} id 身份证号码,支持15位
74
71
  * @returns {IdCardInfo | null} 省份、生日、性别,省/市/区/年/月/日/性别编码。如果解析失败将返回 null 。
75
72
  * @example
package/esm/safeDate.js CHANGED
@@ -30,8 +30,8 @@ import _construct from "@babel/runtime/helpers/construct";
30
30
  *
31
31
  * @static
32
32
  * @alias module:Processor.safeDate
33
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date|Date}
34
33
  * @since 4.4.0
34
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date|Date}
35
35
  * @param {string|number|Date} [value] 日期时间字符串、毫秒数、日期对象
36
36
  * @param {...number} args 月/日/时/分/秒/毫秒
37
37
  * @returns {Date} Date 实例日期对象
@@ -4,9 +4,9 @@
4
4
  *
5
5
  * @static
6
6
  * @alias module:Processor.setDataURLPrefix
7
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/Data_URIs|Data URLs}
8
- * @see 参考 {@link https://mimesniff.spec.whatwg.org/#understanding-mime-types|MIME types}
9
7
  * @since 4.1.0
8
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/Data_URIs|Data URLs}
9
+ * @see {@link https://mimesniff.spec.whatwg.org/#understanding-mime-types|MIME types}
10
10
  * @param {string} data 数据本身
11
11
  * @param {string} [mimetype="image/png"] MIME 类型
12
12
  * @param {boolean} [base64=true] 添加 base64 标识
@@ -1,6 +1,4 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
4
2
  // 如果修改文档,请同步修改 interface.doc.js
5
3
 
6
4
  import { isObject } from './utils/type';
package/esm/treeToList.js CHANGED
@@ -1,6 +1,4 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
4
2
  import { isObject } from "./utils/type";
5
3
 
6
4
  /**
@@ -15,5 +15,5 @@ function setDisableWarning(bool) {
15
15
  }
16
16
 
17
17
  // eslint-disable-next-line no-undef
18
- var version = "4.16.0";
18
+ var version = "4.16.2";
19
19
  export { config, setDisableWarning, version };
@@ -129,10 +129,10 @@ function hasUnallowableCharacter(val, chars) {
129
129
  /**
130
130
  * 验证密码(数字、大小写字母、特殊字符、非法字符)
131
131
  *
132
- * @see 参考 {@link https://baike.baidu.com/item/ASCII#3|ASCII}
133
132
  * @static
134
133
  * @alias module:Validator.validatePassword
135
134
  * @since 3.7.0
135
+ * @see {@link https://baike.baidu.com/item/ASCII#3|ASCII}
136
136
  * @param {string} value 要检测的值
137
137
  * @param {Object} [options] 配置项
138
138
  * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
@@ -15,11 +15,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
15
15
  *
16
16
  * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
17
17
  *
18
+ * @ignore
18
19
  * @static
19
20
  * @alias module:Processor.blobToDataURL
20
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL|FileReader.readAsDataURL()}
21
21
  * @since 4.1.0
22
- * @ignore
22
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL|FileReader.readAsDataURL()}
23
23
  * @deprecated 请使用 `fileReader` 方法
24
24
  * @param {Blob} blob Blob 或 File 对象
25
25
  * @returns {Promise<string>} data:URL 格式的 Base64 字符串。
@@ -7,15 +7,14 @@ exports["default"] = void 0;
7
7
  var _normalizeString = _interopRequireDefault(require("./normalizeString"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
9
  // ref: https://github.com/ant-design/ant-design-mobile/blob/v2/components/input-item/index.tsx#L240
10
-
11
10
  /**
12
11
  * 计算输入框的值格式化后光标位置
13
12
  *
14
13
  * @static
15
14
  * @alias module:Other.calculateCursorPosition
16
15
  * @since 4.6.0
17
- * @see h5示例 {@link https://2950v9.csb.app/|点击查看}
18
- * @see react示例 {@link https://33ccy9.csb.app/|点击查看}
16
+ * @see {@link https://2950v9.csb.app/|h5示例}
17
+ * @see {@link https://33ccy9.csb.app/|react示例}
19
18
  * @param {number} prevPos 赋值前的光标位置,onChange/onInput的光标位置 e.target.selectionEnd
20
19
  * @param {string} prevCtrlValue 上一个格式化后的值
21
20
  * @param {string} rawValue 当前输入原值
@@ -9,8 +9,8 @@ exports["default"] = void 0;
9
9
  *
10
10
  * @static
11
11
  * @alias module:Processor.dataURLToBlob
12
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64|Base64}
13
12
  * @since 4.1.0
13
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64|Base64}
14
14
  * @param {string} dataurl data: 协议的URL
15
15
  * @returns {Blob} Blob 对象
16
16
  * @example
package/lib/divide.js CHANGED
@@ -12,7 +12,7 @@ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread n
12
12
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
13
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
14
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
15
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
15
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
16
16
  /**
17
17
  * 精确除法,支持多个数相除,除数默认为 1 。
18
18
  *
package/lib/download.js CHANGED
@@ -8,8 +8,9 @@ var _dataURLToBlob = _interopRequireDefault(require("./dataURLToBlob"));
8
8
  var _isUrl = _interopRequireDefault(require("./isUrl"));
9
9
  var _ajax = _interopRequireDefault(require("./ajax"));
10
10
  var _type = require("./utils/type");
11
+ var _isPromiseLike = _interopRequireDefault(require("./isPromiseLike"));
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
13
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } // 如果修改文档,请同步修改 interface.doc.js
13
14
  /**
14
15
  * 下载文件
15
16
  *
@@ -45,13 +46,13 @@ function saver(blobUrl, fileName) {
45
46
  /**
46
47
  * @callback TransformRequest
47
48
  * @param {AjaxOptions} options ajax 配置项
48
- * @returns {AjaxOptions}
49
+ * @returns {AjaxOptions | Promise<AjaxOptions>}
49
50
  */
50
51
 
51
52
  /**
52
53
  * @callback TransformResponse
53
54
  * @param {Blob} res 响应的Blob对象。如果你通过 transformRequest 修改了 responseType ,该参数将是该类型响应值。
54
- * @returns {Blob}
55
+ * @returns {Blob | Promise<Blob>}
55
56
  */
56
57
 
57
58
  /**
@@ -71,7 +72,8 @@ function saver(blobUrl, fileName) {
71
72
  * @static
72
73
  * @alias module:Other.download
73
74
  * @since 4.16.0
74
- * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展|多用途互联网邮件扩展}
75
+ * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展|MIME}
76
+ * @see {@link https://9ykc9s.csb.app/|在线示例}
75
77
  * @param {string|Blob|ArrayBuffer|Int8Array|Uint8Array|Uint8ClampedArray|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array|BigInt64Array|BigUint64Array} data 字符串、blob数据或url地址
76
78
  * @param {string|DownloadOptions} [options] 文件名称 或 配置项
77
79
  * @returns {Promise<void>}
@@ -111,21 +113,34 @@ function download(data, options) {
111
113
  payload = (0, _dataURLToBlob["default"])(data);
112
114
  } else if (dataType === 'url' || !dataType && (0, _isUrl["default"])(data)) {
113
115
  // url
114
- /** @type {AjaxOptions} */
115
- var defaultAjaxOptions = {
116
- responseType: 'blob'
116
+ // 包装为异步方法
117
+ /** @type {(opts: AjaxOptions)=>Promise<AjaxOptions>} */
118
+ var asyncTransformRequest = function asyncTransformRequest(opts) {
119
+ // 请求前配置调整
120
+ var tempOptions = typeof transformRequest === 'function' ? transformRequest(opts) : opts;
121
+ // @ts-ignore
122
+ return (0, _isPromiseLike["default"])(tempOptions) ? tempOptions : Promise.resolve(tempOptions);
117
123
  };
118
- // 请求前配置调整
119
- var ajaxOptions = typeof transformRequest === 'function' ? transformRequest(defaultAjaxOptions) : defaultAjaxOptions;
120
- return (0, _ajax["default"])(data, ajaxOptions).then(function (e) {
121
- /** @type {Blob} */
124
+ /** @type {(res: Blob)=>Promise<Blob>} */
125
+ var asyncTransformResponse = function asyncTransformResponse(res) {
126
+ var tempRes = typeof transformResponse === 'function' ? transformResponse(res) : res;
122
127
  // @ts-ignore
123
- // 响应结果调整
124
- var res = typeof transformResponse === 'function' ? transformResponse(e.target.response) : e.target.response;
125
- var currentFileName = fileName || data.split("?")[0].split("#")[0].split("/").pop();
126
- return download(res, {
127
- fileName: currentFileName,
128
- type: type || ((0, _type.isBlob)(res) ? res.type : undefined)
128
+ return (0, _isPromiseLike["default"])(tempRes) ? tempRes : Promise.resolve(tempRes);
129
+ };
130
+
131
+ // 此处如果使用 async/await 语法糖,编译后的umd代码过大
132
+ return asyncTransformRequest({
133
+ responseType: 'blob'
134
+ }).then(function (ajaxOptions) {
135
+ return (0, _ajax["default"])(data, ajaxOptions).then(function (e) {
136
+ // @ts-ignore
137
+ return asyncTransformResponse(e.target.response).then(function (res) {
138
+ var currentFileName = fileName || data.split("?")[0].split("#")[0].split("/").pop();
139
+ return download(res, {
140
+ fileName: currentFileName,
141
+ type: type || ((0, _type.isBlob)(res) ? res.type : undefined)
142
+ });
143
+ });
129
144
  });
130
145
  });
131
146
  } else {