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,262 +1,111 @@
1
- import devWarn from './utils/devWarn';
1
+ import devWarn from './utils/devWarn.js';
2
+
2
3
  var regNumber = /[\d]/;
3
4
  var regLowerCaseLetter = /[a-z]/;
4
5
  var regUpperCaseLetter = /[A-Z]/;
5
6
  var regAllNumberAndLetter = /[\d|a-z]/gi;
6
-
7
- /**
8
- * 是否包含数字
9
- *
10
- * @private
11
- * @param {string} val 检查的值
12
- * @returns {boolean} 是否包含数字
13
- */
14
7
  function hasNumber(val) {
15
- return regNumber.test(val);
8
+ return regNumber.test(val);
16
9
  }
17
-
18
- /**
19
- * 是否包含小写字母
20
- *
21
- * @private
22
- * @param {string} val 检测的值
23
- * @returns {boolean} 是否包含小写字母
24
- */
25
10
  function hasLowerCaseLetter(val) {
26
- return regLowerCaseLetter.test(val);
11
+ return regLowerCaseLetter.test(val);
27
12
  }
28
-
29
- /**
30
- * 是否包含大写字母
31
- *
32
- * @private
33
- * @param {string} val 检测的值
34
- * @returns {boolean} 是否包含大写字母
35
- */
36
13
  function hasUpperCaseLetter(val) {
37
- return regUpperCaseLetter.test(val);
14
+ return regUpperCaseLetter.test(val);
38
15
  }
39
-
40
- /**
41
- * 是否为十六进制
42
- *
43
- * @private
44
- * @param {string} val 检测的值
45
- * @returns {boolean} 是否为十六进制
46
- */
47
16
  function hasHex(val) {
48
- return val.indexOf('\\x') > -1 || val.indexOf("\\u") > -1;
17
+ return val.indexOf('\\x') > -1 || val.indexOf('\\u') > -1;
49
18
  }
