util-helpers 4.16.2 → 4.17.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 (259) hide show
  1. package/dist/util-helpers.js +1600 -4039
  2. package/dist/util-helpers.js.map +1 -1
  3. package/dist/util-helpers.min.js +1 -1
  4. package/dist/util-helpers.min.js.map +1 -1
  5. package/esm/ajax.js +50 -146
  6. package/esm/blobToDataURL.js +4 -34
  7. package/esm/bytesToSize.js +12 -37
  8. package/esm/calculateCursorPosition.js +30 -52
  9. package/esm/dataURLToBlob.js +14 -28
  10. package/esm/divide.js +24 -48
  11. package/esm/download.js +83 -164
  12. package/esm/fileReader.js +18 -64
  13. package/esm/filterTree.js +25 -55
  14. package/esm/findTreeNode.js +39 -67
  15. package/esm/findTreeNodes.js +35 -66
  16. package/esm/findTreeSelect.js +38 -74
  17. package/esm/formatBankCard.js +13 -43
  18. package/esm/formatMobile.js +17 -43
  19. package/esm/formatMoney.js +59 -139
  20. package/esm/index.js +55 -130
  21. package/esm/isBankCard.js +22 -57
  22. package/esm/isBusinessLicense.js +32 -78
  23. package/esm/isChinese.js +23 -66
  24. package/esm/isEmail.js +6 -21
  25. package/esm/isHMCard.js +5 -28
  26. package/esm/isIPv4.js +5 -22
  27. package/esm/isIPv6.js +5 -36
  28. package/esm/isIdCard.js +27 -66
  29. package/esm/isMobile.js +5 -20
  30. package/esm/isPassport.js +5 -22
  31. package/esm/isPassword.js +7 -48
  32. package/esm/isPostcode.js +5 -20
  33. package/esm/isPromiseLike.js +3 -18
  34. package/esm/isQQ.js +5 -20
  35. package/esm/isSocialCreditCode.js +28 -83
  36. package/esm/isSwiftCode.js +6 -25
  37. package/esm/isTWCard.js +11 -37
  38. package/esm/isTelephone.js +6 -27
  39. package/esm/isUrl.js +5 -44
  40. package/esm/isVehicle.js +5 -28
  41. package/esm/isWX.js +5 -20
  42. package/esm/listToTree.js +51 -120
  43. package/esm/minus.js +21 -39
  44. package/esm/normalizeString.js +8 -29
  45. package/esm/numberToChinese.js +96 -215
  46. package/esm/padZero.js +14 -36
  47. package/esm/parseIdCard.js +64 -129
  48. package/esm/plus.js +21 -39
  49. package/esm/randomString.js +13 -45
  50. package/esm/replaceChar.js +27 -77
  51. package/esm/round.js +14 -31
  52. package/esm/safeDate.js +12 -55
  53. package/esm/setDataURLPrefix.js +6 -29
  54. package/esm/strlen.js +14 -30
  55. package/esm/times.js +24 -42
  56. package/esm/transformFieldNames.js +37 -93
  57. package/esm/treeToList.js +25 -84
  58. package/esm/utils/config.js +4 -14
  59. package/esm/utils/constants.js +4 -4
  60. package/esm/utils/convertToString.js +4 -9
  61. package/esm/utils/devWarn.js +11 -11
  62. package/esm/utils/math.util.js +95 -181
  63. package/esm/utils/type/isBlob.js +4 -24
  64. package/esm/utils/type/isNaN.js +4 -19
  65. package/esm/utils/type/isNil.js +5 -13
  66. package/esm/utils/type/isNull.js +3 -18
  67. package/esm/utils/type/isNumber.js +4 -28
  68. package/esm/utils/type/isObject.js +4 -23
  69. package/esm/utils/type/isString.js +4 -19
  70. package/esm/utils/type/isSymbol.js +4 -19
  71. package/esm/utils/type/isType.js +3 -12
  72. package/esm/utils/type/isUndefined.js +3 -21
  73. package/esm/validatePassword.js +86 -237
  74. package/esm/waitTime.js +7 -26
  75. package/lib/ajax.js +51 -152
  76. package/lib/blobToDataURL.js +5 -40
  77. package/lib/bytesToSize.js +13 -43
  78. package/lib/calculateCursorPosition.js +32 -58
  79. package/lib/dataURLToBlob.js +15 -34
  80. package/lib/divide.js +26 -60
  81. package/lib/download.js +85 -169
  82. package/lib/fileReader.js +19 -70
  83. package/lib/filterTree.js +27 -66
  84. package/lib/findTreeNode.js +40 -77
  85. package/lib/findTreeNodes.js +36 -76
  86. package/lib/findTreeSelect.js +40 -82
  87. package/lib/formatBankCard.js +15 -50
  88. package/lib/formatMobile.js +19 -50
  89. package/lib/formatMoney.js +60 -150
  90. package/lib/index.js +117 -395
  91. package/lib/isBankCard.js +24 -64
  92. package/lib/isBusinessLicense.js +34 -85
  93. package/lib/isChinese.js +24 -73
  94. package/lib/isEmail.js +7 -27
  95. package/lib/isHMCard.js +7 -35
  96. package/lib/isIPv4.js +7 -29
  97. package/lib/isIPv6.js +7 -43
  98. package/lib/isIdCard.js +29 -73
  99. package/lib/isMobile.js +7 -27
  100. package/lib/isPassport.js +7 -29
  101. package/lib/isPassword.js +9 -55
  102. package/lib/isPostcode.js +7 -27
  103. package/lib/isPromiseLike.js +4 -24
  104. package/lib/isQQ.js +7 -27
  105. package/lib/isSocialCreditCode.js +30 -90
  106. package/lib/isSwiftCode.js +7 -32
  107. package/lib/isTWCard.js +13 -44
  108. package/lib/isTelephone.js +7 -33
  109. package/lib/isUrl.js +6 -49
  110. package/lib/isVehicle.js +7 -35
  111. package/lib/isWX.js +7 -27
  112. package/lib/listToTree.js +53 -131
  113. package/lib/minus.js +23 -51
  114. package/lib/normalizeString.js +10 -36
  115. package/lib/numberToChinese.js +98 -222
  116. package/lib/padZero.js +16 -43
  117. package/lib/parseIdCard.js +65 -138
  118. package/lib/plus.js +23 -51
  119. package/lib/randomString.js +14 -51
  120. package/lib/replaceChar.js +28 -83
  121. package/lib/round.js +15 -37
  122. package/lib/safeDate.js +13 -63
  123. package/lib/setDataURLPrefix.js +7 -35
  124. package/lib/strlen.js +16 -37
  125. package/lib/times.js +26 -53
  126. package/lib/transformFieldNames.js +38 -101
  127. package/lib/treeToList.js +27 -94
  128. package/lib/utils/config.js +6 -23
  129. package/lib/utils/constants.js +3 -11
  130. package/lib/utils/convertToString.js +6 -16
  131. package/lib/utils/devWarn.js +13 -17
  132. package/lib/utils/math.util.js +95 -185
  133. package/lib/utils/type/isBlob.js +6 -31
  134. package/lib/utils/type/isNaN.js +6 -26
  135. package/lib/utils/type/isNil.js +7 -20
  136. package/lib/utils/type/isNull.js +4 -24
  137. package/lib/utils/type/isNumber.js +6 -35
  138. package/lib/utils/type/isObject.js +5 -29
  139. package/lib/utils/type/isString.js +6 -26
  140. package/lib/utils/type/isSymbol.js +6 -26
  141. package/lib/utils/type/isType.js +4 -18
  142. package/lib/utils/type/isUndefined.js +4 -27
  143. package/lib/validatePassword.js +87 -244
  144. package/lib/waitTime.js +8 -32
  145. package/package.json +21 -25
  146. package/types/ajax.d.ts +38 -95
  147. package/types/blobToDataURL.d.ts +2 -2
  148. package/types/bytesToSize.d.ts +7 -6
  149. package/types/calculateCursorPosition.d.ts +10 -9
  150. package/types/dataURLToBlob.d.ts +5 -5
  151. package/types/divide.d.ts +2 -2
  152. package/types/download.d.ts +22 -38
  153. package/types/fileReader.d.ts +35 -2
  154. package/types/filterTree.d.ts +6 -7
  155. package/types/findTreeNode.d.ts +5 -7
  156. package/types/findTreeNodes.d.ts +5 -7
  157. package/types/findTreeSelect.d.ts +5 -7
  158. package/types/formatBankCard.d.ts +8 -5
  159. package/types/formatMobile.d.ts +7 -4
  160. package/types/formatMoney.d.ts +8 -7
  161. package/types/index.d.ts +125 -55
  162. package/types/isBankCard.d.ts +9 -8
  163. package/types/isBusinessLicense.d.ts +8 -5
  164. package/types/isChinese.d.ts +9 -8
  165. package/types/isEmail.d.ts +1 -1
  166. package/types/isHMCard.d.ts +2 -2
  167. package/types/isIPv4.d.ts +1 -1
  168. package/types/isIPv6.d.ts +1 -1
  169. package/types/isIdCard.d.ts +8 -7
  170. package/types/isMobile.d.ts +1 -1
  171. package/types/isPassport.d.ts +2 -2
  172. package/types/isPassword.d.ts +4 -7
  173. package/types/isPostcode.d.ts +1 -1
  174. package/types/isPromiseLike.d.ts +1 -1
  175. package/types/isQQ.d.ts +1 -1
  176. package/types/isSocialCreditCode.d.ts +8 -5
  177. package/types/isSwiftCode.d.ts +2 -2
  178. package/types/isTWCard.d.ts +6 -5
  179. package/types/isTelephone.d.ts +1 -1
  180. package/types/isUrl.d.ts +2 -2
  181. package/types/isVehicle.d.ts +2 -2
  182. package/types/isWX.d.ts +1 -1
  183. package/types/listToTree.d.ts +12 -12
  184. package/types/minus.d.ts +3 -2
  185. package/types/normalizeString.d.ts +2 -2
  186. package/types/numberToChinese.d.ts +13 -12
  187. package/types/padZero.d.ts +2 -2
  188. package/types/parseIdCard.d.ts +17 -56
  189. package/types/plus.d.ts +3 -2
  190. package/types/randomString.d.ts +2 -2
  191. package/types/replaceChar.d.ts +15 -11
  192. package/types/round.d.ts +2 -2
  193. package/types/safeDate.d.ts +24 -2
  194. package/types/setDataURLPrefix.d.ts +5 -5
  195. package/types/strlen.d.ts +1 -1
  196. package/types/times.d.ts +3 -2
  197. package/types/transformFieldNames.d.ts +12 -10
  198. package/types/treeToList.d.ts +1 -1
  199. package/types/utils/config.d.ts +6 -5
  200. package/types/utils/constants.d.ts +2 -2
  201. package/types/utils/convertToString.d.ts +1 -1
  202. package/types/utils/devWarn.d.ts +1 -1
  203. package/types/utils/math.util.d.ts +15 -9
  204. package/types/utils/type/index.d.ts +7 -0
  205. package/types/utils/type/isArguments.d.ts +1 -1
  206. package/types/utils/type/isArray.d.ts +1 -1
  207. package/types/utils/type/isArrayBuffer.d.ts +1 -1
  208. package/types/utils/type/isBlob.d.ts +1 -1
  209. package/types/utils/type/isBoolean.d.ts +1 -1
  210. package/types/utils/type/isDate.d.ts +1 -1
  211. package/types/utils/type/isError.d.ts +1 -1
  212. package/types/utils/type/isFunction.d.ts +1 -1
  213. package/types/utils/type/isMap.d.ts +1 -1
  214. package/types/utils/type/isNaN.d.ts +1 -1
  215. package/types/utils/type/isNil.d.ts +1 -1
  216. package/types/utils/type/isNull.d.ts +1 -1
  217. package/types/utils/type/isNumber.d.ts +1 -1
  218. package/types/utils/type/isObject.d.ts +1 -1
  219. package/types/utils/type/isRegExp.d.ts +1 -1
  220. package/types/utils/type/isSet.d.ts +1 -1
  221. package/types/utils/type/isString.d.ts +1 -1
  222. package/types/utils/type/isSymbol.d.ts +1 -1
  223. package/types/utils/type/isType.d.ts +1 -1
  224. package/types/utils/type/isUndefined.d.ts +1 -1
  225. package/types/utils/type/isWeakMap.d.ts +1 -1
  226. package/types/utils/type/isWeakSet.d.ts +1 -1
  227. package/types/validatePassword.d.ts +17 -48
  228. package/types/waitTime.d.ts +2 -2
  229. package/esm/interface.doc.js +0 -125
  230. package/esm/interface.type.js +0 -17
  231. package/esm/utils/type/index.js +0 -29
  232. package/esm/utils/type/isArguments.js +0 -22
  233. package/esm/utils/type/isArray.js +0 -22
  234. package/esm/utils/type/isArrayBuffer.js +0 -25
  235. package/esm/utils/type/isBoolean.js +0 -22
  236. package/esm/utils/type/isDate.js +0 -22
  237. package/esm/utils/type/isError.js +0 -22
  238. package/esm/utils/type/isFunction.js +0 -22
  239. package/esm/utils/type/isMap.js +0 -22
  240. package/esm/utils/type/isRegExp.js +0 -22
  241. package/esm/utils/type/isSet.js +0 -22
  242. package/esm/utils/type/isWeakMap.js +0 -22
  243. package/esm/utils/type/isWeakSet.js +0 -22
  244. package/lib/interface.doc.js +0 -127
  245. package/lib/interface.type.js +0 -5
  246. package/lib/utils/type/index.js +0 -146
  247. package/lib/utils/type/isArguments.js +0 -29
  248. package/lib/utils/type/isArray.js +0 -29
  249. package/lib/utils/type/isArrayBuffer.js +0 -32
  250. package/lib/utils/type/isBoolean.js +0 -29
  251. package/lib/utils/type/isDate.js +0 -29
  252. package/lib/utils/type/isError.js +0 -29
  253. package/lib/utils/type/isFunction.js +0 -29
  254. package/lib/utils/type/isMap.js +0 -29
  255. package/lib/utils/type/isRegExp.js +0 -29
  256. package/lib/utils/type/isSet.js +0 -29
  257. package/lib/utils/type/isWeakMap.js +0 -29
  258. package/lib/utils/type/isWeakSet.js +0 -29
  259. package/types/interface.type.d.ts +0 -2
