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