util-helpers 4.16.1 → 4.17.0

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 (260) hide show
  1. package/README.md +3 -1
  2. package/dist/util-helpers.js +1542 -4040
  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 +50 -146
  7. package/esm/blobToDataURL.js +4 -34
  8. package/esm/bytesToSize.js +12 -37
  9. package/esm/calculateCursorPosition.js +30 -52
  10. package/esm/dataURLToBlob.js +14 -28
  11. package/esm/divide.js +24 -48
  12. package/esm/download.js +83 -164
  13. package/esm/fileReader.js +18 -64
  14. package/esm/filterTree.js +25 -57
  15. package/esm/findTreeNode.js +39 -69
  16. package/esm/findTreeNodes.js +35 -68
  17. package/esm/findTreeSelect.js +38 -76
  18. package/esm/formatBankCard.js +13 -43
  19. package/esm/formatMobile.js +17 -43
  20. package/esm/formatMoney.js +59 -139
  21. package/esm/index.js +55 -130
  22. package/esm/isBankCard.js +22 -57
  23. package/esm/isBusinessLicense.js +32 -78
  24. package/esm/isChinese.js +23 -66
  25. package/esm/isEmail.js +6 -21
  26. package/esm/isHMCard.js +5 -28
  27. package/esm/isIPv4.js +5 -22
  28. package/esm/isIPv6.js +5 -36
  29. package/esm/isIdCard.js +27 -66
  30. package/esm/isMobile.js +5 -20
  31. package/esm/isPassport.js +5 -22
  32. package/esm/isPassword.js +7 -48
  33. package/esm/isPostcode.js +5 -20
  34. package/esm/isPromiseLike.js +3 -18
  35. package/esm/isQQ.js +5 -20
  36. package/esm/isSocialCreditCode.js +28 -83
  37. package/esm/isSwiftCode.js +6 -25
  38. package/esm/isTWCard.js +11 -37
  39. package/esm/isTelephone.js +6 -27
  40. package/esm/isUrl.js +5 -44
  41. package/esm/isVehicle.js +5 -28
  42. package/esm/isWX.js +5 -20
  43. package/esm/listToTree.js +51 -122
  44. package/esm/minus.js +21 -39
  45. package/esm/normalizeString.js +8 -29
  46. package/esm/numberToChinese.js +96 -215
  47. package/esm/padZero.js +14 -36
  48. package/esm/parseIdCard.js +64 -132
  49. package/esm/plus.js +21 -39
  50. package/esm/randomString.js +13 -45
  51. package/esm/replaceChar.js +27 -77
  52. package/esm/round.js +14 -31
  53. package/esm/safeDate.js +12 -55
  54. package/esm/setDataURLPrefix.js +6 -29
  55. package/esm/strlen.js +14 -30
  56. package/esm/times.js +24 -42
  57. package/esm/transformFieldNames.js +37 -95
  58. package/esm/treeToList.js +25 -86
  59. package/esm/utils/config.js +4 -14
  60. package/esm/utils/constants.js +4 -4
  61. package/esm/utils/convertToString.js +4 -9
  62. package/esm/utils/devWarn.js +11 -11
  63. package/esm/utils/math.util.js +95 -181
  64. package/esm/utils/type/isBlob.js +4 -24
  65. package/esm/utils/type/isNaN.js +4 -19
  66. package/esm/utils/type/isNil.js +5 -13
  67. package/esm/utils/type/isNull.js +3 -18
  68. package/esm/utils/type/isNumber.js +4 -28
  69. package/esm/utils/type/isObject.js +4 -23
  70. package/esm/utils/type/isString.js +4 -19
  71. package/esm/utils/type/isSymbol.js +4 -19
  72. package/esm/utils/type/isType.js +3 -12
  73. package/esm/utils/type/isUndefined.js +3 -21
  74. package/esm/validatePassword.js +86 -237
  75. package/esm/waitTime.js +7 -26
  76. package/lib/ajax.js +51 -152
  77. package/lib/blobToDataURL.js +5 -40
  78. package/lib/bytesToSize.js +13 -43
  79. package/lib/calculateCursorPosition.js +31 -58
  80. package/lib/dataURLToBlob.js +15 -34
  81. package/lib/divide.js +26 -60
  82. package/lib/download.js +85 -169
  83. package/lib/fileReader.js +19 -70
  84. package/lib/filterTree.js +27 -66
  85. package/lib/findTreeNode.js +40 -77
  86. package/lib/findTreeNodes.js +36 -76
  87. package/lib/findTreeSelect.js +40 -82
  88. package/lib/formatBankCard.js +15 -50
  89. package/lib/formatMobile.js +19 -50
  90. package/lib/formatMoney.js +60 -150
  91. package/lib/index.js +117 -395
  92. package/lib/isBankCard.js +24 -64
  93. package/lib/isBusinessLicense.js +34 -85
  94. package/lib/isChinese.js +24 -73
  95. package/lib/isEmail.js +7 -27
  96. package/lib/isHMCard.js +7 -35
  97. package/lib/isIPv4.js +7 -29
  98. package/lib/isIPv6.js +7 -43
  99. package/lib/isIdCard.js +29 -73
  100. package/lib/isMobile.js +7 -27
  101. package/lib/isPassport.js +7 -29
  102. package/lib/isPassword.js +9 -55
  103. package/lib/isPostcode.js +7 -27
  104. package/lib/isPromiseLike.js +4 -24
  105. package/lib/isQQ.js +7 -27
  106. package/lib/isSocialCreditCode.js +30 -90
  107. package/lib/isSwiftCode.js +7 -32
  108. package/lib/isTWCard.js +13 -44
  109. package/lib/isTelephone.js +7 -33
  110. package/lib/isUrl.js +6 -50
  111. package/lib/isVehicle.js +7 -35
  112. package/lib/isWX.js +7 -27
  113. package/lib/listToTree.js +53 -131
  114. package/lib/minus.js +23 -51
  115. package/lib/normalizeString.js +10 -36
  116. package/lib/numberToChinese.js +98 -222
  117. package/lib/padZero.js +16 -43
  118. package/lib/parseIdCard.js +65 -138
  119. package/lib/plus.js +23 -51
  120. package/lib/randomString.js +14 -51
  121. package/lib/replaceChar.js +28 -83
  122. package/lib/round.js +15 -37
  123. package/lib/safeDate.js +13 -63
  124. package/lib/setDataURLPrefix.js +7 -35
  125. package/lib/strlen.js +16 -37
  126. package/lib/times.js +26 -53
  127. package/lib/transformFieldNames.js +38 -101
  128. package/lib/treeToList.js +27 -94
  129. package/lib/utils/config.js +6 -23
  130. package/lib/utils/constants.js +3 -11
  131. package/lib/utils/convertToString.js +6 -16
  132. package/lib/utils/devWarn.js +13 -17
  133. package/lib/utils/math.util.js +95 -185
  134. package/lib/utils/type/isBlob.js +6 -31
  135. package/lib/utils/type/isNaN.js +6 -26
  136. package/lib/utils/type/isNil.js +7 -20
  137. package/lib/utils/type/isNull.js +4 -24
  138. package/lib/utils/type/isNumber.js +6 -35
  139. package/lib/utils/type/isObject.js +5 -29
  140. package/lib/utils/type/isString.js +6 -26
  141. package/lib/utils/type/isSymbol.js +6 -26
  142. package/lib/utils/type/isType.js +4 -18
  143. package/lib/utils/type/isUndefined.js +4 -27
  144. package/lib/validatePassword.js +87 -244
  145. package/lib/waitTime.js +8 -32
  146. package/package.json +30 -34
  147. package/types/ajax.d.ts +38 -95
  148. package/types/blobToDataURL.d.ts +2 -2
  149. package/types/bytesToSize.d.ts +7 -6
  150. package/types/calculateCursorPosition.d.ts +10 -9
  151. package/types/dataURLToBlob.d.ts +5 -5
  152. package/types/divide.d.ts +2 -2
  153. package/types/download.d.ts +22 -38
  154. package/types/fileReader.d.ts +35 -2
  155. package/types/filterTree.d.ts +6 -7
  156. package/types/findTreeNode.d.ts +5 -7
  157. package/types/findTreeNodes.d.ts +5 -7
  158. package/types/findTreeSelect.d.ts +5 -7
  159. package/types/formatBankCard.d.ts +8 -5
  160. package/types/formatMobile.d.ts +7 -4
  161. package/types/formatMoney.d.ts +8 -7
  162. package/types/index.d.ts +125 -55
  163. package/types/isBankCard.d.ts +9 -8
  164. package/types/isBusinessLicense.d.ts +8 -5
  165. package/types/isChinese.d.ts +9 -8
  166. package/types/isEmail.d.ts +1 -1
  167. package/types/isHMCard.d.ts +2 -2
  168. package/types/isIPv4.d.ts +1 -1
  169. package/types/isIPv6.d.ts +1 -1
  170. package/types/isIdCard.d.ts +8 -7
  171. package/types/isMobile.d.ts +1 -1
  172. package/types/isPassport.d.ts +2 -2
  173. package/types/isPassword.d.ts +4 -7
  174. package/types/isPostcode.d.ts +1 -1
  175. package/types/isPromiseLike.d.ts +1 -1
  176. package/types/isQQ.d.ts +1 -1
  177. package/types/isSocialCreditCode.d.ts +8 -5
  178. package/types/isSwiftCode.d.ts +2 -2
  179. package/types/isTWCard.d.ts +6 -5
  180. package/types/isTelephone.d.ts +1 -1
  181. package/types/isUrl.d.ts +2 -2
  182. package/types/isVehicle.d.ts +2 -2
  183. package/types/isWX.d.ts +1 -1
  184. package/types/listToTree.d.ts +12 -12
  185. package/types/minus.d.ts +3 -2
  186. package/types/normalizeString.d.ts +2 -2
  187. package/types/numberToChinese.d.ts +13 -12
  188. package/types/padZero.d.ts +2 -2
  189. package/types/parseIdCard.d.ts +17 -56
  190. package/types/plus.d.ts +3 -2
  191. package/types/randomString.d.ts +2 -2
  192. package/types/replaceChar.d.ts +15 -11
  193. package/types/round.d.ts +2 -2
  194. package/types/safeDate.d.ts +24 -2
  195. package/types/setDataURLPrefix.d.ts +5 -5
  196. package/types/strlen.d.ts +1 -1
  197. package/types/times.d.ts +3 -2
  198. package/types/transformFieldNames.d.ts +12 -10
  199. package/types/treeToList.d.ts +1 -1
  200. package/types/utils/config.d.ts +6 -5
  201. package/types/utils/constants.d.ts +2 -2
  202. package/types/utils/convertToString.d.ts +1 -1
  203. package/types/utils/devWarn.d.ts +1 -1
  204. package/types/utils/math.util.d.ts +15 -9
  205. package/types/utils/type/index.d.ts +7 -0
  206. package/types/utils/type/isArguments.d.ts +1 -1
  207. package/types/utils/type/isArray.d.ts +1 -1
  208. package/types/utils/type/isArrayBuffer.d.ts +1 -1
  209. package/types/utils/type/isBlob.d.ts +1 -1
  210. package/types/utils/type/isBoolean.d.ts +1 -1
  211. package/types/utils/type/isDate.d.ts +1 -1
  212. package/types/utils/type/isError.d.ts +1 -1
  213. package/types/utils/type/isFunction.d.ts +1 -1
  214. package/types/utils/type/isMap.d.ts +1 -1
  215. package/types/utils/type/isNaN.d.ts +1 -1
  216. package/types/utils/type/isNil.d.ts +1 -1
  217. package/types/utils/type/isNull.d.ts +1 -1
  218. package/types/utils/type/isNumber.d.ts +1 -1
  219. package/types/utils/type/isObject.d.ts +1 -1
  220. package/types/utils/type/isRegExp.d.ts +1 -1
  221. package/types/utils/type/isSet.d.ts +1 -1
  222. package/types/utils/type/isString.d.ts +1 -1
  223. package/types/utils/type/isSymbol.d.ts +1 -1
  224. package/types/utils/type/isType.d.ts +1 -1
  225. package/types/utils/type/isUndefined.d.ts +1 -1
  226. package/types/utils/type/isWeakMap.d.ts +1 -1
  227. package/types/utils/type/isWeakSet.d.ts +1 -1
  228. package/types/validatePassword.d.ts +17 -48
  229. package/types/waitTime.d.ts +2 -2
  230. package/esm/interface.doc.js +0 -125
  231. package/esm/interface.type.js +0 -17
  232. package/esm/utils/type/index.js +0 -29
  233. package/esm/utils/type/isArguments.js +0 -22
  234. package/esm/utils/type/isArray.js +0 -22
  235. package/esm/utils/type/isArrayBuffer.js +0 -25
  236. package/esm/utils/type/isBoolean.js +0 -22
  237. package/esm/utils/type/isDate.js +0 -22
  238. package/esm/utils/type/isError.js +0 -22
  239. package/esm/utils/type/isFunction.js +0 -22
  240. package/esm/utils/type/isMap.js +0 -22
  241. package/esm/utils/type/isRegExp.js +0 -22
  242. package/esm/utils/type/isSet.js +0 -22
  243. package/esm/utils/type/isWeakMap.js +0 -22
  244. package/esm/utils/type/isWeakSet.js +0 -22
  245. package/lib/interface.doc.js +0 -127
  246. package/lib/interface.type.js +0 -5
  247. package/lib/utils/type/index.js +0 -146
  248. package/lib/utils/type/isArguments.js +0 -29
  249. package/lib/utils/type/isArray.js +0 -29
  250. package/lib/utils/type/isArrayBuffer.js +0 -32
  251. package/lib/utils/type/isBoolean.js +0 -29
  252. package/lib/utils/type/isDate.js +0 -29
  253. package/lib/utils/type/isError.js +0 -29
  254. package/lib/utils/type/isFunction.js +0 -29
  255. package/lib/utils/type/isMap.js +0 -29
  256. package/lib/utils/type/isRegExp.js +0 -29
  257. package/lib/utils/type/isSet.js +0 -29
  258. package/lib/utils/type/isWeakMap.js +0 -29
  259. package/lib/utils/type/isWeakSet.js +0 -29
  260. package/types/interface.type.d.ts +0 -2