@@ -1,6 +1,9 @@
1
- export default bytesToSize;
1
+ type BytesToSizeOptions = {
2
+ spaceMark?: string;
3
+ precision?: number;
4
+ };
2
5
  /**
3
- * 字节转换存储单位,保留2位小数点
6
+ * 字节转换存储单位
4
7
  *
5
8
  * @static
6
9
  * @alias module:Processor.bytesToSize
@@ -22,7 +25,5 @@ export default bytesToSize;
22
25
  * bytesToSize(1024, { spaceMark: '' }); // 1KB
23
26
  *
24
27
  */
25
- declare function bytesToSize(bytes: number, options?: {
26
- spaceMark?: string | undefined;
27
- precision?: number | undefined;
28
- } | undefined): string;
28
+ declare function bytesToSize(bytes: number, options?: BytesToSizeOptions): string;
29
+ export default bytesToSize;
@@ -1,24 +1,25 @@
1
- export default calculateCursorPosition;
1
+ type CalculateCursorPositionOptions = {
2
+ placeholderChar?: string;
3
+ maskReg?: RegExp;
4
+ type?: 'mobile' | 'bankCard';
5
+ };
2
6
  /**
3
7
  * 计算输入框的值格式化后光标位置
4
8
  *
5
9
  * @static
6
10
  * @alias module:Other.calculateCursorPosition
7
11
  * @since 4.6.0
8
- * @see {@link https://2950v9.csb.app/|h5示例}
9
- * @see {@link https://33ccy9.csb.app/|react示例}
12
+ * @see {@link https://2950v9.csb.app/ | h5示例}
13
+ * @see {@link https://33ccy9.csb.app/ | react示例}
10
14
  * @param {number} prevPos 赋值前的光标位置,onChange/onInput的光标位置 e.target.selectionEnd
11
15
  * @param {string} prevCtrlValue 上一个格式化后的值
12
16
  * @param {string} rawValue 当前输入原值
13
17
  * @param {string} ctrlValue 当前格式化后的值
14
18
  * @param {Object} [options] 配置项
15
- * @param {string[]|string} [options.placeholderChar=' '] 占位符
19
+ * @param {string|string[]} [options.placeholderChar=' '] 占位符
16
20
  * @param {RegExp} [options.maskReg=/\D/g] 需要遮盖的字符规则。默认去掉非数字,意味着 ctrlValue 需要去掉非数字。
17
21
  * @param {'mobile'|'bankCard'} [options.type] 格式化类型,内置手机号码和银行卡号特殊处理
18
22
  * @returns {number} 格式化后的光标位置
19
23
  */
