util-helpers 4.15.3 → 4.16.1

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 (102) hide show
  1. package/README.md +6 -5
  2. package/dist/util-helpers.js +491 -73
  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/ajax.js +149 -0
  7. package/esm/blobToDataURL.js +9 -13
  8. package/esm/calculateCursorPosition.js +2 -2
  9. package/esm/dataURLToBlob.js +7 -6
  10. package/esm/download.js +171 -0
  11. package/esm/fileReader.js +67 -0
  12. package/esm/index.js +6 -3
  13. package/esm/interface.doc.js +125 -0
  14. package/esm/isBankCard.js +1 -1
  15. package/esm/isBusinessLicense.js +1 -1
  16. package/esm/isChinese.js +3 -3
  17. package/esm/isHMCard.js +1 -1
  18. package/esm/isIdCard.js +2 -2
  19. package/esm/isPassport.js +1 -1
  20. package/esm/isPassword.js +2 -2
  21. package/esm/isSocialCreditCode.js +1 -1
  22. package/esm/isSwiftCode.js +1 -1
  23. package/esm/isTWCard.js +1 -1
  24. package/esm/isUrl.js +1 -1
  25. package/esm/isVehicle.js +1 -1
  26. package/esm/normalizeString.js +1 -1
  27. package/esm/numberToChinese.js +3 -2
  28. package/esm/parseIdCard.js +2 -2
  29. package/esm/safeDate.js +27 -10
  30. package/esm/setDataURLPrefix.js +2 -2
  31. package/esm/transformFieldNames.js +2 -3
  32. package/esm/utils/config.js +1 -1
  33. package/esm/utils/type/index.js +3 -1
  34. package/esm/utils/type/isArrayBuffer.js +25 -0
  35. package/esm/utils/type/isBlob.js +27 -0
  36. package/esm/validatePassword.js +1 -1
  37. package/lib/ajax.js +156 -0
  38. package/lib/blobToDataURL.js +9 -13
  39. package/lib/calculateCursorPosition.js +2 -2
  40. package/lib/dataURLToBlob.js +7 -6
  41. package/lib/download.js +176 -0
  42. package/lib/fileReader.js +74 -0
  43. package/lib/index.js +22 -1
  44. package/lib/interface.doc.js +127 -0
  45. package/lib/isBankCard.js +1 -1
  46. package/lib/isBusinessLicense.js +1 -1
  47. package/lib/isChinese.js +3 -3
  48. package/lib/isHMCard.js +1 -1
  49. package/lib/isIdCard.js +2 -2
  50. package/lib/isPassport.js +1 -1
  51. package/lib/isPassword.js +2 -2
  52. package/lib/isSocialCreditCode.js +1 -1
  53. package/lib/isSwiftCode.js +1 -1
  54. package/lib/isTWCard.js +1 -1
  55. package/lib/isUrl.js +1 -1
  56. package/lib/isVehicle.js +1 -1
  57. package/lib/normalizeString.js +1 -1
  58. package/lib/numberToChinese.js +3 -2
  59. package/lib/parseIdCard.js +2 -2
  60. package/lib/safeDate.js +28 -11
  61. package/lib/setDataURLPrefix.js +2 -2
  62. package/lib/transformFieldNames.js +1 -1
  63. package/lib/utils/config.js +1 -1
  64. package/lib/utils/type/index.js +14 -0
  65. package/lib/utils/type/isArrayBuffer.js +32 -0
  66. package/lib/utils/type/isBlob.js +34 -0
  67. package/lib/validatePassword.js +1 -1
  68. package/package.json +2 -2
  69. package/types/ajax.d.ts +121 -0
  70. package/types/blobToDataURL.d.ts +6 -2
  71. package/types/calculateCursorPosition.d.ts +2 -2
  72. package/types/dataURLToBlob.d.ts +1 -1
  73. package/types/download.d.ts +78 -0
  74. package/types/fileReader.d.ts +3 -0
  75. package/types/index.d.ts +4 -1
  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/numberToChinese.d.ts +3 -2
  90. package/types/parseIdCard.d.ts +3 -3
  91. package/types/safeDate.d.ts +3 -23
  92. package/types/setDataURLPrefix.d.ts +2 -2
  93. package/types/transformFieldNames.d.ts +2 -2
  94. package/types/utils/type/index.d.ts +21 -19
  95. package/types/utils/type/isArrayBuffer.d.ts +21 -0
  96. package/types/utils/type/isBlob.d.ts +23 -0
  97. package/types/validatePassword.d.ts +1 -1
  98. package/esm/transformFieldNames.doc.js +0 -35
  99. package/lib/transformFieldNames.doc.js +0 -42
  100. /package/esm/{transformFieldNames.type.js → interface.type.js} +0 -0
  101. /package/lib/{transformFieldNames.type.js → interface.type.js} +0 -0
  102. /package/types/{transformFieldNames.type.d.ts → interface.type.d.ts} +0 -0