50
-
51
- /**
52
- * 是否包含特殊字符
53
- *
54
- * @private
55
- * @param {string} val 检测的值
56
- * @param {string} chars 特殊字符
57
- * @returns {boolean} 是否包含特殊字符
58
- */
59
19
  function hasSpecialCharacter(val, chars) {
60
- if (!chars || !val) {
61
- return false;
62
- }
63
- var specialChars = val.replace(regAllNumberAndLetter, '');
64
- if (!specialChars) {
65
- return false;
66
- }
67
- var regChars = hasHex(chars) ? new RegExp("[".concat(chars, "]")) : null;
68
- if (regChars) {
69
- return regChars.test(specialChars);
70
- }
71
- var ret = false;
72
- specialChars.split('').some(function (charItem) {
73
- if (chars.indexOf(charItem) > -1) {
74
- ret = true;
20
+ if (!chars || !val) {
21
+ return false;
22
+ }
23
+ var specialChars = val.replace(regAllNumberAndLetter, '');
24
+ if (!specialChars) {
25
+ return false;
26
+ }
27
+ var regChars = hasHex(chars) ? new RegExp("[".concat(chars, "]")) : null;
28
+ if (regChars) {
29
+ return regChars.test(specialChars);
75
30
  }
31
+ var ret = false;
32
+ specialChars.split('').some(function (charItem) {
33
+ if (chars.indexOf(charItem) > -1) {
34
+ ret = true;
35
+ }
36
+ return ret;
37
+ });
76
38
  return ret;
77
- });
78
- return ret;
79
39
  }
80
-
81
- /**
82
- * 是否包含非法字符
83
- *
84
- * @private
85
- * @param {string} val 检测的值
86
- * @param {string} chars 特殊字符
87
- * @returns {boolean} 是否包含非法字符
88
- */
89
40
  function hasUnallowableCharacter(val, chars) {
90
- if (!val) {
91
- return false;
92
- }
93
- var specialChars = val.replace(regAllNumberAndLetter, '');
94
- if (!specialChars) {
95
- return false;
96
- } else if (!chars) {
97
- return true;
98
- }
99
- var regChars = hasHex(chars) ? new RegExp("[^".concat(chars, "]")) : null;
100
- if (regChars) {
101
- return regChars.test(specialChars);
102
- }
103
- var ret = false;
104
- specialChars.split('').some(function (charItem) {
105
- if (chars.indexOf(charItem) === -1) {
106
- ret = true;
41
+ if (!val) {
42
+ return false;
43
+ }
44
+ var specialChars = val.replace(regAllNumberAndLetter, '');
45
+ if (!specialChars) {
46
+ return false;
107
47
  }
48
+ else if (!chars) {
49
+ return true;
50
+ }
51
+ var regChars = hasHex(chars) ? new RegExp("[^".concat(chars, "]")) : null;
52
+ if (regChars) {
53
+ return regChars.test(specialChars);
54
+ }
55
+ var ret = false;
56
+ specialChars.split('').some(function (charItem) {
57
+ if (chars.indexOf(charItem) === -1) {
58
+ ret = true;
59
+ }
60
+ return ret;
61
+ });
108
62
  return ret;
109
- });
110
- return ret;
111
63
  }
112
-
113
- /**
114
- * @typedef {Object} PasswordContaines - 验证密码的包含内容
115
- * @property {boolean} number - 包含数字
116
- * @property {boolean} lowerCaseLetter - 包含小写字母
117
- * @property {boolean} upperCaseLetter - 包含大写字母
118
- * @property {boolean} specialCharacter - 包含特殊字符
119
- * @property {boolean} unallowableCharacter - 包含非法字符
120
- */
121
-
122
- /**
123
- * @typedef {Object} ValidatePasswordReturn - 验证结果
124
- * @property {boolean} validated - 验证结果,根据密码强度、是否包含非法字符得出
125
- * @property {number} level - 强度级别,包含数字/大小写字母/特殊字符
126
- * @property {PasswordContaines} containes - 包含内容
127
- */
128
-
129
- /**
130
- * 验证密码(数字、大小写字母、特殊字符、非法字符)
131
- *
132
- * @static
133
- * @alias module:Validator.validatePassword
134
- * @since 3.7.0
135
- * @see {@link https://baike.baidu.com/item/ASCII#3|ASCII}
136
- * @param {string} value 要检测的值
137
- * @param {Object} [options] 配置项
138
- * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
139
- * @param {boolean} [options.ignoreCase=false] 是否忽略大小写,为 ture 时,大小写字母视为一种字符
140
- * @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符
141
- * @returns {ValidatePasswordReturn} 验证结果
142
- * @example
143
- *
144
- * validatePassword('a12345678');
145
- * // =>
146
- * {
147
- * validated: true, // 验证结果,根据密码强度、是否包含非法字符得出
148
- * level: 2, // 强度级别
149
- * containes: {
150
- * number: true, // 包含数字
151
- * lowerCaseLetter: true, // 包含小写字母
152
- * upperCaseLetter: false, // 包含大写字母
153
- * specialCharacter: false, // 包含特殊字符
154
- * unallowableCharacter: false // 包含非法字符
155
- * }
156
- * }
157
- *
158
- * validatePassword('a12345678', { level: 3 });
159
- * // =>
160
- * {
161
- * validated: false,
162
- * level: 2,
163
- * containes: {
164
- * number: true,
165
- * lowerCaseLetter: true,
166
- * upperCaseLetter: false,
167
- * specialCharacter: false,
168
- * unallowableCharacter: false
169
- * }
170
- * }
171
- *
172
- * validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true });
173
- * // =>
174
- * {
175
- * validated: false,
176
- * level: 3,
177
- * containes: {
178
- * number: true,
179
- * lowerCaseLetter: true,
180
- * upperCaseLetter: true,
181
- * specialCharacter: true,
182
- * unallowableCharacter: true
183
- * }
184
- * }
185
- *
186
- * // 自定义特殊字符
187
- * validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true, special: '_一二三' });
188
- * // =>
189
- * {
190
- * validated: true,
191
- * level: 3,
192
- * containes: {
193
- * number: true,
194
- * lowerCaseLetter: true,
195
- * upperCaseLetter: true,
196
- * specialCharacter: true,
197
- * unallowableCharacter: false
198
- * }
199
- * }
200
- */
201
- function validatePassword(value) {
202
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
203
- var _options$level = options.level,
204
- level = _options$level === void 0 ? 2 : _options$level,
205
- _options$ignoreCase = options.ignoreCase,
206
- ignoreCase = _options$ignoreCase === void 0 ? false : _options$ignoreCase,
207
- _options$special = options.special,
208
- special = _options$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _options$special;
209
- var valStr = value;
210
- if (typeof value !== 'string') {
211
- devWarn("[validatePassword] value must be a string.");
212
- valStr = '';
213
- }
214
- var currentLevel = 0;
215
-
216
- // 包含数字
217
- var containesNumber = hasNumber(valStr);
218
- // 包含小写字母
219
- var containesLowerCaseLetter = hasLowerCaseLetter(valStr);
220
- // 包含大写字母
221
- var containesUpperCaseLetter = hasUpperCaseLetter(valStr);
222
- // 包含特殊字符
223
- var containesSpecialCharacter = hasSpecialCharacter(valStr, special);
224
- // 包含非法字符,即含有非数字字母特殊字符以外的其他字符
225
- var containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
226
- if (containesNumber) {
227
- currentLevel += 1;
228
- }
229
-
230
- // 不区分大小写
231
- if (ignoreCase) {
232
- if (containesLowerCaseLetter || containesUpperCaseLetter) {
233
- currentLevel += 1;
64
+ function validatePassword(value, options) {
65
+ if (options === void 0) { options = {}; }
66
+ var _a = options.level, level = _a === void 0 ? 2 : _a, _b = options.ignoreCase, ignoreCase = _b === void 0 ? false : _b, _c = options.special, special = _c === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _c;
67
+ var valStr = value;
68
+ if (typeof value !== 'string') {
69
+ devWarn("[validatePassword] value must be a string.");
70
+ valStr = '';
234
71
  }
235
- } else {
236
- // 区分大小写
237
- if (containesLowerCaseLetter) {
238
- currentLevel += 1;
72
+ var currentLevel = 0;
73
+ var containesNumber = hasNumber(valStr);
74
+ var containesLowerCaseLetter = hasLowerCaseLetter(valStr);
75
+ var containesUpperCaseLetter = hasUpperCaseLetter(valStr);
76
+ var containesSpecialCharacter = hasSpecialCharacter(valStr, special);
77
+ var containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
78
+ if (containesNumber) {
79
+ currentLevel += 1;
239
80
  }
240
- if (containesUpperCaseLetter) {
241
- currentLevel += 1;
81
+ if (ignoreCase) {
82
+ if (containesLowerCaseLetter || containesUpperCaseLetter) {
83
+ currentLevel += 1;
84
+ }
242
85
  }
243
- }
244
- if (containesSpecialCharacter) {
245
- currentLevel += 1;
246
- }
247
-
248
- // 验证结果
249
- var validated = currentLevel >= level && !containesUnallowableCharacter;
250
- return {
251
- validated: validated,
252
- level: currentLevel,
253
- containes: {
254
- number: containesNumber,
255
- lowerCaseLetter: containesLowerCaseLetter,
256
- upperCaseLetter: containesUpperCaseLetter,
257
- specialCharacter: containesSpecialCharacter,
258
- unallowableCharacter: containesUnallowableCharacter
86
+ else {
87
+ if (containesLowerCaseLetter) {
88
+ currentLevel += 1;
89
+ }
90
+ if (containesUpperCaseLetter) {
91
+ currentLevel += 1;
92
+ }
259
93
  }
260
- };
94
+ if (containesSpecialCharacter) {
95
+ currentLevel += 1;
96
+ }
97
+ var validated = currentLevel >= level && !containesUnallowableCharacter;
98
+ return {
99
+ validated: validated,
100
+ level: currentLevel,
101
+ containes: {
102
+ number: containesNumber,
103
+ lowerCaseLetter: containesLowerCaseLetter,
104
+ upperCaseLetter: containesUpperCaseLetter,
105
+ specialCharacter: containesSpecialCharacter,
106
+ unallowableCharacter: containesUnallowableCharacter
107
+ }
108
+ };
261
109
  }
262
- export default validatePassword;
110
+
111
+ export { validatePassword as default };
package/esm/waitTime.js CHANGED
@@ -1,27 +1,8 @@
1
- /**
2
- * 等待时间返回 Promise 。常用于异步方法中延时。
3
- *
4
- * @static
5
- * @alias module:Other.waitTime
6
- * @since 4.2.0
7
- * @param {number} [time=1000] 延时时间,单位毫秒
8
- * @returns {Promise<void>}
9
- * @example
10
- *
11
- * const test = async ()=>{
12
- * await waitTime();
13
- * // do something
14
- * }
15
- *
16
- * waitTime(500).then(()=>{
17
- * // do something
18
- * });
19
- *
20
- */
21
- function waitTime() {
22
- var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
23
- return new Promise(function (resolve) {
24
- setTimeout(resolve, time);
25
- });
1
+ function waitTime(time) {
2
+ if (time === void 0) { time = 1000; }
3
+ return new Promise(function (resolve) {
4
+ setTimeout(resolve, time);
5
+ });
26
6
  }
27
- export default waitTime;
7
+
8
+ export { waitTime as default };
package/lib/ajax.js CHANGED
@@ -1,156 +1,55 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- 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); }
8
- /**
9
- * @typedef {XMLHttpRequest['onloadstart']} XMLHttpRequestEvent XMLHttpRequest 事件对象
10
- */
11
-
12
- /**
13
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
14
- * @typedef {Object} AjaxOptions ajax配置项
15
- * @property {string} [method="get"] 创建请求时使用的方法
16
- * @property {Document | XMLHttpRequestBodyInit | null} [data=null] 请求体被发送的数据
17
- * @property {Object.<string, string>} [headers] 自定义请求头
18
- * @property {XMLHttpRequestResponseType} [responseType] 响应类型
19
- * @property {number} [timeout] 请求超时的毫秒数
20
- * @property {boolean} [withCredentials=false] 跨域请求时是否需要使用凭证
21
- * @property {boolean} [async=true] 是否异步执行操作
22
- * @property {string|null} [user=null] 用户名,用于认证用途
23
- * @property {string|null} [password=null] 密码,用于认证用途
24
- * @property {XMLHttpRequestEvent} [onLoadStart] 接收到响应数据时触发
25
- * @property {XMLHttpRequestEvent} [onProgress] 请求接收到更多数据时,周期性地触发
26
- * @property {XMLHttpRequestEvent} [onAbort] 当 request 被停止时触发,例如当程序调用 XMLHttpRequest.abort() 时
27
- * @property {XMLHttpRequestEvent} [onTimeout] 在预设时间内没有接收到响应时触发
28
- * @property {XMLHttpRequestEvent} [onError] 当 request 遭遇错误时触发
29
- * @property {XMLHttpRequestEvent} [onLoad] 请求成功完成时触发
30
- * @property {XMLHttpRequestEvent} [onLoadEnd] 请求结束时触发,无论请求成功 (load) 还是失败 (abort 或 error)
31
- */
32
-
33
- /**
34
- * 请求<br/><br/>
35
- *
36
- * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
37
- *
38
- * @static
39
- * @alias module:Other.ajax
40
- * @since 4.16.0
41
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
42
- * @param {string} url 地址
43
- * @param {AjaxOptions} [options] 配置项
44
- * @returns {Promise<ProgressEvent<EventTarget>>}
45
- * @example
46
- * ajax('/somefile').then(res=>{
47
- * // do something
48
- * });
49
- *
50
- * ajax('/api', { method: 'post' }).then(res=>{
51
- * // do something
52
- * });
53
- */
54
3
  function ajax(url, options) {
55
- var _ref = options || {},
56
- _ref$method = _ref.method,
57
- method = _ref$method === void 0 ? 'get' : _ref$method,
58
- _ref$data = _ref.data,
59
- data = _ref$data === void 0 ? null : _ref$data,
60
- timeout = _ref.timeout,
61
- headers = _ref.headers,
62
- _ref$withCredentials = _ref.withCredentials,
63
- withCredentials = _ref$withCredentials === void 0 ? false : _ref$withCredentials,
64
- _ref$async = _ref.async,
65
- async = _ref$async === void 0 ? true : _ref$async,
66
- _ref$user = _ref.user,
67
- user = _ref$user === void 0 ? null : _ref$user,
68
- _ref$password = _ref.password,
69
- password = _ref$password === void 0 ? null : _ref$password,
70
- responseType = _ref.responseType,
71
- onAbort = _ref.onAbort,
72
- onError = _ref.onError,
73
- onLoad = _ref.onLoad,
74
- onLoadEnd = _ref.onLoadEnd,
75
- onLoadStart = _ref.onLoadStart,
76
- onProgress = _ref.onProgress,
77
- onTimeout = _ref.onTimeout;
78
- return new Promise(function (resolve, reject) {
79
- var xhr = new XMLHttpRequest();
80
- xhr.open(method.toLowerCase(), url, async, user, password);
81
-
82
- // 设置请求超时
83
- if (typeof timeout === 'number' && timeout > 0) {
84
- xhr.timeout = timeout;
85
- }
86
-
87
- // 跨域请求时是否需要使用凭证
88
- xhr.withCredentials = withCredentials;
89
-
90
- // 设置响应类型
91
- if (responseType) {
92
- xhr.responseType = responseType;
93
- }
94
-
95
- // 设置请求头
96
- if (_typeof(headers) === 'object') {
97
- Object.keys(headers).map(function (item) {
98
- xhr.setRequestHeader(item, headers[item]);
99
- });
100
- }
101
-
102
- /**
103
- * 请求成功异步调用
104
- * @param {XMLHttpRequestEvent} [cb] 回调方法
105
- */
106
- var wrapSuccess = function wrapSuccess(cb) {
107
- /**
108
- * 内部方法
109
- * @param {ProgressEvent<EventTarget>} e 事件对象
110
- */
111
- return function (e) {
112
- resolve(e);
113
- cb === null || cb === void 0 ? void 0 : cb.call(xhr, e);
114
- };
115
- };
116
-
117
- /**
118
- * 请求失败(中断/超时/失败)处理
119
- * @param {XMLHttpRequestEvent} [cb] 回调方法
120
- */
121
- var wrapError = function wrapError(cb) {
122
- /**
123
- * 内部方法
124
- * @param {ProgressEvent<EventTarget>} e 事件对象
125
- */
126
- return function (e) {
127
- reject(e);
128
- cb === null || cb === void 0 ? void 0 : cb.call(xhr, e);
129
- };
130
- };
131
-
132
- // 事件处理
133
- /**@type {Object.<keyof XMLHttpRequestEventTargetEventMap, XMLHttpRequestEvent | undefined>} */
134
- var events = {
135
- loadstart: onLoadStart,
136
- progress: onProgress,
137
- abort: wrapError(onAbort),
138
- timeout: wrapError(onTimeout),
139
- error: wrapError(onError),
140
- load: wrapSuccess(onLoad),
141
- loadend: onLoadEnd
142
- };
143
- /**@type {(keyof XMLHttpRequestEventTargetEventMap)[]} */
144
- // @ts-ignore
145
- var eventNames = Object.keys(events);
146
- eventNames.map(function (item) {
147
- var func = events[item];
148
- if (func) {
149
- xhr.addEventListener(item, func);
150
- }
4
+ var _a = options || {}, _b = _a.method, method = _b === void 0 ? 'get' : _b, _c = _a.data, data = _c === void 0 ? null : _c, timeout = _a.timeout, headers = _a.headers, _d = _a.withCredentials, withCredentials = _d === void 0 ? false : _d, _e = _a.async, async = _e === void 0 ? true : _e, _f = _a.user, user = _f === void 0 ? null : _f, _g = _a.password, password = _g === void 0 ? null : _g, responseType = _a.responseType, onReadyStateChange = _a.onReadyStateChange, onLoadStart = _a.onLoadStart, onProgress = _a.onProgress, onAbort = _a.onAbort, onTimeout = _a.onTimeout, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd;
5
+ return new Promise(function (resolve, reject) {
6
+ var xhr = new XMLHttpRequest();
7
+ xhr.open(method.toLowerCase(), url, async, user, password);
8
+ if (onReadyStateChange) {
9
+ xhr.onreadystatechange = onReadyStateChange;
10
+ }
11
+ if (typeof timeout === 'number' && timeout > 0) {
12
+ xhr.timeout = timeout;
13
+ }
14
+ xhr.withCredentials = withCredentials;
15
+ if (responseType) {
16
+ xhr.responseType = responseType;
17
+ }
18
+ if (typeof headers === 'object') {
19
+ Object.keys(headers).map(function (item) {
20
+ xhr.setRequestHeader(item, headers[item]);
21
+ });
22
+ }
23
+ var wrapSuccess = function (cb) {
24
+ return function (e) {
25
+ resolve(e);
26
+ cb === null || cb === void 0 ? void 0 : cb.call(xhr, e);
27
+ };
28
+ };
29
+ var wrapError = function (cb) {
30
+ return function (e) {
31
+ reject(e);
32
+ cb === null || cb === void 0 ? void 0 : cb.call(xhr, e);
33
+ };
34
+ };
35
+ var events = {
36
+ loadstart: onLoadStart,
37
+ progress: onProgress,
38
+ abort: wrapError(onAbort),
39
+ timeout: wrapError(onTimeout),
40
+ error: wrapError(onError),
41
+ load: wrapSuccess(onLoad),
42
+ loadend: onLoadEnd
43
+ };
44
+ var eventKeys = Object.keys(events);
45
+ eventKeys.map(function (item) {
46
+ var func = events[item];
47
+ if (func) {
48
+ xhr.addEventListener(item, func);
49
+ }
50
+ });
51
+ xhr.send(data);
151
52
  });
152
- xhr.send(data);
153
- });
154
53
  }
155
- var _default = ajax;
156
- exports["default"] = _default;
54
+
55
+ module.exports = ajax;
@@ -1,44 +1,9 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _fileReader = _interopRequireDefault(require("./fileReader"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- // file、blob文件如何预览图片?
10
- // 方法1:将file或者blob类型文件转成base64数据,再作为src赋值给img标签
11
- // 方法2:使用 window.URL.createObjectURL(blob) 为blob、file 创建一个指向该参数对象的URL
3
+ var fileReader = require('./fileReader.js');
12
4
 
13
- /**
14
- * 将 Blob 或 File 对象转成 data:URL 格式的 Base64 字符串<br/><br/>
15
- *
16
- * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
17
- *
18
- * @ignore
19
- * @static
20
- * @alias module:Processor.blobToDataURL
21
- * @since 4.1.0
22
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL|FileReader.readAsDataURL()}
23
- * @deprecated 请使用 `fileReader` 方法
24
- * @param {Blob} blob Blob 或 File 对象
25
- * @returns {Promise<string>} data:URL 格式的 Base64 字符串。
26
- * @example
27
- * const aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // 一个包含DOMString的数组
28
- * const htmlBlob = new Blob(aFileParts, { type: 'text/html' }); // 得到 blob
29
- *
30
- * blobToDataURL(htmlBlob).then(data=>{
31
- * console.log(data); // data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
32
- * });
33
- *
34
- * const textBlob = new Blob(aFileParts, { type: 'text/plain' });
35
- *
36
- * blobToDataURL(textBlob).then(data=>{
37
- * console.log(data); // data:text/plain;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
38
- * });
39
- */
40
5
  function blobToDataURL(blob) {
41
- return (0, _fileReader["default"])(blob);
6
+ return fileReader(blob);
42
7
  }
43
- var _default = blobToDataURL;
44
- exports["default"] = _default;
8
+
9
+ module.exports = blobToDataURL;