20
- declare function calculateCursorPosition(prevPos: number, prevCtrlValue: string, rawValue: string, ctrlValue: string, options?: {
21
- placeholderChar?: string | string[] | undefined;
22
- maskReg?: RegExp | undefined;
23
- type?: "mobile" | "bankCard" | undefined;
24
- } | undefined): number;
24
+ declare function calculateCursorPosition(prevPos: number, prevCtrlValue: string, rawValue: string, ctrlValue: string, options?: CalculateCursorPositionOptions): number;
25
+ export default calculateCursorPosition;
@@ -1,15 +1,15 @@
1
- export default dataURLToBlob;
2
1
  /**
3
2
  * 将 DataURL 转为 Blob 对象
4
3
  *
5
4
  * @static
6
5
  * @alias module:Processor.dataURLToBlob
7
6
  * @since 4.1.0
8
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64|Base64}
9
- * @param {string} dataurl data: 协议的URL
7
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64 | Base64}
8
+ * @param {string} data data: 协议的URL
10
9
  * @returns {Blob} Blob 对象
11
10
  * @example
12
- * const dataurl = 'data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=';
11
+ * const data = 'data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=';
13
12
  * dataURLToBlob(dataurl); // Blob {size: 32, type: 'text/html'}
14
13
  */
15
- declare function dataURLToBlob(dataurl: string): Blob;
14
+ declare function dataURLToBlob(data: string): Blob;
15
+ export default dataURLToBlob;
package/types/divide.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export default divide;
2
1
  /**
3
2
  * 精确除法,支持多个数相除,除数默认为 1 。
4
3
  *
@@ -19,4 +18,5 @@ export default divide;
19
18
  * divide('1.5 ', 0.5); // 3 Number('1.5 ') 转换为 1.5 ,1.5/0.5 = 3
20
19
  *
21
20
  */