package/lib/safeDate.js CHANGED
@@ -4,21 +4,42 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _isNil = _interopRequireDefault(require("./utils/type/isNil"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
7
  function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
10
8
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
11
9
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
- // TODO: 函数重载,类型参照 Date
10
+ /**
11
+ * @overload
12
+ * @return {Date}
13
+ */
14
+
15
+ /**
16
+ * @overload
17
+ * @param {number | string | Date} value Unix时间戳、时间戳字符串 dateString 、Date 日期对象
18
+ * @return {Date}
19
+ */
20
+
21
+ /**
22
+ * @overload
23
+ * @param {number} year 表示年份的整数值。0 到 99 会被映射至 1900 年至 1999 年,其他值代表实际年份。
24
+ * @param {number} monthIndex 表示月份的整数值,从 0(1 月)到 11(12 月)。
25
+ * @param {number} [date] 表示一个月中的第几天的整数值,从 1 开始。默认值为 1。
26
+ * @param {number} [hours] 表示一天中的小时数的整数值 (24 小时制)。默认值为 0(午夜)。
27
+ * @param {number} [minutes] 表示一个完整时间(如 01:10:00)中的分钟部分的整数值。默认值为 0。
28
+ * @param {number} [seconds] 表示一个完整时间(如 01:10:00)中的秒部分的整数值。默认值为 0。
29
+ * @param {number} [ms] 表示一个完整时间的毫秒部分的整数值。默认值为 0。
30
+ * @return {Date}
31
+ */
13
32
 
14
33
  /**
15
- * 创建一个 Date 实例日期对象,同 new Date() 。<br/>
16
- * 规避了苹果设备浏览器不支持部分格式(YYYY-MM-DD HH-mm 或 YYYY.MM.DD)。
34
+ * 创建一个 Date 实例日期对象,同 <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date#%E5%8F%82%E6%95%B0">new Date()</a> <br/><br/>
35
+ *
36
+ * 规避了苹果设备浏览器不支持部分格式(例如,YYYY-MM-DD HH-mm 或 YYYY.MM.DD)。<br/>
37
+ * 如果参数为 undefined 正常返回 Date 。
17
38
  *
18
39
  * @static
19
40
  * @alias module:Processor.safeDate
20
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date|Date}
21
41
  * @since 4.4.0
42
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date|Date}
22
43
  * @param {string|number|Date} [value] 日期时间字符串、毫秒数、日期对象
23
44
  * @param {...number} args 月/日/时/分/秒/毫秒
24
45
  * @returns {Date} Date 实例日期对象
@@ -30,8 +51,6 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Objec
30
51
  * safeDate('2022.1.1 11:11'); // Sat Jan 01 2022 11:11:00 GMT+0800 (中国标准时间)
31
52
  * safeDate(99, 1); // Mon Feb 01 1999 00:00:00 GMT+0800 (中国标准时间)
32
53
  * safeDate(1646711233171); // Tue Mar 08 2022 11:47:13 GMT+0800 (中国标准时间)
33
- *
34
- *
35
54
  */
36
55
  function safeDate(value) {
37
56
  var safeValue = typeof value === 'string' ? value.replace(/[\\.-]/g, '/') : value;
@@ -42,9 +61,7 @@ function safeDate(value) {
42
61
  // @ts-ignore
43
62
  return _construct(Date, [safeValue].concat(args));
44
63
  }
45
-
46
- // @ts-ignore
47
- return (0, _isNil["default"])(safeValue) ? new Date() : new Date(safeValue);
64
+ return typeof safeValue === 'undefined' ? new Date() : new Date(safeValue);
48
65
  }
49
66
  var _default = safeDate;
50
67
  exports["default"] = _default;
@@ -10,9 +10,9 @@ exports["default"] = void 0;
10
10
  *
11
11
  * @static
12
12
  * @alias module:Processor.setDataURLPrefix
13
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/Data_URIs|Data URLs}
14
- * @see 参考 {@link https://mimesniff.spec.whatwg.org/#understanding-mime-types|MIME types}
15
13
  * @since 4.1.0
14
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/Data_URIs|Data URLs}
15
+ * @see {@link https://mimesniff.spec.whatwg.org/#understanding-mime-types|MIME types}
16
16
  * @param {string} data 数据本身
17
17
  * @param {string} [mimetype="image/png"] MIME 类型
18
18
  * @param {boolean} [base64=true] 添加 base64 标识
@@ -24,7 +24,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
24
24
  * @param {F} fieldNames 字段名映射
25
25
  * @param {C} [childrenField] 子级数据字段名
26
26
  * @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
27
- * @returns {import('./transformFieldNames.type.js').TransformFieldNames<D, F, C>}
27
+ * @returns {import('./interface.type.js').TransformFieldNames<D, F, C>}
28
28
  * @example
29
29
  *
30
30
  * const options = [{code: '1', name: 'one'},{code:'2', name:'two'}];
@@ -24,5 +24,5 @@ function setDisableWarning(bool) {
24
24
  }
25
25
 
26
26
  // eslint-disable-next-line no-undef
27
- var version = "4.15.3";
27
+ var version = "4.16.1";
28
28
  exports.version = version;
@@ -15,6 +15,18 @@ Object.defineProperty(exports, "isArray", {
15
15
  return _isArray["default"];
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "isArrayBuffer", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _isArrayBuffer["default"];
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "isBlob", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _isBlob["default"];
28
+ }
29
+ });
18
30
  Object.defineProperty(exports, "isBoolean", {
19
31
  enumerable: true,
20
32
  get: function get() {
@@ -113,6 +125,8 @@ Object.defineProperty(exports, "isWeakSet", {
113
125
  });
114
126
  var _isArguments = _interopRequireDefault(require("./isArguments"));
115
127
  var _isArray = _interopRequireDefault(require("./isArray"));
128
+ var _isArrayBuffer = _interopRequireDefault(require("./isArrayBuffer"));
129
+ var _isBlob = _interopRequireDefault(require("./isBlob"));
116
130
  var _isBoolean = _interopRequireDefault(require("./isBoolean"));
117
131
  var _isDate = _interopRequireDefault(require("./isDate"));
118
132
  var _isError = _interopRequireDefault(require("./isError"));
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _isType = _interopRequireDefault(require("./isType"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ /**
10
+ * 检查值是否为ArrayBuffer对象
11
+ *
12
+ * @static
13
+ * @alias module:Type.isArrayBuffer
14
+ * @since 4.16.0
15
+ * @param {*} value 检查值
16
+ * @returns {boolean} 是否为ArrayBuffer对象
17
+ * @example
18
+ *
19
+ * isArrayBuffer(new ArrayBuffer(8))
20
+ * // => true
21
+ *
22
+ * isArrayBuffer({})
23
+ * // => false
24
+ *
25
+ * isArrayBuffer('2012')
26
+ * // => false
27
+ */
28
+ function isArrayBuffer(value) {
29
+ return (0, _isType["default"])(value, 'ArrayBuffer');
30
+ }
31
+ var _default = isArrayBuffer;
32
+ exports["default"] = _default;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _isType = _interopRequireDefault(require("./isType"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ /**
10
+ * 检查值是否为Blob对象<br/><br/>
11
+ *
12
+ * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
13
+ *
14
+ * @static
15
+ * @alias module:Type.isBlob
16
+ * @since 4.16.0
17
+ * @param {*} value 检查值
18
+ * @returns {boolean} 是否为Blob对象
19
+ * @example
20
+ *
21
+ * isBlob(new Blob(['a']))
22
+ * // => true
23
+ *
24
+ * isBlob({})
25
+ * // => false
26
+ *
27
+ * isBlob('2012')
28
+ * // => false
29
+ */
30
+ function isBlob(value) {
31
+ return (0, _isType["default"])(value, 'Blob');
32
+ }
33
+ var _default = isBlob;
34
+ exports["default"] = _default;
@@ -136,10 +136,10 @@ function hasUnallowableCharacter(val, chars) {
136
136
  /**
137
137
  * 验证密码(数字、大小写字母、特殊字符、非法字符)
138
138
  *
139
- * @see 参考 {@link https://baike.baidu.com/item/ASCII#3|ASCII}
140
139
  * @static
141
140
  * @alias module:Validator.validatePassword
142
141
  * @since 3.7.0
142
+ * @see {@link https://baike.baidu.com/item/ASCII#3|ASCII}
143
143
  * @param {string} value 要检测的值
144
144
  * @param {Object} [options] 配置项
145
145
  * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "4.15.3",
3
+ "version": "4.16.1",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -84,7 +84,7 @@
84
84
  "prettier": "^2.3.2",
85
85
  "rollup": "^2.49.0",
86
86
  "rollup-plugin-terser": "^7.0.2",
87
- "typescript": "^4.9.3"
87
+ "typescript": "^5.0.4"
88
88
  },
89
89
  "lint-staged": {
90
90
  "**/*.js": "npm run lint-staged:js",
@@ -0,0 +1,121 @@
1
+ export default ajax;
2
+ /**
3
+ * XMLHttpRequest 事件对象
4
+ */
5
+ export type XMLHttpRequestEvent = XMLHttpRequest['onloadstart'];
6
+ /**
7
+ * ajax配置项
8
+ */
9
+ export type AjaxOptions = {
10
+ /**
11
+ * 创建请求时使用的方法
12
+ */
13
+ method?: string | undefined;
14
+ /**
15
+ * 请求体被发送的数据
16
+ */
17
+ data?: Document | XMLHttpRequestBodyInit | null | undefined;
18
+ /**
19
+ * 自定义请求头
20
+ */
21
+ headers?: {
22
+ [x: string]: string;
23
+ } | undefined;
24
+ /**
25
+ * 响应类型
26
+ */
27
+ responseType?: XMLHttpRequestResponseType | undefined;
28
+ /**
29
+ * 请求超时的毫秒数
30
+ */
31
+ timeout?: number | undefined;
32
+ /**
33
+ * 跨域请求时是否需要使用凭证
34
+ */
35
+ withCredentials?: boolean | undefined;
36
+ /**
37
+ * 是否异步执行操作
38
+ */
39
+ async?: boolean | undefined;
40
+ /**
41
+ * 用户名,用于认证用途
42
+ */
43
+ user?: string | null | undefined;
44
+ /**
45
+ * 密码,用于认证用途
46
+ */
47
+ password?: string | null | undefined;
48
+ /**
49
+ * 接收到响应数据时触发
50
+ */
51
+ onLoadStart?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
52
+ /**
53
+ * 请求接收到更多数据时,周期性地触发
54
+ */
55
+ onProgress?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
56
+ /**
57
+ * 当 request 被停止时触发,例如当程序调用 XMLHttpRequest.abort() 时
58
+ */
59
+ onAbort?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
60
+ /**
61
+ * 在预设时间内没有接收到响应时触发
62
+ */
63
+ onTimeout?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
64
+ /**
65
+ * 当 request 遭遇错误时触发
66
+ */
67
+ onError?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
68
+ /**
69
+ * 请求成功完成时触发
70
+ */
71
+ onLoad?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
72
+ /**
73
+ * 请求结束时触发,无论请求成功 (load) 还是失败 (abort 或 error)
74
+ */
75
+ onLoadEnd?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
76
+ };
77
+ /**
78
+ * @typedef {XMLHttpRequest['onloadstart']} XMLHttpRequestEvent XMLHttpRequest 事件对象
79
+ */
80
+ /**
81
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
82
+ * @typedef {Object} AjaxOptions ajax配置项
83
+ * @property {string} [method="get"] 创建请求时使用的方法
84
+ * @property {Document | XMLHttpRequestBodyInit | null} [data=null] 请求体被发送的数据
85
+ * @property {Object.<string, string>} [headers] 自定义请求头
86
+ * @property {XMLHttpRequestResponseType} [responseType] 响应类型
87
+ * @property {number} [timeout] 请求超时的毫秒数
88
+ * @property {boolean} [withCredentials=false] 跨域请求时是否需要使用凭证
89
+ * @property {boolean} [async=true] 是否异步执行操作
90
+ * @property {string|null} [user=null] 用户名,用于认证用途
91
+ * @property {string|null} [password=null] 密码,用于认证用途
92
+ * @property {XMLHttpRequestEvent} [onLoadStart] 接收到响应数据时触发
93
+ * @property {XMLHttpRequestEvent} [onProgress] 请求接收到更多数据时,周期性地触发
94
+ * @property {XMLHttpRequestEvent} [onAbort] 当 request 被停止时触发,例如当程序调用 XMLHttpRequest.abort() 时
95
+ * @property {XMLHttpRequestEvent} [onTimeout] 在预设时间内没有接收到响应时触发
96
+ * @property {XMLHttpRequestEvent} [onError] 当 request 遭遇错误时触发
97
+ * @property {XMLHttpRequestEvent} [onLoad] 请求成功完成时触发
98
+ * @property {XMLHttpRequestEvent} [onLoadEnd] 请求结束时触发,无论请求成功 (load) 还是失败 (abort 或 error)
99
+ */
100
+ /**
101
+ * 请求<br/><br/>
102
+ *
103
+ * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
104
+ *
105
+ * @static
106
+ * @alias module:Other.ajax
107
+ * @since 4.16.0
108
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
109
+ * @param {string} url 地址
110
+ * @param {AjaxOptions} [options] 配置项
111
+ * @returns {Promise<ProgressEvent<EventTarget>>}
112
+ * @example
113
+ * ajax('/somefile').then(res=>{
114
+ * // do something
115
+ * });
116
+ *
117
+ * ajax('/api', { method: 'post' }).then(res=>{
118
+ * // do something
119
+ * });
120
+ */
121
+ declare function ajax(url: string, options?: AjaxOptions | undefined): Promise<ProgressEvent<EventTarget>>;
@@ -1,11 +1,15 @@
1
1
  export default blobToDataURL;
2
2
  /**
3
- * 将 Blob 或 File 对象转成 data:URL 格式的 Base64 字符串。
3
+ * 将 Blob 或 File 对象转成 data:URL 格式的 Base64 字符串<br/><br/>
4
4
  *
5
+ * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
6
+ *
7
+ * @ignore
5
8
  * @static
6
9
  * @alias module:Processor.blobToDataURL
7
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL|FileReader.readAsDataURL()}
8
10
  * @since 4.1.0
11
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL|FileReader.readAsDataURL()}
12
+ * @deprecated 请使用 `fileReader` 方法
9
13
  * @param {Blob} blob Blob 或 File 对象
10
14
  * @returns {Promise<string>} data:URL 格式的 Base64 字符串。
11
15
  * @example
@@ -5,8 +5,8 @@ export default calculateCursorPosition;
5
5
  * @static
6
6
  * @alias module:Other.calculateCursorPosition
7
7
  * @since 4.6.0
8
- * @see h5示例 {@link https://2950v9.csb.app/|点击查看}
9
- * @see react示例 {@link https://33ccy9.csb.app/|点击查看}
8
+ * @see {@link https://2950v9.csb.app/|h5示例}
9
+ * @see {@link https://33ccy9.csb.app/|react示例}
10
10
  * @param {number} prevPos 赋值前的光标位置,onChange/onInput的光标位置 e.target.selectionEnd
11
11
  * @param {string} prevCtrlValue 上一个格式化后的值
12
12
  * @param {string} rawValue 当前输入原值
@@ -4,8 +4,8 @@ export default dataURLToBlob;
4
4
  *
5
5
  * @static
6
6
  * @alias module:Processor.dataURLToBlob
7
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64|Base64}
8
7
  * @since 4.1.0
8
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64|Base64}
9
9
  * @param {string} dataurl data: 协议的URL
10
10
  * @returns {Blob} Blob 对象
11
11
  * @example
@@ -0,0 +1,78 @@
1
+ export default download;
2
+ /**
3
+ * ajax 配置项
4
+ */
5
+ export type AjaxOptions = import('./ajax.js').AjaxOptions;
6
+ export type TransformRequest = (options: AjaxOptions) => AjaxOptions | Promise<AjaxOptions>;
7
+ export type TransformResponse = (res: Blob) => Blob | Promise<Blob>;
8
+ /**
9
+ * 下载配置项
10
+ */
11
+ export type DownloadOptions = {
12
+ /**
13
+ * 文件名称
14
+ */
15
+ fileName?: string | undefined;
16
+ /**
17
+ * MIME 类型
18
+ */
19
+ type?: string | undefined;
20
+ /**
21
+ * 手动设置数据类型,默认会根据传入的数据判断类型,主要是为了区分 url 和 text 。<br/>如果你要下载的文本是 url ,请设置 'text' ;如果你要下载的 url 是绝对/相对路径,请设置 'url' 。
22
+ */
23
+ dataType?: "text" | "url" | undefined;
24
+ /**
25
+ * 请求前触发,XHR 对象或配置调整
26
+ */
27
+ transformRequest?: TransformRequest | undefined;
28
+ /**
29
+ * 请求成功后触发,在传递给 then/catch 前,允许修改响应数据
30
+ */
31
+ transformResponse?: TransformResponse | undefined;
32
+ };
33
+ /**
34
+ * @typedef {import('./ajax.js').AjaxOptions} AjaxOptions ajax 配置项
35
+ */
36
+ /**
37
+ * @callback TransformRequest
38
+ * @param {AjaxOptions} options ajax 配置项
39
+ * @returns {AjaxOptions | Promise<AjaxOptions>}
40
+ */
41
+ /**
42
+ * @callback TransformResponse
43
+ * @param {Blob} res 响应的Blob对象。如果你通过 transformRequest 修改了 responseType ,该参数将是该类型响应值。
44
+ * @returns {Blob | Promise<Blob>}
45
+ */
46
+ /**
47
+ * @typedef {Object} DownloadOptions 下载配置项
48
+ * @property {string} [options.fileName] 文件名称
49
+ * @property {string} [options.type] MIME 类型
50
+ * @property {'url'|'text'} [options.dataType] 手动设置数据类型,默认会根据传入的数据判断类型,主要是为了区分 url 和 text 。<br/>如果你要下载的文本是 url ,请设置 'text' ;如果你要下载的 url 是绝对/相对路径,请设置 'url' 。
51
+ * @property {TransformRequest} [options.transformRequest] 请求前触发,XHR 对象或配置调整
52
+ * @property {TransformResponse} [options.transformResponse] 请求成功后触发,在传递给 then/catch 前,允许修改响应数据
53
+ */
54
+ /**
55
+ * 下载<br/><br/>
56
+ *
57
+ * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端,兼容 IE10+ 和现代浏览器。</em>
58
+ *
59
+ * @static
60
+ * @alias module:Other.download
61
+ * @since 4.16.0
62
+ * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展|MIME}
63
+ * @see {@link https://9ykc9s.csb.app/|在线示例}
64
+ * @param {string|Blob|ArrayBuffer|Int8Array|Uint8Array|Uint8ClampedArray|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array|BigInt64Array|BigUint64Array} data 字符串、blob数据或url地址
65
+ * @param {string|DownloadOptions} [options] 文件名称 或 配置项
66
+ * @returns {Promise<void>}
67
+ * @example
68
+ * // 文本
69
+ * download('hello world', 'text.txt');
70
+ *
71
+ * // 远程文件
72
+ * download('/xxx.jpg', { dataType: 'url' });
73
+ *
74
+ * // blob文件
75
+ * download(new Blob(['hello world']), 'text.txt');
76
+ *
77
+ */
78
+ declare function download(data: string | Blob | ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array, options?: string | DownloadOptions | undefined): Promise<void>;
@@ -0,0 +1,3 @@
1
+ export default fileReader;
2
+ declare function fileReader(blob: Blob, type: 'arrayBuffer'): Promise<ArrayBuffer>;
3
+ declare function fileReader(blob: Blob, type?: "text" | "binaryString" | "dataURL" | undefined): Promise<string>;
package/types/index.d.ts CHANGED
@@ -27,6 +27,7 @@ export { default as numberToChinese } from "./numberToChinese";
27
27
  export { default as bytesToSize } from "./bytesToSize";
28
28
  export { default as parseIdCard } from "./parseIdCard";
29
29
  export { default as blobToDataURL } from "./blobToDataURL";
30
+ export { default as fileReader } from "./fileReader";
30
31
  export { default as dataURLToBlob } from "./dataURLToBlob";
31
32
  export { default as setDataURLPrefix } from "./setDataURLPrefix";
32
33
  export { default as normalizeString } from "./normalizeString";
@@ -38,10 +39,12 @@ export { default as minus } from "./minus";
38
39
  export { default as times } from "./times";
39
40
  export { default as divide } from "./divide";
40
41
  export { default as round } from "./round";
41
- export { default as waitTime } from "./waitTime";
42
+ export { default as ajax } from "./ajax";
42
43
  export { default as calculateCursorPosition } from "./calculateCursorPosition";
44
+ export { default as download } from "./download";
43
45
  export { default as randomString } from "./randomString";
44
46
  export { default as strlen } from "./strlen";
47
+ export { default as waitTime } from "./waitTime";
45
48
  export { default as transformFieldNames } from "./transformFieldNames";
46
49
  export { default as listToTree } from "./listToTree";
47
50
  export { default as treeToList } from "./treeToList";
@@ -4,8 +4,8 @@ export default isBankCard;
4
4
  *
5
5
  * @static
6
6
  * @alias module:Validator.isBankCard
7
- * @see 参考 {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html|常用银行账号位数参考}
8
7
  * @since 1.1.0
8
+ * @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html|常用银行账号位数参考}
9
9
  * @param {*} value 要检测的值
10
10
  * @param {Object} [options] 配置项
11
11
  * @param {boolean} [options.loose=false] 宽松模式,8~30位数字
@@ -4,8 +4,8 @@ export default isBusinessLicense;
4
4
  *
5
5
  * @static
6
6
  * @alias module:Validator.isBusinessLicense
7
- * @see 参考 {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html|GS15—2006 工商行政管理市场主体注册号编制规则}
8
7
  * @since 3.5.0
8
+ * @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html|GS15—2006 工商行政管理市场主体注册号编制规则}
9
9
  * @param {*} value 要检测的值
10
10
  * @param {Object} [options] 配置项
11
11
  * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
@@ -5,9 +5,9 @@ export default isChinese;
5
5
  * @static
6
6
  * @alias module:Validator.isChinese
7
7
  * @since 1.1.0
8
- * @see 参考 {@link http://www.unicode.org/reports/tr38/#BlockListing|4.4 Listing of Characters Covered by the Unihan Database}
9
- * @see 参考 {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射|Unicode字符平面映射}
10
- * @see 参考 {@link https://zh.wikipedia.org/wiki/Unicode區段|Unicode区段}
8
+ * @see {@link http://www.unicode.org/reports/tr38/#BlockListing|4.4 Listing of Characters Covered by the Unihan Database}
9
+ * @see {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射|Unicode字符平面映射}
10
+ * @see {@link https://zh.wikipedia.org/wiki/Unicode區段|Unicode区段}
11
11
  * @param {*} value 要检测的值
12
12
  * @param {Object} [options] 配置项
13
13
  * @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
@@ -5,7 +5,7 @@ export default isHMCard;
5
5
  * @static
6
6
  * @alias module:Validator.isHMCard
7
7
  * @since 4.0.0
8
- * @see 参考 {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证|港澳居民来往内地通行证}
8
+ * @see {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证|港澳居民来往内地通行证}
9
9
  * @param {*} value 要检测的值
10
10
  * @returns {boolean} 是否为港澳居民来往内地通行证
11
11
  * @example
@@ -5,8 +5,8 @@ export default isIdCard;
5
5
  * @static
6
6
  * @alias module:Validator.isIdCard
7
7
  * @since 1.1.0
8
- * @see 参考 {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码|中华人民共和国公民身份号码}
9
- * @see 参考 {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
8
+ * @see {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码|中华人民共和国公民身份号码}
9
+ * @see {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
10
10
  * @param {*} value 要检测的值
11
11
  * @param {Object} [options] 配置项
12
12
  * @param {boolean} [options.loose=false] 宽松模式,支持15位身份证号码
@@ -5,8 +5,8 @@ export default isPassport;
5
5
  *
6
6
  * @static
7
7
  * @alias module:Validator.isPassport
8
- * @see 参考 {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页|中华人民共和国护照#个人资料页}
9
8
  * @since 1.1.0
9
+ * @see {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页|中华人民共和国护照#个人资料页}
10
10
  * @param {*} value 要检测的值
11
11
  * @returns {boolean} 值是否为护照号
12
12
  * @example
@@ -4,11 +4,11 @@ export default isPassword;
4
4
  * <p><strong>注意:该校验只校验是否存在不同字符(大小写字母、数字、特殊符号),不判断长度。</strong></p>
5
5
  * <p><i>如果需要更细致的验证,请使用 <a href="#.validatePassword">validatePassword</a></i></p>
6
6
  *
7
- * @see 参考 {@link https://baike.baidu.com/item/ASCII#3|ASCII}
8
7
  * @static
9
8
  * @alias module:Validator.isPassword
10
- * @since 1.1.0
11
9
  * @requires module:Validator.validatePassword
10
+ * @since 1.1.0
11
+ * @see {@link https://baike.baidu.com/item/ASCII#3|ASCII}
12
12
  * @param {*} value 要检测的值
13
13
  * @param {Object} [options] 配置项
14
14
  * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
@@ -4,8 +4,8 @@ export default isSocialCreditCode;
4
4
  *
5
5
  * @static
6
6
  * @alias module:Validator.isSocialCreditCode
7
- * @see 参考 {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则|GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
8
7
  * @since 1.1.0
8
+ * @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则|GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
9
9
  * @param {*} value 要检测的值
10
10
  * @param {Object} [options] 配置项
11
11
  * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
@@ -4,8 +4,8 @@ export default isSwiftCode;
4
4
  *
5
5
  * @static
6
6
  * @alias module:Validator.isSwiftCode
7
- * @see 参考 {@link https://zh.wikipedia.org/wiki/ISO_9362|ISO 9362}
8
7
  * @since 4.9.0
8
+ * @see {@link https://zh.wikipedia.org/wiki/ISO_9362|ISO 9362}
9
9
  * @param {*} value 要检测的值
10
10
  * @returns {boolean} 值是否为 Swift Code
11
11
  * @example
@@ -5,7 +5,7 @@ export default isTWCard;
5
5
  * @static
6
6
  * @alias module:Validator.isTWCard
7
7
  * @since 4.0.0
8
- * @see 参考 {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
8
+ * @see {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
9
9
  * @param {*} value 要检测的值
10
10
  * @param {Object} [options] 配置项
11
11
  * @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
package/types/isUrl.d.ts CHANGED
@@ -5,7 +5,7 @@ export default isUrl;
5
5
  * @static
6
6
  * @alias module:Validator.isUrl
7
7
  * @since 3.4.0
8
- * @see 参考 {@link https://zh.wikipedia.org/wiki/统一资源定位符|统一资源定位符}
8
+ * @see {@link https://zh.wikipedia.org/wiki/统一资源定位符|统一资源定位符}
9
9
  * @param {*} value 要检测的值
10
10
  * @returns {boolean} 值是否为url
11
11
  * @example
@@ -4,8 +4,8 @@ export default isVehicle;
4
4
  *
5
5
  * @static
6
6
  * @alias module:Validator.isVehicle
7
- * @see 参考 {@link https://baike.baidu.com/item/车牌号|车牌号}
8
7
  * @since 1.1.0
8
+ * @see {@link https://baike.baidu.com/item/车牌号|车牌号}
9
9
  * @param {*} value 要检测的值
10
10
  * @returns {boolean} 值是否为车牌号
11
11
  * @example
@@ -4,8 +4,8 @@ export default normalizeString;
4
4
  *
5
5
  * @static
6
6
  * @alias module:Processor.normalizeString
7
- * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
8
7
  * @since 4.3.0
8
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
9
9
  * @param {*} value 待处理的值
10
10
  * @returns {string} 规整化的值
11
11
  * @example