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
package/lib/isPassword.js CHANGED
@@ -1,57 +1,11 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _validatePassword = _interopRequireDefault(require("./validatePassword"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- /**
10
- * 检测值是否符合密码强度
11
- * <p><strong>注意:该校验只校验是否存在不同字符(大小写字母、数字、特殊符号),不判断长度。</strong></p>
12
- * <p><i>如果需要更细致的验证,请使用 <a href="#.validatePassword">validatePassword</a></i></p>
13
- *
14
- * @static
15
- * @alias module:Validator.isPassword
16
- * @requires module:Validator.validatePassword
17
- * @since 1.1.0
18
- * @see {@link https://baike.baidu.com/item/ASCII#3|ASCII}
19
- * @param {*} value 要检测的值
20
- * @param {Object} [options] 配置项
21
- * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
22
- * @param {boolean} [options.ignoreCase=false] 是否忽略大小写,为 ture 时,大小写字母视为一种字符
23
- * @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符
24
- * @returns {boolean} 值是否符合密码强度
25
- * @example
26
- *
27
- * isPassword('a12345678'); // true
28
- *
29
- * // 3级密码强度
30
- * isPassword('a12345678', {level: 3}); // false
31
- * isPassword('Aa12345678', {level: 3}); // true
32
- *
33
- * // 3级密码强度,大小写字符仅计算1级强度
34
- * isPassword('Aa12345678', {level: 3, ignoreCase: true}); // false
35
- * isPassword('_Aa12345678', {level: 3, ignoreCase: true}); // true
36
- *
37
- * // 仅支持 数字、字母、特殊字符,其他非法字符如中文字符是校验不通过的
38
- * isPassword('_Aa一二三45678', {level: 3, ignoreCase: true}); // false
39
- * isPassword(' _Aa12345678', {level: 3, ignoreCase: true}); // false
40
- *
41
- */
42
- function isPassword(value) {
43
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
44
- var _options$level = options.level,
45
- level = _options$level === void 0 ? 2 : _options$level,
46
- _options$ignoreCase = options.ignoreCase,
47
- ignoreCase = _options$ignoreCase === void 0 ? false : _options$ignoreCase,
48
- _options$special = options.special,
49
- special = _options$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _options$special;
50
- return (0, _validatePassword["default"])(value, {
51
- level: level,
52
- ignoreCase: ignoreCase,
53
- special: special
54
- }).validated;
3
+ var validatePassword = require('./validatePassword.js');
4
+
5
+ function isPassword(value, options) {
6
+ if (options === void 0) { options = {}; }
7
+ 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;
8
+ return validatePassword(value, { level: level, ignoreCase: ignoreCase, special: special }).validated;
55
9
  }
56
- var _default = isPassword;
57
- exports["default"] = _default;
10
+
11
+ module.exports = isPassword;
package/lib/isPostcode.js CHANGED
@@ -1,31 +1,11 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _normalizeString = _interopRequireDefault(require("./normalizeString"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- // 邮政编码
10
- var reg = /^\d{6}$/;
3
+ var normalizeString = require('./normalizeString.js');
11
4
 
12
- /**
13
- * 检测值是否为邮政编码,6位数字
14
- *
15
- * @static
16
- * @alias module:Validator.isPostcode
17
- * @since 1.1.0
18
- * @param {*} value 要检测的值
19
- * @returns {boolean} 值是否为邮政编码
20
- * @example
21
- *
22
- * isPostcode('101111'); // true
23
- * isPostcode('123'); // false
24
- *
25
- */
5
+ var reg = /^\d{6}$/;
26
6
  function isPostcode(value) {
27
- var valueStr = (0, _normalizeString["default"])(value);
28
- return reg.test(valueStr);
7
+ var valueStr = normalizeString(value);
8
+ return reg.test(valueStr);
29
9
  }
30
- var _default = isPostcode;
31
- exports["default"] = _default;
10
+
11
+ module.exports = isPostcode;
@@ -1,27 +1,7 @@
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
- * 检测值是否类似Promise对象
10
- *
11
- * @static
12
- * @alias module:Validator.isPromiseLike
13
- * @since 3.8.0
14
- * @param {*} obj 要检测的值
15
- * @returns {boolean} 是否类似Promise对象
16
- * @example
17
- *
18
- * isPromiseLike([]); // false
19
- * isPromiseLike({ then: () => { } }); // true
20
- * isPromiseLike(Promise.resolve()); // true
21
- *
22
- */
23
3
  function isPromiseLike(obj) {
24
- return obj !== null && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
4
+ return obj !== null && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
25
5
  }
26
- var _default = isPromiseLike;
27
- exports["default"] = _default;
6
+
7
+ module.exports = isPromiseLike;
package/lib/isQQ.js CHANGED
@@ -1,31 +1,11 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _normalizeString = _interopRequireDefault(require("./normalizeString"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- // QQ号正则
10
- var reg = /^[1-9]\d{4,10}$/;
3
+ var normalizeString = require('./normalizeString.js');
11
4
 
12
- /**
13
- * 检测值是否为QQ号,非0开头,5至11位数字
14
- *
15
- * @static
16
- * @alias module:Validator.isQQ
17
- * @since 1.1.0
18
- * @param {*} value 要检测的值
19
- * @returns {boolean} 值是否为QQ号
20
- * @example
21
- *
22
- * isQQ('12345'); // true
23
- * isQQ('123'); // false
24
- *
25
- */
5
+ var reg = /^[1-9]\d{4,10}$/;
26
6
  function isQQ(value) {
27
- var valueStr = (0, _normalizeString["default"])(value);
28
- return reg.test(valueStr);
7
+ var valueStr = normalizeString(value);
8
+ return reg.test(valueStr);
29
9
  }
30
- var _default = isQQ;
31
- exports["default"] = _default;
10
+
11
+ module.exports = isQQ;
@@ -1,96 +1,36 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _normalizeString = _interopRequireDefault(require("./normalizeString"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- // 基础规则,由18位数字和大写字母组成,不使用I、O、Z、S、V。
10
- var baseReg = /^[\dA-HJ-NPQRTUWXY]{2}\d{6}[\dA-HJ-NPQRTUWXY]{10}$/;
3
+ var normalizeString = require('./normalizeString.js');
11
4
 
12
- // 基础字符组成
5
+ var baseReg = /^[\dA-HJ-NPQRTUWXY]{2}\d{6}[\dA-HJ-NPQRTUWXY]{10}$/;
13
6
  var baseCodeArr = '0123456789ABCDEFGHJKLMNPQRTUWXY'.split('');
14
-
15
- /**
16
- * 计算校验码
17
- *
18
- * @private
19
- * @since 1.1.0
20
- * @param {string} preCode 统一代码前17位
21
- * @returns {string} 校验码
22
- */
23
7
  function sumCheckCode(preCode) {
24
- var total = 0;
25
-
26
- // 计算字符位置对应序号和加权因子的乘积,总和
27
- var _loop = function _loop(i) {
28
- // 字符位置对应的基础编码序号
29
- var index = baseCodeArr.findIndex(function (item) {
30
- return item === preCode[i];
31
- });
32
- // 加权因子
33
- var wf = Math.pow(3, i) % 31;
34
- // 计算序号和加权因子的乘积,并计算级数之和
35
- total += index * wf;
36
- };
37
- for (var i = 0; i < 17; i++) {
38
- _loop(i);
39
- }
40
-
41
- // 计算整数求余函数MOD
42
- var remainder = total % 31;
43
- // 校验码字符值序号
44
- var checkCodeIndex = remainder !== 0 ? 31 - remainder : 0;
45
- return baseCodeArr[checkCodeIndex];
8
+ var total = 0;
9
+ var _loop_1 = function (i) {
10
+ var index = baseCodeArr.findIndex(function (item) { return item === preCode[i]; });
11
+ var wf = Math.pow(3, i) % 31;
12
+ total += index * wf;
13
+ };
14
+ for (var i = 0; i < 17; i++) {
15
+ _loop_1(i);
16
+ }
17
+ var remainder = total % 31;
18
+ var checkCodeIndex = remainder !== 0 ? 31 - remainder : 0;
19
+ return baseCodeArr[checkCodeIndex];
46
20
  }
47
-
48
- /**
49
- * 检测值是否为统一社会信用代码,也叫三证合一组织代码。由18位数字和大写字母组成,不使用I、O、Z、S、V。
50
- *
51
- * @static
52
- * @alias module:Validator.isSocialCreditCode
53
- * @since 1.1.0
54
- * @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则|GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
55
- * @param {*} value 要检测的值
56
- * @param {Object} [options] 配置项
57
- * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
58
- * @returns {boolean} 值是否为统一社会信用代码
59
- * @example
60
- *
61
- * isSocialCreditCode('91350100M000100Y43'); // true
62
- * isSocialCreditCode('91350100M000100Y4A'); // false
63
- *
64
- * // 不校验校验位,长度和类型还是有校验的
65
- * isSocialCreditCode('91350100M000100Y4A', { checkCode: false }); // true
66
- * isSocialCreditCode('91350100M000100YIO', { checkCode: false }); // false
67
- * isSocialCreditCode('91350100M000100Y', { checkCode: false }); // false
68
- *
69
- */
70
- function isSocialCreditCode(value) {
71
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
72
- var valueStr = (0, _normalizeString["default"])(value);
73
- // @ts-ignore
74
- // TODO 下个版本废弃 loose
75
- var _options$loose = options.loose,
76
- loose = _options$loose === void 0 ? false : _options$loose,
77
- _options$checkCode = options.checkCode,
78
- cc = _options$checkCode === void 0 ? true : _options$checkCode;
79
- var needCheckCode = !loose && cc;
80
- var passBaseRule = baseReg.test(valueStr);
81
-
82
- // 宽松模式 或 基础规则不通过直接返回
83
- if (!needCheckCode || !passBaseRule) {
84
- return passBaseRule;
85
- }
86
-
87
- // 前17位
88
- var preCode = valueStr.substring(0, 17);
89
- // 校验码
90
- var lastCode = valueStr.substring(valueStr.length - 1);
91
- // 计算校验码
92
- var checkCode = sumCheckCode(preCode);
93
- return lastCode === checkCode;
21
+ function isSocialCreditCode(value, options) {
22
+ if (options === void 0) { options = {}; }
23
+ var valueStr = normalizeString(value);
24
+ var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.checkCode, cc = _b === void 0 ? true : _b;
25
+ var needCheckCode = !loose && cc;
26
+ var passBaseRule = baseReg.test(valueStr);
27
+ if (!needCheckCode || !passBaseRule) {
28
+ return passBaseRule;
29
+ }
30
+ var preCode = valueStr.substring(0, 17);
31
+ var lastCode = valueStr.substring(valueStr.length - 1);
32
+ var checkCode = sumCheckCode(preCode);
33
+ return lastCode === checkCode;
94
34
  }
95
- var _default = isSocialCreditCode;
96
- exports["default"] = _default;
35
+
36
+ module.exports = isSocialCreditCode;
@@ -1,36 +1,11 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _normalizeString = _interopRequireDefault(require("./normalizeString"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- var reg = /^[A-Z]{6}[A-Z\d]{2}(?:[A-Z\d]{3})?$/;
3
+ var normalizeString = require('./normalizeString.js');
10
4
 
11
- /**
12
- * 检测值是否为 Swift Code。8位或11位,前6位为大写字母,7-8位为大写字母或数字,9-11位为可选的大写字母或数字。
13
- *
14
- * @static
15
- * @alias module:Validator.isSwiftCode
16
- * @since 4.9.0
17
- * @see {@link https://zh.wikipedia.org/wiki/ISO_9362|ISO 9362}
18
- * @param {*} value 要检测的值
19
- * @returns {boolean} 值是否为 Swift Code
20
- * @example
21
- *
22
- * isSwiftCode('DEUTDEFF'); // true
23
- * isSwiftCode('deutdeff'); // false
24
- *
25
- * isSwiftCode('BKTWTWTP010'); // true
26
- * isSwiftCode('010BKTWTWTP'); // false
27
- *
28
- * isSwiftCode('ICBKCNBJBJM'); // true
29
- *
30
- */
5
+ var reg = /^[A-Z]{6}[A-Z\d]{2}(?:[A-Z\d]{3})?$/;
31
6
  function isSwiftCode(value) {
32
- var valueStr = (0, _normalizeString["default"])(value);
33
- return reg.test(valueStr);
7
+ var valueStr = normalizeString(value);
8
+ return reg.test(valueStr);
34
9
  }
35
- var _default = isSwiftCode;
36
- exports["default"] = _default;
10
+
11
+ module.exports = isSwiftCode;
package/lib/isTWCard.js CHANGED
@@ -1,48 +1,17 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _normalizeString = _interopRequireDefault(require("./normalizeString"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- // 台湾居民来往大陆通行证正则
10
- var regTWCard = /^\d{8}$/i;
3
+ var normalizeString = require('./normalizeString.js');
11
4
 
12
- // 一次性短期台胞证
5
+ var regTWCard = /^\d{8}$/i;
13
6
  var singleRegTWCard = /^[\da-z]{10,12}$/i;
14
-
15
- /**
16
- * 检测值是否为台湾居民来往大陆通行证,俗称台胞证。
17
- *
18
- * @static
19
- * @alias module:Validator.isTWCard
20
- * @since 4.0.0
21
- * @see {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
22
- * @param {*} value 要检测的值
23
- * @param {Object} [options] 配置项
24
- * @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
25
- * @returns {boolean} 是否为台湾居民来往大陆通行证
26
- * @example
27
- *
28
- * isTWCard('12345678'); // true
29
- * isTWCard('07257456'); // true
30
- *
31
- * // 一次性短期
32
- * isTWCard('F290299977'); // false
33
- *
34
- * // 宽松模式,支持一次性短期通行证
35
- * isTWCard('F290299977', { loose: true }); // true
36
- */
37
- function isTWCard(value) {
38
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
39
- var _options$loose = options.loose,
40
- loose = _options$loose === void 0 ? false : _options$loose;
41
- var valueStr = (0, _normalizeString["default"])(value);
42
- if (regTWCard.test(valueStr)) {
43
- return true;
44
- }
45
- return loose ? singleRegTWCard.test(valueStr) : false;
7
+ function isTWCard(value, options) {
8
+ if (options === void 0) { options = {}; }
9
+ var _a = options.loose, loose = _a === void 0 ? false : _a;
10
+ var valueStr = normalizeString(value);
11
+ if (regTWCard.test(valueStr)) {
12
+ return true;
13
+ }
14
+ return loose ? singleRegTWCard.test(valueStr) : false;
46
15
  }
47
- var _default = isTWCard;
48
- exports["default"] = _default;
16
+
17
+ module.exports = isTWCard;
@@ -1,37 +1,11 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _normalizeString = _interopRequireDefault(require("./normalizeString"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- // 固定电话 支持区号和分机号 3~4位区号,以0开头;7~8位直播号,以2~9开头;1~6位分机号
10
- var reg = /^(0\d{2,3}\-)?([2-9]\d{6,7})(\-\d{1,6})?$/;
3
+ var normalizeString = require('./normalizeString.js');
11
4
 
12
- /**
13
- * 检测值是否为固定电话
14
- *
15
- * @static
16
- * @alias module:Validator.isTelephone
17
- * @since 1.1.0
18
- * @param {*} value 要检测的值
19
- * @returns {boolean} 值是否为固定电话
20
- * @example
21
- *
22
- * isTelephone('22033212'); // true
23
- * isTelephone('13000000000'); // false
24
- *
25
- * // 含区号
26
- * isTelephone('021-22033212'); // true
27
- *
28
- * // 含区号和分机号
29
- * isTelephone('021-22033212-123'); // true
30
- *
31
- */
5
+ var reg = /^(0\d{2,3}-)?([2-9]\d{6,7})(-\d{1,6})?$/;
32
6
  function isTelephone(value) {
33
- var valueStr = (0, _normalizeString["default"])(value);
34
- return reg.test(valueStr);
7
+ var valueStr = normalizeString(value);
8
+ return reg.test(valueStr);
35
9
  }
36
- var _default = isTelephone;
37
- exports["default"] = _default;
10
+
11
+ module.exports = isTelephone;
package/lib/isUrl.js CHANGED
@@ -1,18 +1,7 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _normalizeString = _interopRequireDefault(require("./normalizeString"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- // 标准格式如下:
10
- // [协议类型]://[服务器地址]:[端口号]/[资源层级UNIX文件路径][文件名]?[查询]#[片段ID]
3
+ var normalizeString = require('./normalizeString.js');
11
4
 
12
- // 完整格式如下:
13
- // [协议类型]://[访问资源需要的凭证信息]@[服务器地址]:[端口号]/[资源层级UNIX文件路径][文件名]?[查询]#[片段ID]
14
- //
15
- // 其中[访问凭证信息]、[端口号]、[查询]、[片段ID]都属于选填项。
16
5
  var protocalReg = '[\\w-.]+:\\/\\/';
17
6
  var credentialsReg = '[-;:&=\\+\\$,\\w]+@';
18
7
  var serverReg = 'localhost|(([^\\s:\\/]+?\\.)+?[^\\s:\\/]+)';
@@ -22,41 +11,9 @@ var searchReg = '\\?.*';
22
11
  var hashReg = '#.*';
23
12
  var regWithProtocal = new RegExp("^".concat(protocalReg, "(?:").concat(credentialsReg, ")?(?:").concat(serverReg, ")(?:").concat(portReg, ")?(?:").concat(pathReg, ")*(?:").concat(searchReg, ")?(?:").concat(hashReg, ")?$"));
24
13
  var regNonProtocal = new RegExp("^(?:".concat(serverReg, ")(?:").concat(portReg, ")?(?:").concat(pathReg, ")*(?:").concat(searchReg, ")?(?:").concat(hashReg, ")?$"));
25
-
26
- /**
27
- * 检测值是否为url
28
- *
29
- * @static
30
- * @alias module:Validator.isUrl
31
- * @since 3.4.0
32
- * @see {@link https://zh.wikipedia.org/wiki/统一资源定位符|统一资源定位符}
33
- * @param {*} value 要检测的值
34
- * @returns {boolean} 值是否为url
35
- * @example
36
- *
37
- * isUrl(''); // false
38
- * isUrl('/foo/bar'); // false
39
- *
40
- * isUrl('8.8.8.8'); // true
41
- * isUrl('example.com'); // true
42
- * isUrl('http://example.com'); // true
43
- * isUrl('https://example.com:8080'); // true
44
- * isUrl('https://www.example.com/test/123'); // true
45
- * isUrl('https://www.example.com/test/123?foo=bar'); // true
46
- * isUrl('https://www.example.com/test/123?foo=中文#id'); // true
47
- * isUrl('https://www.example.com/test/123?foo=中文#测试'); // true
48
- * isUrl('ftp://127.0.0.1:8080/测试.tar'); // true
49
- * isUrl('a.b'); // true
50
- * isUrl('a.b:8080'); // true
51
- * isUrl('p://a.b'); // true
52
- * isUrl('p://a.b:8888'); // true
53
- * isUrl('中文域名.中文后缀'); // true
54
- * isUrl('中文域名.cn'); // true
55
- *
56
- */
57
14
  function isUrl(value) {
58
- var valueStr = (0, _normalizeString["default"])(value);
59
- return regWithProtocal.test(valueStr) || regNonProtocal.test(valueStr);
15
+ var valueStr = normalizeString(value);
16
+ return regWithProtocal.test(valueStr) || regNonProtocal.test(valueStr);
60
17
  }
61
- var _default = isUrl;
62
- exports["default"] = _default;
18
+
19
+ module.exports = isUrl;
package/lib/isVehicle.js CHANGED
@@ -1,39 +1,11 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _normalizeString = _interopRequireDefault(require("./normalizeString"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- // 车牌号正则
10
- var reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})|([A-Z0-9]{5}[DF])|([DF][A-Z0-9]{5}))$/;
3
+ var normalizeString = require('./normalizeString.js');
11
4
 
12
- /**
13
- * 检测值是否为车牌号,支持新能源和非新能源车牌
14
- *
15
- * @static
16
- * @alias module:Validator.isVehicle
17
- * @since 1.1.0
18
- * @see {@link https://baike.baidu.com/item/车牌号|车牌号}
19
- * @param {*} value 要检测的值
20
- * @returns {boolean} 值是否为车牌号
21
- * @example
22
- *
23
- * isVehicle('京L12345'); // true
24
- * isVehicle('京L1234学'); // true
25
- * isVehicle('BL1234警'); // true
26
- *
27
- * // 新能源车牌
28
- * isVehicle('粤BD12345'); // true
29
- * isVehicle('粤BF12345'); // true
30
- * isVehicle('粤B12345D'); // true
31
- * isVehicle('粤B12345F'); // true
32
- *
33
- */
5
+ var reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})|([A-Z0-9]{5}[DF])|([DF][A-Z0-9]{5}))$/;
34
6
  function isVehicle(value) {
35
- var valueStr = (0, _normalizeString["default"])(value);
36
- return reg.test(valueStr);
7
+ var valueStr = normalizeString(value);
8
+ return reg.test(valueStr);
37
9
  }
38
- var _default = isVehicle;
39
- exports["default"] = _default;
10
+
11
+ module.exports = isVehicle;
package/lib/isWX.js CHANGED
@@ -1,31 +1,11 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _normalizeString = _interopRequireDefault(require("./normalizeString"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- // 微信号 6至20位,以字母开头,字母,数字,减号(连接符),下划线
10
- var reg = /^[a-z]([-_a-z0-9]{5,19})+$/i;
3
+ var normalizeString = require('./normalizeString.js');
11
4
 
12
- /**
13
- * 检测值是否为微信号
14
- *
15
- * @static
16
- * @alias module:Validator.isWX
17
- * @since 1.1.0
18
- * @param {*} value 要检测的值
19
- * @returns {boolean} 值是否为微信号
20
- * @example
21
- *
22
- * isWX('a12345'); // true
23
- * isWX('123'); // false
24
- *
25
- */
5
+ var reg = /^[a-z]([-_a-z0-9]{5,19})+$/i;
26
6
  function isWX(value) {
27
- var valueStr = (0, _normalizeString["default"])(value);
28
- return reg.test(valueStr);
7
+ var valueStr = normalizeString(value);
8
+ return reg.test(valueStr);
29
9
  }
30
- var _default = isWX;
31
- exports["default"] = _default;
10
+
11
+ module.exports = isWX;