22
- declare function divide(...nums: (number | string)[]): number;
21
+ declare function divide(...nums: (string | number)[]): number;
22
+ export default divide;
@@ -1,38 +1,15 @@
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;
1
+ import ajax from './ajax';
2
+ type DataType = string | Blob | ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
3
+ type AjaxOptions = Parameters<typeof ajax>[1];
4
+ type TransformRequest = (options: AjaxOptions) => AjaxOptions | Promise<AjaxOptions>;
5
+ type TransformResponse = (res: Blob) => Blob | Promise<Blob>;
6
+ type DownloadOptions = {
7
+ fileName?: string;
8
+ type?: string;
9
+ dataType?: 'url' | 'text';
10
+ transformRequest?: TransformRequest;
11
+ transformResponse?: TransformResponse;
32
12
  };
33
- /**
34
- * @typedef {import('./ajax.js').AjaxOptions} AjaxOptions ajax 配置项
35
- */
36
13
  /**
37
14
  * @callback TransformRequest
38
15
  * @param {AjaxOptions} options ajax 配置项
@@ -59,9 +36,9 @@ export type DownloadOptions = {
59
36
  * @static
60
37
  * @alias module:Other.download
61
38
  * @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地址
39
+ * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展 | MIME}
40
+ * @see {@link https://9ykc9s.csb.app/ | 在线示例}
41
+ * @param {string|Blob|ArrayBuffer|TypedArray} data 字符串、blob数据或url地址
65
42
  * @param {string|DownloadOptions} [options] 文件名称 或 配置项
66
43
  * @returns {Promise<void>}
67
44
  * @example
@@ -71,8 +48,15 @@ export type DownloadOptions = {
71
48
  * // 远程文件
72
49
  * download('/xxx.jpg', { dataType: 'url' });
73
50
  *
51
+ * // base64
52
+ * download('data:image/png;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=', 'test.png');
53
+ *
74
54
  * // blob文件
75
55
  * download(new Blob(['hello world']), 'text.txt');
76
56
  *
57
+ * // 本地文件
58
+ * download(File, 'filename.ext');
59
+ *
77
60
  */
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>;
61
+ declare function download(data: DataType, options?: string | DownloadOptions): Promise<void>;
62
+ export default download;
@@ -1,3 +1,36 @@
1
- export default fileReader;
1
+ declare const FileReaderMethodMap: {
2
+ readonly arrayBuffer: "readAsArrayBuffer";
3
+ readonly binaryString: "readAsBinaryString";
4
+ readonly dataURL: "readAsDataURL";
5
+ readonly text: "readAsText";
6
+ };
7
+ type ReadType = keyof typeof FileReaderMethodMap;
8
+ /**
9
+ * 读取 Blob 或 File 对象,转为 Base64/String/ArrayBuffer<br/><br/>
10
+ *
11
+ * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
12
+ *
13
+ * @static
14
+ * @alias module:Processor.fileReader
15
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader | FileReader}
16
+ * @since 4.16.0
17
+ * @param {Blob} blob Blob 或 File 对象
18
+ * @param {'arrayBuffer'|'binaryString'|'dataURL'|'text'} [type='dataURL'] 读取类型
19
+ * @returns {Promise<string|ArrayBuffer>} 文件内容
20
+ * @example
21
+ * const aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // 一个包含DOMString的数组
22
+ * const htmlBlob = new Blob(aFileParts, { type: 'text/html' }); // 得到 blob
23
+ *
24
+ * fileReader(htmlBlob).then(data=>{
25
+ * console.log(data); // data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
26
+ * });
27
+ *
28
+ * const textBlob = new Blob(aFileParts, { type: 'text/plain' });
29
+ *
30
+ * fileReader(textBlob, 'text').then(data=>{
31
+ * console.log(data); // <a id="a"><b id="b">hey!</b></a>
32
+ * });
33
+ */
2
34
  declare function fileReader(blob: Blob, type: 'arrayBuffer'): Promise<ArrayBuffer>;
