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.
- package/README.md +3 -1
- package/dist/util-helpers.js +60 -46
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/blobToDataURL.js +2 -2
- package/esm/calculateCursorPosition.js +2 -2
- package/esm/dataURLToBlob.js +1 -1
- package/esm/download.js +31 -16
- package/esm/fileReader.js +2 -2
- package/esm/filterTree.js +1 -3
- package/esm/findTreeNode.js +1 -3
- package/esm/findTreeNodes.js +1 -3
- package/esm/findTreeSelect.js +1 -3
- package/esm/index.js +2 -2
- package/esm/interface.doc.js +3 -2
- package/esm/isBankCard.js +1 -1
- package/esm/isBusinessLicense.js +1 -1
- package/esm/isChinese.js +3 -3
- package/esm/isHMCard.js +1 -1
- package/esm/isIdCard.js +2 -2
- package/esm/isPassport.js +1 -1
- package/esm/isPassword.js +2 -2
- package/esm/isSocialCreditCode.js +1 -1
- package/esm/isSwiftCode.js +1 -1
- package/esm/isTWCard.js +1 -1
- package/esm/isUrl.js +1 -1
- package/esm/isVehicle.js +1 -1
- package/esm/listToTree.js +1 -3
- package/esm/normalizeString.js +1 -1
- package/esm/parseIdCard.js +2 -5
- package/esm/safeDate.js +1 -1
- package/esm/setDataURLPrefix.js +2 -2
- package/esm/transformFieldNames.js +1 -3
- package/esm/treeToList.js +1 -3
- package/esm/utils/config.js +1 -1
- package/esm/validatePassword.js +1 -1
- package/lib/blobToDataURL.js +2 -2
- package/lib/calculateCursorPosition.js +2 -3
- package/lib/dataURLToBlob.js +1 -1
- package/lib/divide.js +1 -1
- package/lib/download.js +32 -17
- package/lib/fileReader.js +2 -2
- package/lib/findTreeNode.js +1 -1
- package/lib/findTreeNodes.js +1 -1
- package/lib/findTreeSelect.js +1 -1
- package/lib/formatMoney.js +2 -2
- package/lib/interface.doc.js +3 -2
- package/lib/isBankCard.js +1 -1
- package/lib/isBusinessLicense.js +1 -1
- package/lib/isChinese.js +3 -3
- package/lib/isHMCard.js +1 -1
- package/lib/isIdCard.js +2 -2
- package/lib/isPassport.js +1 -1
- package/lib/isPassword.js +2 -2
- package/lib/isSocialCreditCode.js +1 -1
- package/lib/isSwiftCode.js +1 -1
- package/lib/isTWCard.js +1 -1
- package/lib/isUrl.js +1 -2
- package/lib/isVehicle.js +1 -1
- package/lib/minus.js +1 -1
- package/lib/normalizeString.js +1 -1
- package/lib/parseIdCard.js +2 -2
- package/lib/plus.js +1 -1
- package/lib/safeDate.js +1 -1
- package/lib/setDataURLPrefix.js +2 -2
- package/lib/times.js +1 -1
- package/lib/transformFieldNames.js +1 -1
- package/lib/utils/config.js +1 -1
- package/lib/validatePassword.js +1 -1
- package/package.json +14 -14
- package/types/blobToDataURL.d.ts +2 -2
- package/types/calculateCursorPosition.d.ts +2 -2
- package/types/dataURLToBlob.d.ts +1 -1
- package/types/download.d.ts +6 -5
- package/types/isBankCard.d.ts +1 -1
- package/types/isBusinessLicense.d.ts +1 -1
- package/types/isChinese.d.ts +3 -3
- package/types/isHMCard.d.ts +1 -1
- package/types/isIdCard.d.ts +2 -2
- package/types/isPassport.d.ts +1 -1
- package/types/isPassword.d.ts +2 -2
- package/types/isSocialCreditCode.d.ts +1 -1
- package/types/isSwiftCode.d.ts +1 -1
- package/types/isTWCard.d.ts +1 -1
- package/types/isUrl.d.ts +1 -1
- package/types/isVehicle.d.ts +1 -1
- package/types/normalizeString.d.ts +1 -1
- package/types/parseIdCard.d.ts +1 -1
- package/types/setDataURLPrefix.d.ts +2 -2
- package/types/validatePassword.d.ts +1 -1
package/README.md
CHANGED
|
@@ -50,9 +50,9 @@ formatBankCard('6228480402564890018', { spaceMark: '-' }); // 6228-4804-0256-489
|
|
|
50
50
|
- [divide](https://doly-dev.github.io/util-helpers/module-Math.html#.divide) - 除
|
|
51
51
|
- [round](https://doly-dev.github.io/util-helpers/module-Math.html#.round) - 四舍五入
|
|
52
52
|
- 数据处理
|
|
53
|
-
- [blobToDataURL](https://doly-dev.github.io/util-helpers/module-Processor.html#.blobToDataURL) - 将 Blob 或 File 对象转成 data:URL 格式的 Base64 字符串
|
|
54
53
|
- [bytesToSize](https://doly-dev.github.io/util-helpers/module-Processor.html#.bytesToSize) - 字节转换为存储单位
|
|
55
54
|
- [dataURLToBlob](https://doly-dev.github.io/util-helpers/module-Processor.html#.dataURLToBlob) - 将 DataURL 转为 Blob 对象
|
|
55
|
+
- [fileReader](https://doly-dev.github.io/util-helpers/module-Processor.html#.fileReader) - 读取 Blob 或 File 对象,转为 Base64/String/ArrayBuffer
|
|
56
56
|
- [formatMoney](https://doly-dev.github.io/util-helpers/module-Processor.html#.formatMoney) - 格式化金额
|
|
57
57
|
- [formatMobile](https://doly-dev.github.io/util-helpers/module-Processor.html#.formatMobile) - 格式化手机号码
|
|
58
58
|
- [formatBankCard](https://doly-dev.github.io/util-helpers/module-Processor.html#.formatBankCard) - 格式化银行卡
|
|
@@ -95,7 +95,9 @@ formatBankCard('6228480402564890018', { spaceMark: '-' }); // 6228-4804-0256-489
|
|
|
95
95
|
- [isBusinessLicense](https://doly-dev.github.io/util-helpers/module-Validator.html#.isBusinessLicense) - 营业执照,也叫工商注册号
|
|
96
96
|
- [validatePassword](https://doly-dev.github.io/util-helpers/module-Validator.html#.validatePassword) - 验证密码
|
|
97
97
|
- 其他
|
|
98
|
+
- [ajax](https://doly-dev.github.io/util-helpers/module-Other.html#.ajax) - 请求
|
|
98
99
|
- [calculateCursorPosition](https://doly-dev.github.io/util-helpers/module-Other.html#.calculateCursorPosition) - 计算光标位置
|
|
100
|
+
- [download](https://doly-dev.github.io/util-helpers/module-Other.html#.download) - 下载
|
|
99
101
|
- [randomString](https://doly-dev.github.io/util-helpers/module-Other.html#.randomString) - 随机字符串
|
|
100
102
|
- [strlen](https://doly-dev.github.io/util-helpers/module-Other.html#.strlen) - 字符长度
|
|
101
103
|
- [waitTime](https://doly-dev.github.io/util-helpers/module-Other.html#.waitTime) - 等待时间返回 Promise
|
package/dist/util-helpers.js
CHANGED
|
@@ -110,8 +110,8 @@
|
|
|
110
110
|
*
|
|
111
111
|
* @static
|
|
112
112
|
* @alias module:Processor.normalizeString
|
|
113
|
-
* @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
|
|
114
113
|
* @since 4.3.0
|
|
114
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
|
|
115
115
|
* @param {*} value 待处理的值
|
|
116
116
|
* @returns {string} 规整化的值
|
|
117
117
|
* @example
|
|
@@ -235,8 +235,8 @@
|
|
|
235
235
|
* @static
|
|
236
236
|
* @alias module:Validator.isIdCard
|
|
237
237
|
* @since 1.1.0
|
|
238
|
-
* @see
|
|
239
|
-
* @see
|
|
238
|
+
* @see {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码|中华人民共和国公民身份号码}
|
|
239
|
+
* @see {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
|
|
240
240
|
* @param {*} value 要检测的值
|
|
241
241
|
* @param {Object} [options] 配置项
|
|
242
242
|
* @param {boolean} [options.loose=false] 宽松模式,支持15位身份证号码
|
|
@@ -350,8 +350,8 @@
|
|
|
350
350
|
*
|
|
351
351
|
* @static
|
|
352
352
|
* @alias module:Validator.isVehicle
|
|
353
|
-
* @see 参考 {@link https://baike.baidu.com/item/车牌号|车牌号}
|
|
354
353
|
* @since 1.1.0
|
|
354
|
+
* @see {@link https://baike.baidu.com/item/车牌号|车牌号}
|
|
355
355
|
* @param {*} value 要检测的值
|
|
356
356
|
* @returns {boolean} 值是否为车牌号
|
|
357
357
|
* @example
|
|
@@ -400,8 +400,8 @@
|
|
|
400
400
|
*
|
|
401
401
|
* @static
|
|
402
402
|
* @alias module:Validator.isBankCard
|
|
403
|
-
* @see 参考 {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html|常用银行账号位数参考}
|
|
404
403
|
* @since 1.1.0
|
|
404
|
+
* @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html|常用银行账号位数参考}
|
|
405
405
|
* @param {*} value 要检测的值
|
|
406
406
|
* @param {Object} [options] 配置项
|
|
407
407
|
* @param {boolean} [options.loose=false] 宽松模式,8~30位数字
|
|
@@ -477,8 +477,8 @@
|
|
|
477
477
|
*
|
|
478
478
|
* @static
|
|
479
479
|
* @alias module:Validator.isSocialCreditCode
|
|
480
|
-
* @see 参考 {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则|GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
|
|
481
480
|
* @since 1.1.0
|
|
481
|
+
* @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则|GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
|
|
482
482
|
* @param {*} value 要检测的值
|
|
483
483
|
* @param {Object} [options] 配置项
|
|
484
484
|
* @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
|
|
@@ -537,7 +537,7 @@
|
|
|
537
537
|
}
|
|
538
538
|
|
|
539
539
|
// eslint-disable-next-line no-undef
|
|
540
|
-
var version = "4.16.
|
|
540
|
+
var version = "4.16.2";
|
|
541
541
|
|
|
542
542
|
/**
|
|
543
543
|
* 打印警告信息
|
|
@@ -681,10 +681,10 @@
|
|
|
681
681
|
/**
|
|
682
682
|
* 验证密码(数字、大小写字母、特殊字符、非法字符)
|
|
683
683
|
*
|
|
684
|
-
* @see 参考 {@link https://baike.baidu.com/item/ASCII#3|ASCII}
|
|
685
684
|
* @static
|
|
686
685
|
* @alias module:Validator.validatePassword
|
|
687
686
|
* @since 3.7.0
|
|
687
|
+
* @see {@link https://baike.baidu.com/item/ASCII#3|ASCII}
|
|
688
688
|
* @param {string} value 要检测的值
|
|
689
689
|
* @param {Object} [options] 配置项
|
|
690
690
|
* @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
|
|
@@ -817,11 +817,11 @@
|
|
|
817
817
|
* <p><strong>注意:该校验只校验是否存在不同字符(大小写字母、数字、特殊符号),不判断长度。</strong></p>
|
|
818
818
|
* <p><i>如果需要更细致的验证,请使用 <a href="#.validatePassword">validatePassword</a></i></p>
|
|
819
819
|
*
|
|
820
|
-
* @see 参考 {@link https://baike.baidu.com/item/ASCII#3|ASCII}
|
|
821
820
|
* @static
|
|
822
821
|
* @alias module:Validator.isPassword
|
|
823
|
-
* @since 1.1.0
|
|
824
822
|
* @requires module:Validator.validatePassword
|
|
823
|
+
* @since 1.1.0
|
|
824
|
+
* @see {@link https://baike.baidu.com/item/ASCII#3|ASCII}
|
|
825
825
|
* @param {*} value 要检测的值
|
|
826
826
|
* @param {Object} [options] 配置项
|
|
827
827
|
* @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
|
|
@@ -869,8 +869,8 @@
|
|
|
869
869
|
*
|
|
870
870
|
* @static
|
|
871
871
|
* @alias module:Validator.isPassport
|
|
872
|
-
* @see 参考 {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页|中华人民共和国护照#个人资料页}
|
|
873
872
|
* @since 1.1.0
|
|
873
|
+
* @see {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页|中华人民共和国护照#个人资料页}
|
|
874
874
|
* @param {*} value 要检测的值
|
|
875
875
|
* @returns {boolean} 值是否为护照号
|
|
876
876
|
* @example
|
|
@@ -917,9 +917,9 @@
|
|
|
917
917
|
* @static
|
|
918
918
|
* @alias module:Validator.isChinese
|
|
919
919
|
* @since 1.1.0
|
|
920
|
-
* @see
|
|
921
|
-
* @see
|
|
922
|
-
* @see
|
|
920
|
+
* @see {@link http://www.unicode.org/reports/tr38/#BlockListing|4.4 Listing of Characters Covered by the Unihan Database}
|
|
921
|
+
* @see {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射|Unicode字符平面映射}
|
|
922
|
+
* @see {@link https://zh.wikipedia.org/wiki/Unicode區段|Unicode区段}
|
|
923
923
|
* @param {*} value 要检测的值
|
|
924
924
|
* @param {Object} [options] 配置项
|
|
925
925
|
* @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
|
|
@@ -1044,7 +1044,7 @@
|
|
|
1044
1044
|
* @static
|
|
1045
1045
|
* @alias module:Validator.isUrl
|
|
1046
1046
|
* @since 3.4.0
|
|
1047
|
-
* @see
|
|
1047
|
+
* @see {@link https://zh.wikipedia.org/wiki/统一资源定位符|统一资源定位符}
|
|
1048
1048
|
* @param {*} value 要检测的值
|
|
1049
1049
|
* @returns {boolean} 值是否为url
|
|
1050
1050
|
* @example
|
|
@@ -1112,8 +1112,8 @@
|
|
|
1112
1112
|
*
|
|
1113
1113
|
* @static
|
|
1114
1114
|
* @alias module:Validator.isBusinessLicense
|
|
1115
|
-
* @see 参考 {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html|GS15—2006 工商行政管理市场主体注册号编制规则}
|
|
1116
1115
|
* @since 3.5.0
|
|
1116
|
+
* @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html|GS15—2006 工商行政管理市场主体注册号编制规则}
|
|
1117
1117
|
* @param {*} value 要检测的值
|
|
1118
1118
|
* @param {Object} [options] 配置项
|
|
1119
1119
|
* @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
|
|
@@ -1450,7 +1450,7 @@
|
|
|
1450
1450
|
* @static
|
|
1451
1451
|
* @alias module:Validator.isHMCard
|
|
1452
1452
|
* @since 4.0.0
|
|
1453
|
-
* @see
|
|
1453
|
+
* @see {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证|港澳居民来往内地通行证}
|
|
1454
1454
|
* @param {*} value 要检测的值
|
|
1455
1455
|
* @returns {boolean} 是否为港澳居民来往内地通行证
|
|
1456
1456
|
* @example
|
|
@@ -1483,7 +1483,7 @@
|
|
|
1483
1483
|
* @static
|
|
1484
1484
|
* @alias module:Validator.isTWCard
|
|
1485
1485
|
* @since 4.0.0
|
|
1486
|
-
* @see
|
|
1486
|
+
* @see {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
|
|
1487
1487
|
* @param {*} value 要检测的值
|
|
1488
1488
|
* @param {Object} [options] 配置项
|
|
1489
1489
|
* @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
|
|
@@ -1517,8 +1517,8 @@
|
|
|
1517
1517
|
*
|
|
1518
1518
|
* @static
|
|
1519
1519
|
* @alias module:Validator.isSwiftCode
|
|
1520
|
-
* @see 参考 {@link https://zh.wikipedia.org/wiki/ISO_9362|ISO 9362}
|
|
1521
1520
|
* @since 4.9.0
|
|
1521
|
+
* @see {@link https://zh.wikipedia.org/wiki/ISO_9362|ISO 9362}
|
|
1522
1522
|
* @param {*} value 要检测的值
|
|
1523
1523
|
* @returns {boolean} 值是否为 Swift Code
|
|
1524
1524
|
* @example
|
|
@@ -2447,7 +2447,7 @@
|
|
|
2447
2447
|
* @static
|
|
2448
2448
|
* @alias module:Processor.parseIdCard
|
|
2449
2449
|
* @since 4.0.0
|
|
2450
|
-
* @see
|
|
2450
|
+
* @see {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
|
|
2451
2451
|
* @param {string} id 身份证号码,支持15位
|
|
2452
2452
|
* @returns {IdCardInfo | null} 省份、生日、性别,省/市/区/年/月/日/性别编码。如果解析失败将返回 null 。
|
|
2453
2453
|
* @example
|
|
@@ -2533,13 +2533,13 @@
|
|
|
2533
2533
|
*/
|
|
2534
2534
|
|
|
2535
2535
|
/**
|
|
2536
|
-
* 读取 Blob 或 File
|
|
2536
|
+
* 读取 Blob 或 File 对象,转为 Base64/String/ArrayBuffer<br/><br/>
|
|
2537
2537
|
*
|
|
2538
2538
|
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
2539
2539
|
*
|
|
2540
2540
|
* @static
|
|
2541
2541
|
* @alias module:Processor.fileReader
|
|
2542
|
-
* @see
|
|
2542
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader|FileReader}
|
|
2543
2543
|
* @since 4.16.0
|
|
2544
2544
|
* @param {Blob} blob Blob 或 File 对象
|
|
2545
2545
|
* @param {'arrayBuffer'|'binaryString'|'dataURL'|'text'} [type='dataURL'] Blob 或 File 对象
|
|
@@ -2585,11 +2585,11 @@
|
|
|
2585
2585
|
*
|
|
2586
2586
|
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
2587
2587
|
*
|
|
2588
|
+
* @ignore
|
|
2588
2589
|
* @static
|
|
2589
2590
|
* @alias module:Processor.blobToDataURL
|
|
2590
|
-
* @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL|FileReader.readAsDataURL()}
|
|
2591
2591
|
* @since 4.1.0
|
|
2592
|
-
* @
|
|
2592
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL|FileReader.readAsDataURL()}
|
|
2593
2593
|
* @deprecated 请使用 `fileReader` 方法
|
|
2594
2594
|
* @param {Blob} blob Blob 或 File 对象
|
|
2595
2595
|
* @returns {Promise<string>} data:URL 格式的 Base64 字符串。
|
|
@@ -2616,8 +2616,8 @@
|
|
|
2616
2616
|
*
|
|
2617
2617
|
* @static
|
|
2618
2618
|
* @alias module:Processor.dataURLToBlob
|
|
2619
|
-
* @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64|Base64}
|
|
2620
2619
|
* @since 4.1.0
|
|
2620
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64|Base64}
|
|
2621
2621
|
* @param {string} dataurl data: 协议的URL
|
|
2622
2622
|
* @returns {Blob} Blob 对象
|
|
2623
2623
|
* @example
|
|
@@ -2646,9 +2646,9 @@
|
|
|
2646
2646
|
*
|
|
2647
2647
|
* @static
|
|
2648
2648
|
* @alias module:Processor.setDataURLPrefix
|
|
2649
|
-
* @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/Data_URIs|Data URLs}
|
|
2650
|
-
* @see 参考 {@link https://mimesniff.spec.whatwg.org/#understanding-mime-types|MIME types}
|
|
2651
2649
|
* @since 4.1.0
|
|
2650
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/Data_URIs|Data URLs}
|
|
2651
|
+
* @see {@link https://mimesniff.spec.whatwg.org/#understanding-mime-types|MIME types}
|
|
2652
2652
|
* @param {string} data 数据本身
|
|
2653
2653
|
* @param {string} [mimetype="image/png"] MIME 类型
|
|
2654
2654
|
* @param {boolean} [base64=true] 添加 base64 标识
|
|
@@ -2701,8 +2701,8 @@
|
|
|
2701
2701
|
*
|
|
2702
2702
|
* @static
|
|
2703
2703
|
* @alias module:Processor.safeDate
|
|
2704
|
-
* @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date|Date}
|
|
2705
2704
|
* @since 4.4.0
|
|
2705
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date|Date}
|
|
2706
2706
|
* @param {string|number|Date} [value] 日期时间字符串、毫秒数、日期对象
|
|
2707
2707
|
* @param {...number} args 月/日/时/分/秒/毫秒
|
|
2708
2708
|
* @returns {Date} Date 实例日期对象
|
|
@@ -3156,8 +3156,8 @@
|
|
|
3156
3156
|
* @static
|
|
3157
3157
|
* @alias module:Other.calculateCursorPosition
|
|
3158
3158
|
* @since 4.6.0
|
|
3159
|
-
* @see
|
|
3160
|
-
* @see
|
|
3159
|
+
* @see {@link https://2950v9.csb.app/|h5示例}
|
|
3160
|
+
* @see {@link https://33ccy9.csb.app/|react示例}
|
|
3161
3161
|
* @param {number} prevPos 赋值前的光标位置,onChange/onInput的光标位置 e.target.selectionEnd
|
|
3162
3162
|
* @param {string} prevCtrlValue 上一个格式化后的值
|
|
3163
3163
|
* @param {string} rawValue 当前输入原值
|
|
@@ -3236,13 +3236,13 @@
|
|
|
3236
3236
|
/**
|
|
3237
3237
|
* @callback TransformRequest
|
|
3238
3238
|
* @param {AjaxOptions} options ajax 配置项
|
|
3239
|
-
* @returns {AjaxOptions}
|
|
3239
|
+
* @returns {AjaxOptions | Promise<AjaxOptions>}
|
|
3240
3240
|
*/
|
|
3241
3241
|
|
|
3242
3242
|
/**
|
|
3243
3243
|
* @callback TransformResponse
|
|
3244
3244
|
* @param {Blob} res 响应的Blob对象。如果你通过 transformRequest 修改了 responseType ,该参数将是该类型响应值。
|
|
3245
|
-
* @returns {Blob}
|
|
3245
|
+
* @returns {Blob | Promise<Blob>}
|
|
3246
3246
|
*/
|
|
3247
3247
|
|
|
3248
3248
|
/**
|
|
@@ -3262,7 +3262,8 @@
|
|
|
3262
3262
|
* @static
|
|
3263
3263
|
* @alias module:Other.download
|
|
3264
3264
|
* @since 4.16.0
|
|
3265
|
-
* @see {@link https://zh.wikipedia.org/wiki
|
|
3265
|
+
* @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展|MIME}
|
|
3266
|
+
* @see {@link https://9ykc9s.csb.app/|在线示例}
|
|
3266
3267
|
* @param {string|Blob|ArrayBuffer|Int8Array|Uint8Array|Uint8ClampedArray|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array|BigInt64Array|BigUint64Array} data 字符串、blob数据或url地址
|
|
3267
3268
|
* @param {string|DownloadOptions} [options] 文件名称 或 配置项
|
|
3268
3269
|
* @returns {Promise<void>}
|
|
@@ -3302,21 +3303,34 @@
|
|
|
3302
3303
|
payload = dataURLToBlob(data);
|
|
3303
3304
|
} else if (dataType === 'url' || !dataType && isUrl(data)) {
|
|
3304
3305
|
// url
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3306
|
+
// 包装为异步方法
|
|
3307
|
+
/** @type {(opts: AjaxOptions)=>Promise<AjaxOptions>} */
|
|
3308
|
+
var asyncTransformRequest = function asyncTransformRequest(opts) {
|
|
3309
|
+
// 请求前配置调整
|
|
3310
|
+
var tempOptions = typeof transformRequest === 'function' ? transformRequest(opts) : opts;
|
|
3311
|
+
// @ts-ignore
|
|
3312
|
+
return isPromiseLike(tempOptions) ? tempOptions : Promise.resolve(tempOptions);
|
|
3308
3313
|
};
|
|
3309
|
-
|
|
3310
|
-
var
|
|
3311
|
-
|
|
3312
|
-
/** @type {Blob} */
|
|
3314
|
+
/** @type {(res: Blob)=>Promise<Blob>} */
|
|
3315
|
+
var asyncTransformResponse = function asyncTransformResponse(res) {
|
|
3316
|
+
var tempRes = typeof transformResponse === 'function' ? transformResponse(res) : res;
|
|
3313
3317
|
// @ts-ignore
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3318
|
+
return isPromiseLike(tempRes) ? tempRes : Promise.resolve(tempRes);
|
|
3319
|
+
};
|
|
3320
|
+
|
|
3321
|
+
// 此处如果使用 async/await 语法糖,编译后的umd代码过大
|
|
3322
|
+
return asyncTransformRequest({
|
|
3323
|
+
responseType: 'blob'
|
|
3324
|
+
}).then(function (ajaxOptions) {
|
|
3325
|
+
return ajax(data, ajaxOptions).then(function (e) {
|
|
3326
|
+
// @ts-ignore
|
|
3327
|
+
return asyncTransformResponse(e.target.response).then(function (res) {
|
|
3328
|
+
var currentFileName = fileName || data.split("?")[0].split("#")[0].split("/").pop();
|
|
3329
|
+
return download(res, {
|
|
3330
|
+
fileName: currentFileName,
|
|
3331
|
+
type: type || (isBlob(res) ? res.type : undefined)
|
|
3332
|
+
});
|
|
3333
|
+
});
|
|
3320
3334
|
});
|
|
3321
3335
|
});
|
|
3322
3336
|
} else {
|