@@ -1,270 +1,113 @@
1
- "use strict";
1
+ 'use strict';
2
+
3
+ var devWarn = require('./utils/devWarn.js');
2
4
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _devWarn = _interopRequireDefault(require("./utils/devWarn"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
5
  var regNumber = /[\d]/;
10
6
  var regLowerCaseLetter = /[a-z]/;
11
7
  var regUpperCaseLetter = /[A-Z]/;
12
8
  var regAllNumberAndLetter = /[\d|a-z]/gi;
13
-
14
- /**
15
- * 是否包含数字
16
- *
17
- * @private
18
- * @param {string} val 检查的值
19
- * @returns {boolean} 是否包含数字
20
- */
21
9
  function hasNumber(val) {
22
- return regNumber.test(val);
10
+ return regNumber.test(val);
23
11
  }
24
-
25
- /**
26
- * 是否包含小写字母
27
- *
28
- * @private
29
- * @param {string} val 检测的值
30
- * @returns {boolean} 是否包含小写字母
31
- */
32
12
  function hasLowerCaseLetter(val) {
33
- return regLowerCaseLetter.test(val);
13
+ return regLowerCaseLetter.test(val);
34
14
  }
35
-
36
- /**
37
- * 是否包含大写字母
38
- *
39
- * @private
40
- * @param {string} val 检测的值
41
- * @returns {boolean} 是否包含大写字母
42
- */
43
15
  function hasUpperCaseLetter(val) {
44
- return regUpperCaseLetter.test(val);
16
+ return regUpperCaseLetter.test(val);
45
17
  }
46
-
47
- /**
48
- * 是否为十六进制
49
- *
50
- * @private
51
- * @param {string} val 检测的值
52
- * @returns {boolean} 是否为十六进制
53
- */
54
18
  function hasHex(val) {
55
- return val.indexOf('\\x') > -1 || val.indexOf("\\u") > -1;
19
+ return val.indexOf('\\x') > -1 || val.indexOf('\\u') > -1;
56
20
  }
57
-
58
- /**
59
- * 是否包含特殊字符
60
- *
61
- * @private
62
- * @param {string} val 检测的值
63
- * @param {string} chars 特殊字符
64
- * @returns {boolean} 是否包含特殊字符
65
- */
66
21
  function hasSpecialCharacter(val, chars) {
67
- if (!chars || !val) {
68
- return false;
69
- }
70
- var specialChars = val.replace(regAllNumberAndLetter, '');
71
- if (!specialChars) {
72
- return false;
73
- }
74
- var regChars = hasHex(chars) ? new RegExp("[".concat(chars, "]")) : null;
75
- if (regChars) {
76
- return regChars.test(specialChars);
77
- }
78
- var ret = false;
79
- specialChars.split('').some(function (charItem) {
80
- if (chars.indexOf(charItem) > -1) {
81
- ret = true;
22
+ if (!chars || !val) {
23
+ return false;
24
+ }
25
+ var specialChars = val.replace(regAllNumberAndLetter, '');
26
+ if (!specialChars) {
27
+ return false;
28
+ }
29
+ var regChars = hasHex(chars) ? new RegExp("[".concat(chars, "]")) : null;
30
+ if (regChars) {
31
+ return regChars.test(specialChars);
82
32
  }
33
+ var ret = false;
34
+ specialChars.split('').some(function (charItem) {
35
+ if (chars.indexOf(charItem) > -1) {
36
+ ret = true;
37
+ }
38
+ return ret;
39
+ });
83
40
  return ret;
84
- });
85
- return ret;
86
41
  }
87
-
88
- /**
89
- * 是否包含非法字符
90
- *
91
- * @private
92
- * @param {string} val 检测的值
93
- * @param {string} chars 特殊字符
94
- * @returns {boolean} 是否包含非法字符
95
- */
96
42
  function hasUnallowableCharacter(val, chars) {
97
- if (!val) {
98
- return false;
99
- }
100
- var specialChars = val.replace(regAllNumberAndLetter, '');
101
- if (!specialChars) {
102
- return false;
103
- } else if (!chars) {
104
- return true;
105
- }
106
- var regChars = hasHex(chars) ? new RegExp("[^".concat(chars, "]")) : null;
107
- if (regChars) {
108
- return regChars.test(specialChars);
109
- }
110
- var ret = false;
111
- specialChars.split('').some(function (charItem) {
112
- if (chars.indexOf(charItem) === -1) {
113
- ret = true;
43
+ if (!val) {
44
+ return false;
45
+ }
46
+ var specialChars = val.replace(regAllNumberAndLetter, '');
47
+ if (!specialChars) {
48
+ return false;
114
49
  }
50
+ else if (!chars) {
51
+ return true;
52
+ }
53
+ var regChars = hasHex(chars) ? new RegExp("[^".concat(chars, "]")) : null;
54
+ if (regChars) {
55
+ return regChars.test(specialChars);
56
+ }
57
+ var ret = false;
58
+ specialChars.split('').some(function (charItem) {
59
+ if (chars.indexOf(charItem) === -1) {
60
+ ret = true;
61
+ }
62
+ return ret;
63
+ });
115
64
  return ret;
116
- });
117
- return ret;
118
65
  }
119
-
120
- /**
121
- * @typedef {Object} PasswordContaines - 验证密码的包含内容
122
- * @property {boolean} number - 包含数字
123
- * @property {boolean} lowerCaseLetter - 包含小写字母
124
- * @property {boolean} upperCaseLetter - 包含大写字母
125
- * @property {boolean} specialCharacter - 包含特殊字符
126
- * @property {boolean} unallowableCharacter - 包含非法字符
127
- */
128
-
129
- /**
130
- * @typedef {Object} ValidatePasswordReturn - 验证结果
131
- * @property {boolean} validated - 验证结果,根据密码强度、是否包含非法字符得出
132
- * @property {number} level - 强度级别,包含数字/大小写字母/特殊字符
133
- * @property {PasswordContaines} containes - 包含内容
134
- */
135
-
136
- /**
137
- * 验证密码(数字、大小写字母、特殊字符、非法字符)
138
- *
139
- * @static
140
- * @alias module:Validator.validatePassword
141
- * @since 3.7.0
142
- * @see {@link https://baike.baidu.com/item/ASCII#3|ASCII}
143
- * @param {string} value 要检测的值
144
- * @param {Object} [options] 配置项
145
- * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
146
- * @param {boolean} [options.ignoreCase=false] 是否忽略大小写,为 ture 时,大小写字母视为一种字符
147
- * @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符
148
- * @returns {ValidatePasswordReturn} 验证结果
149
- * @example
150
- *
151
- * validatePassword('a12345678');
152
- * // =>
153
- * {
154
- * validated: true, // 验证结果,根据密码强度、是否包含非法字符得出
155
- * level: 2, // 强度级别
156
- * containes: {
157
- * number: true, // 包含数字
158
- * lowerCaseLetter: true, // 包含小写字母
159
- * upperCaseLetter: false, // 包含大写字母
160
- * specialCharacter: false, // 包含特殊字符
161
- * unallowableCharacter: false // 包含非法字符
162
- * }
163
- * }
164
- *
165
- * validatePassword('a12345678', { level: 3 });
166
- * // =>
167
- * {
168
- * validated: false,
169
- * level: 2,
170
- * containes: {
171
- * number: true,
172
- * lowerCaseLetter: true,
173
- * upperCaseLetter: false,
174
- * specialCharacter: false,
175
- * unallowableCharacter: false
176
- * }
177
- * }
178
- *
179
- * validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true });
180
- * // =>
181
- * {
182
- * validated: false,
183
- * level: 3,
184
- * containes: {
185
- * number: true,
186
- * lowerCaseLetter: true,
187
- * upperCaseLetter: true,
188
- * specialCharacter: true,
189
- * unallowableCharacter: true
190
- * }
191
- * }
192
- *
193
- * // 自定义特殊字符
194
- * validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true, special: '_一二三' });
195
- * // =>
196
- * {
197
- * validated: true,
198
- * level: 3,
199
- * containes: {
200
- * number: true,
201
- * lowerCaseLetter: true,
202
- * upperCaseLetter: true,
203
- * specialCharacter: true,
204
- * unallowableCharacter: false
205
- * }
206
- * }
207
- */
208
- function validatePassword(value) {
209
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
210
- var _options$level = options.level,
211
- level = _options$level === void 0 ? 2 : _options$level,
212
- _options$ignoreCase = options.ignoreCase,
213
- ignoreCase = _options$ignoreCase === void 0 ? false : _options$ignoreCase,
214
- _options$special = options.special,
215
- special = _options$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _options$special;
216
- var valStr = value;
217
- if (typeof value !== 'string') {
218
- (0, _devWarn["default"])("[validatePassword] value must be a string.");
219
- valStr = '';
220
- }
221
- var currentLevel = 0;
222
-
223
- // 包含数字
224
- var containesNumber = hasNumber(valStr);
225
- // 包含小写字母
226
- var containesLowerCaseLetter = hasLowerCaseLetter(valStr);
227
- // 包含大写字母
228
- var containesUpperCaseLetter = hasUpperCaseLetter(valStr);
229
- // 包含特殊字符
230
- var containesSpecialCharacter = hasSpecialCharacter(valStr, special);
231
- // 包含非法字符,即含有非数字字母特殊字符以外的其他字符
232
- var containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
233
- if (containesNumber) {
234
- currentLevel += 1;
235
- }
236
-
237
- // 不区分大小写
238
- if (ignoreCase) {
239
- if (containesLowerCaseLetter || containesUpperCaseLetter) {
240
- currentLevel += 1;
66
+ function validatePassword(value, options) {
67
+ if (options === void 0) { options = {}; }
68
+ 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;
69
+ var valStr = value;
70
+ if (typeof value !== 'string') {
71
+ devWarn("[validatePassword] value must be a string.");
72
+ valStr = '';
241
73
  }
242
- } else {
243
- // 区分大小写
244
- if (containesLowerCaseLetter) {
245
- currentLevel += 1;
74
+ var currentLevel = 0;
75
+ var containesNumber = hasNumber(valStr);
76
+ var containesLowerCaseLetter = hasLowerCaseLetter(valStr);
77
+ var containesUpperCaseLetter = hasUpperCaseLetter(valStr);
78
+ var containesSpecialCharacter = hasSpecialCharacter(valStr, special);
79
+ var containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
80
+ if (containesNumber) {
81
+ currentLevel += 1;
246
82
  }
247
- if (containesUpperCaseLetter) {
248
- currentLevel += 1;
83
+ if (ignoreCase) {
84
+ if (containesLowerCaseLetter || containesUpperCaseLetter) {
85
+ currentLevel += 1;
86
+ }
249
87
  }
250
- }
251
- if (containesSpecialCharacter) {
252
- currentLevel += 1;
253
- }
254
-
255
- // 验证结果
256
- var validated = currentLevel >= level && !containesUnallowableCharacter;
257
- return {
258
- validated: validated,
259
- level: currentLevel,
260
- containes: {
261
- number: containesNumber,
262
- lowerCaseLetter: containesLowerCaseLetter,
263
- upperCaseLetter: containesUpperCaseLetter,
264
- specialCharacter: containesSpecialCharacter,
265
- unallowableCharacter: containesUnallowableCharacter
88
+ else {
89
+ if (containesLowerCaseLetter) {
90
+ currentLevel += 1;
91
+ }
92
+ if (containesUpperCaseLetter) {
93
+ currentLevel += 1;
94
+ }
266
95
  }
267
- };
96
+ if (containesSpecialCharacter) {
97
+ currentLevel += 1;
98
+ }
99
+ var validated = currentLevel >= level && !containesUnallowableCharacter;
100
+ return {
101
+ validated: validated,
102
+ level: currentLevel,
103
+ containes: {
104
+ number: containesNumber,
105
+ lowerCaseLetter: containesLowerCaseLetter,
106
+ upperCaseLetter: containesUpperCaseLetter,
107
+ specialCharacter: containesSpecialCharacter,
108
+ unallowableCharacter: containesUnallowableCharacter
109
+ }
110
+ };
268
111
  }
269
- var _default = validatePassword;
270
- exports["default"] = _default;
112
+
113
+ module.exports = validatePassword;
package/lib/waitTime.js CHANGED
@@ -1,34 +1,10 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- /**
8
- * 等待时间返回 Promise 。常用于异步方法中延时。
9
- *
10
- * @static
11
- * @alias module:Other.waitTime
12
- * @since 4.2.0
13
- * @param {number} [time=1000] 延时时间,单位毫秒
14
- * @returns {Promise<void>}
15
- * @example
16
- *
17
- * const test = async ()=>{
18
- * await waitTime();
19
- * // do something
20
- * }
21
- *
22
- * waitTime(500).then(()=>{
23
- * // do something
24
- * });
25
- *
26
- */
27
- function waitTime() {
28
- var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
29
- return new Promise(function (resolve) {
30
- setTimeout(resolve, time);
31
- });
3
+ function waitTime(time) {
4
+ if (time === void 0) { time = 1000; }
5
+ return new Promise(function (resolve) {
6
+ setTimeout(resolve, time);
7
+ });
32
8
  }
33
- var _default = waitTime;
34
- exports["default"] = _default;
9
+
10
+ module.exports = waitTime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "4.16.1",
3
+ "version": "4.17.0",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -15,22 +15,19 @@
15
15
  "test:type": "jest --verbose test/type",
16
16
  "test:validator": "jest --verbose test/validator",
17
17
  "test:processor": "jest --verbose test/processor",
18
- "build": "npm run build:lib && npm run build:esm && npm run build:dist && npm run types",
19
- "build:lib": "rm -rf lib && cross-env MODULE_TYPE=cjs babel src --out-dir lib",
20
- "build:esm": "rm -rf esm && cross-env MODULE_TYPE=esm babel src --out-dir esm",
21
- "build:dist": "rm -rf dist && rollup -c",
18
+ "build": "npm run build:module && npm run build:dist && npm run build:types",
19
+ "build:module": "rm -rf esm && rm -rf lib && rollup -c rollup.module.config.mjs",
20
+ "build:dist": "rm -rf dist && rollup -c rollup.umd.config.mjs",
21
+ "build:types": "rm -rf types && tsc -d --outDir types --emitDeclarationOnly",
22
22
  "build:doc": "npm run doc",
23
- "doc": "rm -rf docs && jsdoc -c conf.json",
23
+ "doc": "rm -rf docs && rm -rf docs-src && tsc --outDir docs-src && jsdoc -c conf.json && rm -rf docs-src",
24
24
  "doc:open": "open ./docs/index.html",
25
- "prettier": "prettier --write 'src/**/*.js' && prettier --write 'test/**/*.js'",
26
- "lint-staged": "lint-staged",
27
- "lint-staged:js": "eslint --ext .js",
25
+ "prettier": "prettier --write 'src/**/*.ts' && prettier --write 'test/**/*.ts'",
28
26
  "precommit": "lint-staged",
29
- "lint": "eslint src --ext .js",
30
- "lint:fix": "eslint src --ext .js --fix",
27
+ "lint": "eslint src --ext .ts",
28
+ "lint:fix": "eslint src --ext .ts --fix",
31
29
  "commit": "cz",
32
- "prepublishOnly": "npm test && npm run build",
33
- "types": "rm -rf types && tsc"
30
+ "prepublishOnly": "npm test && npm run build"
34
31
  },
35
32
  "repository": {
36
33
  "type": "git",
@@ -57,38 +54,37 @@
57
54
  },
58
55
  "homepage": "https://doly-dev.github.io/util-helpers/index.html",
59
56
  "devDependencies": {
60
- "@babel/cli": "^7.8.4",
61
- "@babel/core": "^7.9.0",
62
- "@babel/plugin-transform-modules-commonjs": "^7.14.0",
63
- "@babel/plugin-transform-runtime": "^7.13.15",
64
- "@babel/preset-env": "^7.9.0",
65
- "@babel/preset-typescript": "^7.18.6",
57
+ "@babel/core": "^7.21.4",
58
+ "@babel/preset-env": "^7.21.4",
59
+ "@babel/preset-typescript": "^7.21.4",
66
60
  "@commitlint/cli": "^11.0.0",
67
61
  "@commitlint/config-conventional": "^11.0.0",
68
- "@rollup/plugin-babel": "^5.3.1",
69
- "@rollup/plugin-commonjs": "^19.0.0",
70
- "@rollup/plugin-node-resolve": "^13.0.0",
71
- "@rollup/plugin-replace": "^5.0.1",
72
- "@types/jest": "^29.2.4",
73
- "babel-jest": "^29.3.1",
62
+ "@rollup/plugin-commonjs": "^24.1.0",
63
+ "@rollup/plugin-node-resolve": "^15.0.2",
64
+ "@rollup/plugin-replace": "^5.0.2",
65
+ "@rollup/plugin-terser": "^0.4.1",
66
+ "@rollup/plugin-typescript": "^11.1.0",
67
+ "@types/jest": "^29.5.1",
68
+ "@typescript-eslint/eslint-plugin": "^5.59.1",
69
+ "@typescript-eslint/parser": "^5.59.1",
70
+ "babel-jest": "^29.5.0",
74
71
  "babel-plugin-minify-replace": "^0.5.0",
75
72
  "cross-env": "^7.0.3",
76
73
  "cz-conventional-changelog": "^3.3.0",
77
74
  "docdash": "^1.2.0",
78
- "eslint": "^7.32.0",
75
+ "eslint": "^8.39.0",
79
76
  "husky": "^4.3.6",
80
- "jest": "^29.3.1",
81
- "jest-environment-jsdom": "^29.3.1",
77
+ "jest": "^29.5.0",
78
+ "jest-environment-jsdom": "^29.5.0",
82
79
  "jsdoc": "^3.6.3",
83
80
  "lint-staged": "^11.1.2",
84
- "prettier": "^2.3.2",
85
- "rollup": "^2.49.0",
86
- "rollup-plugin-terser": "^7.0.2",
81
+ "prettier": "^2.8.8",
82
+ "rollup": "^3.21.0",
87
83
  "typescript": "^5.0.4"
88
84
  },
89
85
  "lint-staged": {
90
- "**/*.js": "npm run lint-staged:js",
91
- "**/*.{js,md}": "prettier --write"
86
+ "**/*.ts": "eslint",
87
+ "**/*.{js,ts,md}": "prettier --write"
92
88
  },
93
89
  "husky": {
94
90
  "hooks": {
@@ -101,6 +97,6 @@
101
97
  }
102
98
  },
103
99
  "dependencies": {
104
- "@babel/runtime": "^7.14.0"
100
+ "tslib": "^2.5.0"
105
101
  }
106
102
  }
package/types/ajax.d.ts CHANGED
@@ -1,101 +1,43 @@
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;
1
+ type XMLHttpRequestListener = XMLHttpRequest['onloadstart'];
2
+ type AjaxOptions = {
3
+ method?: string;
4
+ async?: boolean;
5
+ user?: string | null;
6
+ password?: string | null;
7
+ data?: Parameters<XMLHttpRequest['send']>[0];
8
+ headers?: Record<string, string>;
9
+ responseType?: XMLHttpRequestResponseType;
10
+ timeout?: number;
11
+ withCredentials?: boolean;
12
+ onReadyStateChange?: XMLHttpRequest['onreadystatechange'];
13
+ onLoadStart?: XMLHttpRequestListener;
14
+ onProgress?: XMLHttpRequestListener;
15
+ onAbort?: XMLHttpRequestListener;
16
+ onTimeout?: XMLHttpRequestListener;
17
+ onError?: XMLHttpRequestListener;
18
+ onLoad?: XMLHttpRequestListener;
19
+ onLoadEnd?: XMLHttpRequestListener;
76
20
  };
77
21
  /**
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配置项
22
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest | XMLHttpRequest}
23
+ * @typedef {Object} AjaxOptions ajax 配置项
83
24
  * @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
25
  * @property {boolean} [async=true] 是否异步执行操作
90
26
  * @property {string|null} [user=null] 用户名,用于认证用途
91
27
  * @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)
28
+ * @property {object} [headers] 自定义请求头
29
+ * @property {string} [responseType] 响应类型
30
+ * @property {number} [timeout] 请求超时的毫秒数
31
+ * @property {boolean} [withCredentials=false] 跨域请求时是否需要使用凭证
32
+ * @property {*} [data=null] 请求体被发送的数据
33
+ * @property {function} [options.onReadyStateChange] 当 readyState 属性发生变化时触发
34
+ * @property {function} [onLoadStart] 接收到响应数据时触发
35
+ * @property {function} [onProgress] 请求接收到更多数据时,周期性地触发
36
+ * @property {function} [onAbort] 当 request 被停止时触发,例如当程序调用 XMLHttpRequest.abort() 时
37
+ * @property {function} [onTimeout] 在预设时间内没有接收到响应时触发
38
+ * @property {function} [onError] 当 request 遭遇错误时触发
39
+ * @property {function} [onLoad] 请求成功完成时触发
40
+ * @property {function} [onLoadEnd] 请求结束时触发,无论请求成功 (load) 还是失败 (abort 或 error)
99
41
  */
100
42
  /**
101
43
  * 请求<br/><br/>
@@ -105,10 +47,10 @@ export type AjaxOptions = {
105
47
  * @static
106
48
  * @alias module:Other.ajax
107
49
  * @since 4.16.0
108
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
50
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest | XMLHttpRequest}
109
51
  * @param {string} url 地址
110
52
  * @param {AjaxOptions} [options] 配置项
111
- * @returns {Promise<ProgressEvent<EventTarget>>}
53
+ * @returns {Promise<object>} XHR 事件对象
112
54
  * @example
113
55
  * ajax('/somefile').then(res=>{
114
56
  * // do something
@@ -118,4 +60,5 @@ export type AjaxOptions = {
118
60
  * // do something
119
61
  * });
120
62
  */
121
- declare function ajax(url: string, options?: AjaxOptions | undefined): Promise<ProgressEvent<EventTarget>>;
63
+ declare function ajax(url: string, options?: AjaxOptions): Promise<ProgressEvent<EventTarget>>;
64
+ export default ajax;