3
- declare function fileReader(blob: Blob, type?: "text" | "binaryString" | "dataURL" | undefined): Promise<string>;
35
+ declare function fileReader(blob: Blob, type?: Exclude<ReadType, 'arrayBuffer'>): Promise<string>;
36
+ export default fileReader;
@@ -1,17 +1,15 @@
1
- export default filterTree;
1
+ type NodeAssign = 'spread' | 'self';
2
2
  /**
3
3
  * 过滤/筛选树节点。<br/><br/>如果某节点被过滤掉,它的子节点也一并抛弃
4
4
  *
5
5
  * @static
6
6
  * @alias module:Tree.filterTree
7
7
  * @since 4.15.0
8
- * @template {any} T
9
- * @template {(item: T) => boolean} F
10
- * @param {T[]} tree 树结构数据
11
- * @param {F} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy ,结果将包含该节点
8
+ * @param {object[]} tree 树结构数据
9
+ * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy ,结果将包含该节点
12
10
  * @param {string} [childrenField='children'] 子级字段名
13
11
  * @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
14
- * @returns {T[]}
12
+ * @returns {object[]}
15
13
  * @example
16
14
  * const menus = [{ "id": "1", "name": "首页", "code": "trade", "pid": null }, { "id": "2", "name": "交易管理", "code": "trade", "pid": null, "children": [{ "id": "3", "name": "交易查询", "code": "trade-1", "pid": "2", "children": [{ "id": "4", "name": "交易查询-查询操作", "code": "trade-1-1", "pid": "3" }] }] }, { "id": "5", "name": "权限管理", "code": "authorization", "pid": null, "children": [{ "id": "6", "name": "角色管理", "code": "authorization-1", "pid": "5" }, { "id": "7", "name": "用户管理", "code": "authorization-2", "pid": "5" }] }];
17
15
  *
@@ -25,4 +23,5 @@ export default filterTree;
25
23
  * filterTree(menus, item=>item.id === 'not found');
26
24
  * // []
27
25
  */
28
- declare function filterTree<T extends unknown, F extends (item: T) => boolean>(tree: T[], predicate: F, childrenField?: string | undefined, nodeAssign?: "spread" | "self" | undefined): T[];
26
+ declare function filterTree<T extends any, F extends (item: T) => boolean>(tree: T[], predicate: F, childrenField?: string, nodeAssign?: NodeAssign): T[];
27
+ export default filterTree;
@@ -1,16 +1,13 @@
1
- export default findTreeNode;
2
1
  /**
3
2
  * 查找树结构数据节点
4
3
  *
5
4
  * @static
6
5
  * @alias module:Tree.findTreeNode
7
6
  * @since 4.14.0
8
- * @template {any} T
9
- * @template {(item: T) => boolean} F
10
- * @param {T[]} tree 树结构数据
11
- * @param {F} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy ,将返回该节点
7
+ * @param {object[]} tree 树结构数据
8
+ * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy ,将返回该节点
12
9
  * @param {string} [childrenField='children'] 子级字段名
13
- * @returns {T|undefined}
10
+ * @returns {object|undefined}
14
11
  * @example
15
12
  * const menus = [{ "id": "1", "name": "首页", "code": "trade", "pid": null }, { "id": "2", "name": "交易管理", "code": "trade", "pid": null, "children": [{ "id": "3", "name": "交易查询", "code": "trade-1", "pid": "2", "children": [{ "id": "4", "name": "交易查询-查询操作", "code": "trade-1-1", "pid": "3" }] }] }, { "id": "5", "name": "权限管理", "code": "authorization", "pid": null, "children": [{ "id": "6", "name": "角色管理", "code": "authorization-1", "pid": "5" }, { "id": "7", "name": "用户管理", "code": "authorization-2", "pid": "5" }] }];
16
13
  *
@@ -23,4 +20,5 @@ export default findTreeNode;
23
20
  * findTreeNode(menus, item=>item.id === 'not found');
24
21
  * // undefined
25
22
  */
26
- declare function findTreeNode<T extends unknown, F extends (item: T) => boolean>(tree: T[], predicate: F, childrenField?: string | undefined): T | undefined;
23
+ declare function findTreeNode<T extends any, F extends (item: T) => boolean>(tree: T[], predicate: F, childrenField?: string): T | undefined;
24
+ export default findTreeNode;
@@ -1,16 +1,13 @@
1
- export default findTreeNodes;
2
1
  /**
3
2
  * 查找树结构数据多个节点
4
3
  *
5
4
  * @static
6
5
  * @alias module:Tree.findTreeNodes
7
6
  * @since 4.15.0
8
- * @template {any} T
9
- * @template {(item: T) => boolean} F
10
- * @param {T[]} tree 树结构数据
11
- * @param {F} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy ,返回结果将包含该节点
7
+ * @param {object[]} tree 树结构数据
8
+ * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy ,返回结果将包含该节点
12
9
  * @param {string} [childrenField='children'] 子级字段名
13
- * @returns {T[]}
10
+ * @returns {object[]}
14
11
  * @example
15
12
  * const menus = [{ "id": "1", "name": "首页", "code": "trade", "pid": null }, { "id": "2", "name": "交易管理", "code": "trade", "pid": null, "children": [{ "id": "3", "name": "交易查询", "code": "trade-1", "pid": "2", "children": [{ "id": "4", "name": "交易查询-查询操作", "code": "trade-1-1", "pid": "3" }] }] }, { "id": "5", "name": "权限管理", "code": "authorization", "pid": null, "children": [{ "id": "6", "name": "角色管理", "code": "authorization-1", "pid": "5" }, { "id": "7", "name": "用户管理", "code": "authorization-2", "pid": "5" }] }];
16
13
  *
@@ -26,4 +23,5 @@ export default findTreeNodes;
26
23
  * findTreeNodes(menus, item=>item.id === 'not found');
27
24
  * // []
28
25
  */
29
- declare function findTreeNodes<T extends unknown, F extends (item: T) => boolean>(tree: T[], predicate: F, childrenField?: string | undefined): T[];
26
+ declare function findTreeNodes<T extends any, F extends (item: T) => boolean>(tree: T[], predicate: F, childrenField?: string): T[];
27
+ export default findTreeNodes;
@@ -1,16 +1,13 @@
1
- export default findTreeSelect;
2
1
  /**
3
2
  * 查找包含当前节点的所有父级节点
4
3
  *
5
4
  * @static
6
5
  * @alias module:Tree.findTreeSelect
7
6
  * @since 4.14.0
8
- * @template {any} T
9
- * @template {(item: T) => boolean} F
10
- * @param {T[]} tree 树结构数据
11
- * @param {F} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy 将返回包含该节点的所有父级节点
7
+ * @param {object[]} tree 树结构数据
8
+ * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy 将返回包含该节点的所有父级节点
12
9
  * @param {string} [childrenField='children'] 子级字段名
13
- * @returns {T[]}
10
+ * @returns {object[]}
14
11
  * @example
15
12
  * const menus = [{ "id": "1", "name": "首页", "code": "trade", "pid": null }, { "id": "2", "name": "交易管理", "code": "trade", "pid": null, "children": [{ "id": "3", "name": "交易查询", "code": "trade-1", "pid": "2", "children": [{ "id": "4", "name": "交易查询-查询操作", "code": "trade-1-1", "pid": "3" }] }] }, { "id": "5", "name": "权限管理", "code": "authorization", "pid": null, "children": [{ "id": "6", "name": "角色管理", "code": "authorization-1", "pid": "5" }, { "id": "7", "name": "用户管理", "code": "authorization-2", "pid": "5" }] }];
16
13
  *
@@ -23,4 +20,5 @@ export default findTreeSelect;
23
20
  * findTreeSelect(menus, item => item.id === 'not found');
24
21
  * // []
25
22
  */
26
- declare function findTreeSelect<T extends unknown, F extends (item: T) => boolean>(tree: T[], predicate: F, childrenField?: string | undefined): T[];
23
+ declare function findTreeSelect<T extends any, F extends (item: T) => boolean>(tree: T[], predicate: F, childrenField?: string): T[];
24
+ export default findTreeSelect;
@@ -1,4 +1,9 @@
1
- export default formatBankCard;
1
+ type Options = {
2
+ /** @deprecated */
3
+ char?: string;
4
+ spaceMark?: string;
5
+ length?: number;
6
+ };
2
7
  /**
3
8
  * 格式化银行卡号
4
9
  *
@@ -25,7 +30,5 @@ export default formatBankCard;
25
30
  * formatBankCard('6228480402564890', {spaceMark: '-'}); // 6228-4804-0256-4890
26
31
  *
27
32
  */
28
- declare function formatBankCard(bankCardNo?: string, options?: {
29
- spaceMark?: string | undefined;
30
- length?: number | undefined;
31
- } | undefined): string;
33
+ declare function formatBankCard(bankCardNo?: string, options?: Options): string;
34
+ export default formatBankCard;
@@ -1,4 +1,8 @@
1
- export default formatMobile;
1
+ type Options = {
2
+ /** @deprecated */
3
+ char?: string;
4
+ spaceMark?: string;
5
+ };
2
6
  /**
3
7
  * 格式化手机号码
4
8
  *
@@ -24,6 +28,5 @@ export default formatMobile;
24
28
  * formatMobile('13345678'); // 133 4567 8
25
29
  *
26
30
  */
27
- declare function formatMobile(mobileNo: string, options?: {
28
- spaceMark?: string | undefined;
29
- } | undefined): string;
31
+ declare function formatMobile(mobileNo?: string, options?: Options): string;
32
+ export default formatMobile;
@@ -1,4 +1,9 @@
1
- export default formatMoney;
1
+ type Options = {
2
+ precision?: number;
3
+ symbol?: string;
4
+ thousand?: string;
5
+ decimal?: string;
6
+ };
2
7
  /**
3
8
  * 格式化金额
4
9
  *
@@ -38,9 +43,5 @@ export default formatMoney;
38
43
  * // 字符串数字
39
44
  * formatMoney('3000.03', { precision: 4 }); // 3,000.0300
40
45
  */
41
- declare function formatMoney(num: string | number, options?: {
42
- precision?: number | undefined;
43
- symbol?: string | undefined;
44
- thousand?: string | undefined;
45
- decimal?: string | undefined;
46
- } | undefined): string;
46
+ declare const formatMoney: (num: string | number, options?: Options) => string;
47
+ export default formatMoney;
package/types/index.d.ts CHANGED
@@ -1,55 +1,125 @@
1
- export { default as isMobile } from "./isMobile";
2
- export { default as isTelephone } from "./isTelephone";
3
- export { default as isPostcode } from "./isPostcode";
4
- export { default as isIdCard } from "./isIdCard";
5
- export { default as isEmail } from "./isEmail";
6
- export { default as isQQ } from "./isQQ";
7
- export { default as isWX } from "./isWX";
8
- export { default as isVehicle } from "./isVehicle";
9
- export { default as isBankCard } from "./isBankCard";
10
- export { default as isSocialCreditCode } from "./isSocialCreditCode";
11
- export { default as isPassword } from "./isPassword";
12
- export { default as isPassport } from "./isPassport";
13
- export { default as isChinese } from "./isChinese";
14
- export { default as isIPv4 } from "./isIPv4";
15
- export { default as isIPv6 } from "./isIPv6";
16
- export { default as isUrl } from "./isUrl";
17
- export { default as isBusinessLicense } from "./isBusinessLicense";
18
- export { default as validatePassword } from "./validatePassword";
19
- export { default as isPromiseLike } from "./isPromiseLike";
20
- export { default as isHMCard } from "./isHMCard";
21
- export { default as isTWCard } from "./isTWCard";
22
- export { default as isSwiftCode } from "./isSwiftCode";
23
- export { default as formatMoney } from "./formatMoney";
24
- export { default as formatBankCard } from "./formatBankCard";
25
- export { default as replaceChar } from "./replaceChar";
26
- export { default as numberToChinese } from "./numberToChinese";
27
- export { default as bytesToSize } from "./bytesToSize";
28
- export { default as parseIdCard } from "./parseIdCard";
29
- export { default as blobToDataURL } from "./blobToDataURL";
30
- export { default as fileReader } from "./fileReader";
31
- export { default as dataURLToBlob } from "./dataURLToBlob";
32
- export { default as setDataURLPrefix } from "./setDataURLPrefix";
33
- export { default as normalizeString } from "./normalizeString";
34
- export { default as safeDate } from "./safeDate";
35
- export { default as formatMobile } from "./formatMobile";
36
- export { default as padZero } from "./padZero";
37
- export { default as plus } from "./plus";
38
- export { default as minus } from "./minus";
39
- export { default as times } from "./times";
40
- export { default as divide } from "./divide";
41
- export { default as round } from "./round";
42
- export { default as ajax } from "./ajax";
43
- export { default as calculateCursorPosition } from "./calculateCursorPosition";
44
- export { default as download } from "./download";
45
- export { default as randomString } from "./randomString";
46
- export { default as strlen } from "./strlen";
47
- export { default as waitTime } from "./waitTime";
48
- export { default as transformFieldNames } from "./transformFieldNames";
49
- export { default as listToTree } from "./listToTree";
50
- export { default as treeToList } from "./treeToList";
51
- export { default as filterTree } from "./filterTree";
52
- export { default as findTreeNode } from "./findTreeNode";
53
- export { default as findTreeNodes } from "./findTreeNodes";
54
- export { default as findTreeSelect } from "./findTreeSelect";
55
- export { setDisableWarning, version } from "./utils/config";
1
+ /**
2
+ * 数据验证
3
+ *
4
+ * @module Validator
5
+ * @since 1.1.0
6
+ */
7
+ export { default as isMobile } from './isMobile';
8
+ export { default as isTelephone } from './isTelephone';
9
+ export { default as isPostcode } from './isPostcode';
10
+ export { default as isIdCard } from './isIdCard';
11
+ export { default as isEmail } from './isEmail';
12
+ export { default as isQQ } from './isQQ';
13
+ export { default as isWX } from './isWX';
14
+ export { default as isVehicle } from './isVehicle';
15
+ export { default as isBankCard } from './isBankCard';
16
+ export { default as isSocialCreditCode } from './isSocialCreditCode';
17
+ export { default as isPassword } from './isPassword';
18
+ export { default as isPassport } from './isPassport';
19
+ export { default as isChinese } from './isChinese';
20
+ export { default as isIPv4 } from './isIPv4';
21
+ export { default as isIPv6 } from './isIPv6';
22
+ export { default as isUrl } from './isUrl';
23
+ export { default as isBusinessLicense } from './isBusinessLicense';
24
+ export { default as validatePassword } from './validatePassword';
25
+ export { default as isPromiseLike } from './isPromiseLike';
26
+ export { default as isHMCard } from './isHMCard';
27
+ export { default as isTWCard } from './isTWCard';
28
+ export { default as isSwiftCode } from './isSwiftCode';
29
+ /**
30
+ * 数据处理
31
+ *
32
+ * @module Processor
33
+ * @since 1.1.0
34
+ */
35
+ export { default as formatMoney } from './formatMoney';
36
+ export { default as formatBankCard } from './formatBankCard';
37
+ export { default as replaceChar } from './replaceChar';
38
+ export { default as numberToChinese } from './numberToChinese';
39
+ export { default as bytesToSize } from './bytesToSize';
40
+ export { default as parseIdCard } from './parseIdCard';
41
+ export { default as blobToDataURL } from './blobToDataURL';
42
+ export { default as fileReader } from './fileReader';
43
+ export { default as dataURLToBlob } from './dataURLToBlob';
44
+ export { default as setDataURLPrefix } from './setDataURLPrefix';
45
+ export { default as normalizeString } from './normalizeString';
46
+ export { default as safeDate } from './safeDate';
47
+ export { default as formatMobile } from './formatMobile';
48
+ export { default as padZero } from './padZero';
49
+ /**
50
+ * 数学计算,修正浮点数计算问题
51
+ *
52
+ * @module Math
53
+ * @since 3.1.0
54
+ * @see {@link https://github.com/camsong/blog/issues/9 | JavaScript 浮点数陷阱及解法}
55
+ * @see {@link https://2zbuy.csb.app/ | JS浮点数计算测试}
56
+ * @example
57
+ * // 从 4.12.0 版本开始,规范了有效数值。(注意:4.12.3 对有效数值重新定义)
58
+ * // 有效数值即能通过 Number(value) 转为数字,且不能为 NaN 。
59
+ *
60
+ * // 以下为有效数值:
61
+ * // 1. 数字: 1, -1, 1e-2, 1.312, 0.1, Infinity
62
+ * // 2. 字符串: '1', '10e2', '-1', '0.1', '', ' ', ' 15', ' 15 '
63
+ * // 4. 其他类型: null, new Date(), [], new Array(), true, false,...
64
+ *
65
+ * // 以下为无效数值:
66
+ * // 1. 字符串: '1a', '-12a', '10.2.2', '10e2.1'
67
+ * // 2. 其他类型: undefined, [], {}, Symbol(), function(){}, ()=>{}
68
+ *
69
+ * // 计算说明:
70
+ * // 四则运算的第二个参数都是有默认值(乘数和除数默认1,加数和减数默认0)
71
+ * plus(); // NaN 0个参数时,被加数转换为 Number(undefined) NaN ,NaN+0 = NaN 。其他计算方法如果没有参数一样返回 NaN 。
72
+ * plus(0.1); // 0.1 第二个参数,加数默认为 0
73
+ * plus(undefined, 0.1); // NaN 第一个参数被加数转换为 Number(undefined) NaN ,NaN+0 = NaN 。其他计算方法如果第一个参数为无效数值一样返回 NaN 。
74
+ * plus(true, null); // 1 Number(true) 转换为 1 , Number(null) 转换为 0 , 1+0=1
75
+ *
76
+ * // 2. 参数中包含无效数值,返回NaN
77
+ * plus('0.1', ' a'); // NaN
78
+ * plus(true, {}); // NaN
79
+ * plus(true, 0.1, Symbol()); // NaN
80
+ *
81
+ * // 注意:
82
+ * // 如果第二个及后面的参数如果值为 undefined 取默认值,即乘除数取 1 ,加减法取 0 。
83
+ * plus(0.1, undefined); // 0.1
84
+ * plus(0.1, undefined, 0.2, undefined); // 0.3 后面的 undefined 取默认值 0
85
+ * times(0.1, undefined, 0.2, undefined); // 0.02 后面的 undefined 取默认值 1
86
+ *
87
+ */
88
+ export { default as plus } from './plus';
89
+ export { default as minus } from './minus';
90
+ export { default as times } from './times';
91
+ export { default as divide } from './divide';
92
+ export { default as round } from './round';
93
+ /**
94
+ * 其他
95
+ *
96
+ * @module Other
97
+ * @since 4.2.0
98
+ */
99
+ export { default as ajax } from './ajax';
100
+ export { default as calculateCursorPosition } from './calculateCursorPosition';
101
+ export { default as download } from './download';
102
+ export { default as randomString } from './randomString';
103
+ export { default as strlen } from './strlen';
104
+ export { default as waitTime } from './waitTime';
105
+ /**
106
+ * 树结构数据查询、过滤、转换等处理方法
107
+ *
108
+ * @module Tree
109
+ * @since 4.14.0
110
+ */
111
+ export { default as transformFieldNames } from './transformFieldNames';
112
+ export { default as listToTree } from './listToTree';
113
+ export { default as treeToList } from './treeToList';
114
+ export { default as filterTree } from './filterTree';
115
+ export { default as findTreeNode } from './findTreeNode';
116
+ export { default as findTreeNodes } from './findTreeNodes';
117
+ export { default as findTreeSelect } from './findTreeSelect';
118
+ /**
119
+ * 调试相关
120
+ *
121
+ * @module Debug
122
+ * @ignore
123
+ * @since 3.6.1
124
+ */
125
+ export { setDisableWarning, version } from './utils/config';
@@ -1,14 +1,17 @@
1
- export default isBankCard;
1
+ type Options = {
2
+ loose?: boolean;
3
+ luhn?: boolean;
4
+ };
2
5
  /**
3
- * 检测值是否为银行卡号。正常模式(非0开头,10~21位数字)宽松模式(8~30位数字)
6
+ * 检测值是否为银行卡号。正常模式(非0开头,10-21位数字)宽松模式(8-30位数字)
4
7
  *
5
8
  * @static
6
9
  * @alias module:Validator.isBankCard
7
10
  * @since 1.1.0
8
- * @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html|常用银行账号位数参考}
11
+ * @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html | 常用银行账号位数参考}
9
12
  * @param {*} value 要检测的值
10
13
  * @param {Object} [options] 配置项
11
- * @param {boolean} [options.loose=false] 宽松模式,8~30位数字
14
+ * @param {boolean} [options.loose=false] 宽松模式,8-30位数字
12
15
  * @param {boolean} [options.luhn=false] 使用 Luhn 算法校验校验码
13
16
  * @returns {boolean} 值是否为银行卡号
14
17
  * @example
@@ -21,7 +24,5 @@ export default isBankCard;
21
24
  * isBankCard('123456789', { loose: true }); // true
22
25
  *
23
26
  */
24
- declare function isBankCard(value: any, options?: {
25
- loose?: boolean | undefined;
26
- luhn?: boolean | undefined;
27
- } | undefined): boolean;
27
+ declare function isBankCard(value: any, options?: Options): boolean;
28
+ export default isBankCard;
@@ -1,11 +1,15 @@
1
- export default isBusinessLicense;
1
+ type Options = {
2
+ /** @deprecated */
3
+ loose?: boolean;
4
+ checkCode?: boolean;
5
+ };
2
6
  /**
3
7
  * 检测值是否为营业执照号,也叫工商注册号。由14位数字本体码和1位数字校验码组成,其中本体码从左至右依次为:6位首次登记机关码、8位顺序码。
4
8
  *
5
9
  * @static
6
10
  * @alias module:Validator.isBusinessLicense
7
11
  * @since 3.5.0
8
- * @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html|GS15—2006 工商行政管理市场主体注册号编制规则}
12
+ * @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html | GS15—2006 工商行政管理市场主体注册号编制规则}
9
13
  * @param {*} value 要检测的值
10
14
  * @param {Object} [options] 配置项
11
15
  * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
@@ -21,6 +25,5 @@ export default isBusinessLicense;
21
25
  * isBusinessLicense('31011560098', { checkCode: false }); // false
22
26
  *
23
27
  */
24
- declare function isBusinessLicense(value: any, options?: {
25
- checkCode?: boolean | undefined;
26
- } | undefined): boolean;
28
+ declare function isBusinessLicense(value: any, options?: Options): boolean;
29
+ export default isBusinessLicense;