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/index.js CHANGED
@@ -1,130 +1,55 @@
1
- /**
2
- * 数据验证
3
- *
4
- * @module Validator
5
- * @since 1.1.0
6
- */
7
- export { default as isMobile } from './isMobile';
8
- export { default as isTelephone } from './isTelephone';
9
- export { default as isPostcode } from './isPostcode';
10
- export { default as isIdCard } from './isIdCard';
11
- export { default as isEmail } from './isEmail';
12
- export { default as isQQ } from './isQQ';
13
- export { default as isWX } from './isWX';
14
- export { default as isVehicle } from './isVehicle';
15
- export { default as isBankCard } from './isBankCard';
16
- export { default as isSocialCreditCode } from './isSocialCreditCode';
17
- export { default as isPassword } from './isPassword';
18
- export { default as isPassport } from './isPassport';
19
- export { default as isChinese } from './isChinese';
20
- export { default as isIPv4 } from './isIPv4';
21
- export { default as isIPv6 } from './isIPv6';
22
- export { default as isUrl } from './isUrl';
23
- export { default as isBusinessLicense } from './isBusinessLicense';
24
- export { default as validatePassword } from './validatePassword';
25
- export { default as isPromiseLike } from './isPromiseLike';
26
- export { default as isHMCard } from './isHMCard';
27
- export { default as isTWCard } from './isTWCard';
28
- export { default as isSwiftCode } from './isSwiftCode';
29
-
30
- /**
31
- * 数据处理
32
- *
33
- * @module Processor
34
- * @since 1.1.0
35
- */
36
- export { default as formatMoney } from './formatMoney';
37
- export { default as formatBankCard } from './formatBankCard';
38
- export { default as replaceChar } from './replaceChar';
39
- export { default as numberToChinese } from './numberToChinese';
40
- export { default as bytesToSize } from './bytesToSize';
41
- export { default as parseIdCard } from './parseIdCard';
42
- export { default as blobToDataURL } from './blobToDataURL';
43
- export { default as fileReader } from './fileReader';
44
- export { default as dataURLToBlob } from './dataURLToBlob';
45
- export { default as setDataURLPrefix } from './setDataURLPrefix';
46
- export { default as normalizeString } from './normalizeString';
47
- export { default as safeDate } from './safeDate';
48
- export { default as formatMobile } from './formatMobile';
49
- export { default as padZero } from './padZero';
50
-
51
- /**
52
- * 数学计算,修正浮点数计算问题
53
- *
54
- * @module Math
55
- * @since 3.1.0
56
- * @see {@link https://github.com/camsong/blog/issues/9|JavaScript 浮点数陷阱及解法}
57
- * @see {@link https://2zbuy.csb.app/|JS浮点数计算测试}
58
- * @example
59
- * // 从 4.12.0 版本开始,规范了有效数值。(注意:4.12.3 对有效数值重新定义)
60
- * // 有效数值即能通过 Number(value) 转为数字,且不能为 NaN 。
61
- *
62
- * // 以下为有效数值:
63
- * // 1. 数字: 1, -1, 1e-2, 1.312, 0.1, Infinity
64
- * // 2. 字符串: '1', '10e2', '-1', '0.1', '', ' ', ' 15', ' 15 '
65
- * // 4. 其他类型: null, new Date(), [], new Array(), true, false,...
66
- *
67
- * // 以下为无效数值:
68
- * // 1. 字符串: '1a', '-12a', '10.2.2', '10e2.1'
69
- * // 2. 其他类型: undefined, [], {}, Symbol(), function(){}, ()=>{}
70
- *
71
- * // 计算说明:
72
- * // 四则运算的第二个参数都是有默认值(乘数和除数默认1,加数和减数默认0)
73
- * plus(); // NaN 0个参数时,被加数转换为 Number(undefined) NaN ,NaN+0 = NaN 。其他计算方法如果没有参数一样返回 NaN 。
74
- * plus(0.1); // 0.1 第二个参数,加数默认为 0
75
- * plus(undefined, 0.1); // NaN 第一个参数被加数转换为 Number(undefined) NaN ,NaN+0 = NaN 。其他计算方法如果第一个参数为无效数值一样返回 NaN 。
76
- * plus(true, null); // 1 Number(true) 转换为 1 , Number(null) 转换为 0 , 1+0=1
77
- *
78
- * // 2. 参数中包含无效数值,返回NaN
79
- * plus('0.1', ' a'); // NaN
80
- * plus(true, {}); // NaN
81
- * plus(true, 0.1, Symbol()); // NaN
82
- *
83
- * // 注意:
84
- * // 如果第二个及后面的参数如果值为 undefined 取默认值,即乘除数取 1 ,加减法取 0 。
85
- * plus(0.1, undefined); // 0.1
86
- * plus(0.1, undefined, 0.2, undefined); // 0.3 后面的 undefined 取默认值 0
87
- * times(0.1, undefined, 0.2, undefined); // 0.02 后面的 undefined 取默认值 1
88
- *
89
- */
90
- export { default as plus } from './plus';
91
- export { default as minus } from './minus';
92
- export { default as times } from './times';
93
- export { default as divide } from './divide';
94
- export { default as round } from './round';
95
-
96
- /**
97
- * 其他
98
- *
99
- * @module Other
100
- * @since 4.2.0
101
- */
102
- export { default as ajax } from './ajax';
103
- export { default as calculateCursorPosition } from './calculateCursorPosition';
104
- export { default as download } from './download';
105
- export { default as randomString } from './randomString';
106
- export { default as strlen } from './strlen';
107
- export { default as waitTime } from './waitTime';
108
-
109
- /**
110
- * 树结构数据查询、过滤、转换等处理方法
111
- *
112
- * @module Tree
113
- * @since 4.14.0
114
- */
115
- export { default as transformFieldNames } from './transformFieldNames';
116
- export { default as listToTree } from './listToTree';
117
- export { default as treeToList } from './treeToList';
118
- export { default as filterTree } from './filterTree';
119
- export { default as findTreeNode } from './findTreeNode';
120
- export { default as findTreeNodes } from './findTreeNodes';
121
- export { default as findTreeSelect } from './findTreeSelect';
122
-
123
- /**
124
- * 调试相关
125
- *
126
- * @module Debug
127
- * @ignore
128
- * @since 3.6.1
129
- */
130
- export { setDisableWarning, version } from './utils/config';
1
+ export { default as isMobile } from './isMobile.js';
2
+ export { default as isTelephone } from './isTelephone.js';
3
+ export { default as isPostcode } from './isPostcode.js';
4
+ export { default as isIdCard } from './isIdCard.js';
5
+ export { default as isEmail } from './isEmail.js';
6
+ export { default as isQQ } from './isQQ.js';
7
+ export { default as isWX } from './isWX.js';
8
+ export { default as isVehicle } from './isVehicle.js';
9
+ export { default as isBankCard } from './isBankCard.js';
10
+ export { default as isSocialCreditCode } from './isSocialCreditCode.js';
11
+ export { default as isPassword } from './isPassword.js';
12
+ export { default as isPassport } from './isPassport.js';
13
+ export { default as isChinese } from './isChinese.js';
14
+ export { default as isIPv4 } from './isIPv4.js';
15
+ export { default as isIPv6 } from './isIPv6.js';
16
+ export { default as isUrl } from './isUrl.js';
17
+ export { default as isBusinessLicense } from './isBusinessLicense.js';
18
+ export { default as validatePassword } from './validatePassword.js';
19
+ export { default as isPromiseLike } from './isPromiseLike.js';
20
+ export { default as isHMCard } from './isHMCard.js';
21
+ export { default as isTWCard } from './isTWCard.js';
22
+ export { default as isSwiftCode } from './isSwiftCode.js';
23
+ export { default as formatMoney } from './formatMoney.js';
24
+ export { default as formatBankCard } from './formatBankCard.js';
25
+ export { default as replaceChar } from './replaceChar.js';
26
+ export { default as numberToChinese } from './numberToChinese.js';
27
+ export { default as bytesToSize } from './bytesToSize.js';
28
+ export { default as parseIdCard } from './parseIdCard.js';
29
+ export { default as blobToDataURL } from './blobToDataURL.js';
30
+ export { default as fileReader } from './fileReader.js';
31
+ export { default as dataURLToBlob } from './dataURLToBlob.js';
32
+ export { default as setDataURLPrefix } from './setDataURLPrefix.js';
33
+ export { default as normalizeString } from './normalizeString.js';
34
+ export { default as safeDate } from './safeDate.js';
35
+ export { default as formatMobile } from './formatMobile.js';
36
+ export { default as padZero } from './padZero.js';
37
+ export { default as plus } from './plus.js';
38
+ export { default as minus } from './minus.js';
39
+ export { default as times } from './times.js';
40
+ export { default as divide } from './divide.js';
41
+ export { default as round } from './round.js';
42
+ export { default as ajax } from './ajax.js';
43
+ export { default as calculateCursorPosition } from './calculateCursorPosition.js';
44
+ export { default as download } from './download.js';
45
+ export { default as randomString } from './randomString.js';
46
+ export { default as strlen } from './strlen.js';
47
+ export { default as waitTime } from './waitTime.js';
48
+ export { default as transformFieldNames } from './transformFieldNames.js';
49
+ export { default as listToTree } from './listToTree.js';
50
+ export { default as treeToList } from './treeToList.js';
51
+ export { default as filterTree } from './filterTree.js';
52
+ export { default as findTreeNode } from './findTreeNode.js';
53
+ export { default as findTreeNodes } from './findTreeNodes.js';
54
+ export { default as findTreeSelect } from './findTreeSelect.js';
55
+ export { setDisableWarning, version } from './utils/config.js';
package/esm/isBankCard.js CHANGED
@@ -1,63 +1,28 @@
1
- import normalizeString from './normalizeString';
1
+ import normalizeString from './normalizeString.js';
2
2
 
3
- // 非0开头,10~21位数字
4
3
  var reg = /^[1-9]\d{9,20}$/;
5
-
6
- // 8~30位数字
7
4
  var regLoose = /^\d{8,30}$/;
8
-
9
- /**
10
- * luhn 计算校验位
11
- * @private
12
- * @param {string} numStr 银行卡前面数字
13
- * @returns {number}
14
- */
15
5
  function sumCheckCode(numStr) {
16
- var numArr = (numStr + '').replace(/\D/g, '').split('').reverse();
17
- var sum = 0;
18
- for (var i = 0; i < numArr.length; i++) {
19
- var currNum = parseInt(numArr[i]);
20
- sum += i % 2 === 0 ? currNum * 2 - (currNum > 4 ? 9 : 0) : currNum;
21
- }
22
- var mod = sum % 10;
23
- return mod !== 0 ? 10 - mod : 0;
6
+ var numArr = (numStr + '').replace(/\D/g, '').split('').reverse();
7
+ var sum = 0;
8
+ for (var i = 0; i < numArr.length; i++) {
9
+ var currNum = parseInt(numArr[i]);
10
+ sum += i % 2 === 0 ? currNum * 2 - (currNum > 4 ? 9 : 0) : currNum;
11
+ }
12
+ var mod = sum % 10;
13
+ return mod !== 0 ? 10 - mod : 0;
24
14
  }
25
-
26
- /**
27
- * 检测值是否为银行卡号。正常模式(非0开头,10~21位数字)宽松模式(8~30位数字)
28
- *
29
- * @static
30
- * @alias module:Validator.isBankCard
31
- * @since 1.1.0
32
- * @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html|常用银行账号位数参考}
33
- * @param {*} value 要检测的值
34
- * @param {Object} [options] 配置项
35
- * @param {boolean} [options.loose=false] 宽松模式,8~30位数字
36
- * @param {boolean} [options.luhn=false] 使用 Luhn 算法校验校验码
37
- * @returns {boolean} 值是否为银行卡号
38
- * @example
39
- *
40
- * isBankCard('6228480402564890018'); // true
41
- * isBankCard('6228480402564890'); // true
42
- * isBankCard('123456789'); // false
43
- *
44
- * // 宽松模式
45
- * isBankCard('123456789', { loose: true }); // true
46
- *
47
- */
48
- function isBankCard(value) {
49
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
50
- var _options$loose = options.loose,
51
- loose = _options$loose === void 0 ? false : _options$loose,
52
- _options$luhn = options.luhn,
53
- luhn = _options$luhn === void 0 ? false : _options$luhn;
54
- var valueStr = normalizeString(value);
55
- var validateResult = loose ? regLoose.test(valueStr) : reg.test(valueStr);
56
- if (validateResult && luhn) {
57
- var precode = valueStr.substring(0, valueStr.length - 1);
58
- var checkCode = valueStr[valueStr.length - 1];
59
- return checkCode === String(sumCheckCode(precode));
60
- }
61
- return validateResult;
15
+ function isBankCard(value, options) {
16
+ if (options === void 0) { options = {}; }
17
+ var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.luhn, luhn = _b === void 0 ? false : _b;
18
+ var valueStr = normalizeString(value);
19
+ var validateResult = loose ? regLoose.test(valueStr) : reg.test(valueStr);
20
+ if (validateResult && luhn) {
21
+ var precode = valueStr.substring(0, valueStr.length - 1);
22
+ var checkCode = valueStr[valueStr.length - 1];
23
+ return checkCode === String(sumCheckCode(precode));
24
+ }
25
+ return validateResult;
62
26
  }
63
- export default isBankCard;
27
+
28
+ export { isBankCard as default };
@@ -1,83 +1,37 @@
1
- import normalizeString from './normalizeString';
1
+ import normalizeString from './normalizeString.js';
2
2
 
3
- // 基础规则,由14位数字本体码和1位数字校验码组成,其中本体码从左至右依次为:6位首次登记机关码、8位顺序码。
4
3
  var baseReg = /^\d{15}$/;
5
-
6
- /**
7
- * 计算校验码
8
- *
9
- * @private
10
- * @since 3.5.0
11
- * @param {string} preCode 营业执照前14位
12
- * @returns {number} 校验码
13
- */
14
4
  function sumCheckCode(preCode) {
15
- var retNum; // 校验位数字
16
-
17
- var pj = 10; // Pj+1 11,初始为10
18
-
19
- for (var j = 0; j < 14; j++) {
20
- var sj = pj + Number(preCode[j]);
21
- var sj10 = sj % 10;
22
- sj10 = sj10 === 0 ? 10 : sj10;
23
- var pj1 = sj10 * 2;
24
- pj = pj1 % 11;
25
- }
26
-
27
- // 反模10计算
28
- if (pj === 1) {
29
- retNum = 0;
30
- } else {
31
- retNum = 11 - pj;
32
- }
33
- return retNum;
5
+ var retNum;
6
+ var pj = 10;
7
+ for (var j = 0; j < 14; j++) {
8
+ var sj = pj + Number(preCode[j]);
9
+ var sj10 = sj % 10;
10
+ sj10 = sj10 === 0 ? 10 : sj10;
11
+ var pj1 = sj10 * 2;
12
+ pj = pj1 % 11;
13
+ }
14
+ if (pj === 1) {
15
+ retNum = 0;
16
+ }
17
+ else {
18
+ retNum = 11 - pj;
19
+ }
20
+ return retNum;
34
21
  }
35
-
36
- /**
37
- * 检测值是否为营业执照号,也叫工商注册号。由14位数字本体码和1位数字校验码组成,其中本体码从左至右依次为:6位首次登记机关码、8位顺序码。
38
- *
39
- * @static
40
- * @alias module:Validator.isBusinessLicense
41
- * @since 3.5.0
42
- * @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html|GS15—2006 工商行政管理市场主体注册号编制规则}
43
- * @param {*} value 要检测的值
44
- * @param {Object} [options] 配置项
45
- * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
46
- * @returns {boolean} 值是否为营业执照号
47
- * @example
48
- *
49
- * isBusinessLicense('310115600985533'); // true
50
- * isBusinessLicense('310115600985535'); // false
51
- *
52
- * // 不校验验证码,长度和类型还是有校验
53
- * isBusinessLicense('310115600985535', { checkCode: false }); // true
54
- * isBusinessLicense('ac115600985535', { checkCode: false }); // false
55
- * isBusinessLicense('31011560098', { checkCode: false }); // false
56
- *
57
- */
58
- function isBusinessLicense(value) {
59
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
60
- var valueStr = normalizeString(value);
61
- // @ts-ignore
62
- // TODO 下个版本废弃 loose
63
- var _options$loose = options.loose,
64
- loose = _options$loose === void 0 ? false : _options$loose,
65
- _options$checkCode = options.checkCode,
66
- cc = _options$checkCode === void 0 ? true : _options$checkCode;
67
- var needCheckCode = !loose && cc;
68
- var passBaseRule = baseReg.test(valueStr);
69
-
70
- // 宽松模式 或 基础规则不通过直接返回
71
- if (!needCheckCode || !passBaseRule) {
72
- return passBaseRule;
73
- }
74
-
75
- // 前14位
76
- var preCode = valueStr.substring(0, 14);
77
- // 校验码
78
- var lastCode = valueStr.substring(valueStr.length - 1);
79
- // 计算校验码
80
- var checkCode = sumCheckCode(preCode);
81
- return lastCode === String(checkCode);
22
+ function isBusinessLicense(value, options) {
23
+ if (options === void 0) { options = {}; }
24
+ var valueStr = normalizeString(value);
25
+ var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.checkCode, cc = _b === void 0 ? true : _b;
26
+ var needCheckCode = !loose && cc;
27
+ var passBaseRule = baseReg.test(valueStr);
28
+ if (!needCheckCode || !passBaseRule) {
29
+ return passBaseRule;
30
+ }
31
+ var preCode = valueStr.substring(0, 14);
32
+ var lastCode = valueStr.substring(valueStr.length - 1);
33
+ var checkCode = sumCheckCode(preCode);
34
+ return lastCode === String(checkCode);
82
35
  }
83
- export default isBusinessLicense;
36
+
37
+ export { isBusinessLicense as default };
package/esm/isChinese.js CHANGED
@@ -1,75 +1,32 @@
1
- import normalizeString from './normalizeString';
1
+ import normalizeString from './normalizeString.js';
2
+
2
3
  var chineseDictionary = {
3
- // 基本汉字
4
- chineseBasic: "[\u4E00-\u9FA5]",
5
- // 基本汉字补充
6
- chineseExtend: "[\u9EA6-\u9FEF]",
7
- // 汉字扩展A
8
- chineseExtendA: "[\u3400-\u4DB5]",
9
- // 汉字扩展B
10
- chineseExtendB: "[\uD840\uDC00-\uD869\uDED6]",
11
- // 汉字扩展C
12
- chineseExtendC: "[\uD869\uDF00-\uD86D\uDF34]",
13
- // 汉字扩展D
14
- chineseExtendD: "[\uD86D\uDF40-\uD86E\uDC1D]",
15
- // 汉字扩展E
16
- chineseExtendE: "[\uD86E\uDC20-\uD873\uDEA1]",
17
- // 汉字扩展F
18
- chineseExtendF: "[\uD873\uDEB0-\uD87A\uDFE0]"
4
+ chineseBasic: '[\u4e00-\u9fa5]',
5
+ chineseExtend: '[\u9ea6-\u9fef]',
6
+ chineseExtendA: '[\u3400-\u4DB5]',
7
+ chineseExtendB: "[\uD840\uDC00-\uD869\uDED6]",
8
+ chineseExtendC: "[\uD869\uDF00-\uD86D\uDF34]",
9
+ chineseExtendD: "[\uD86D\uDF40-\uD86E\uDC1D]",
10
+ chineseExtendE: "[\uD86E\uDC20-\uD873\uDEA1]",
11
+ chineseExtendF: "[\uD873\uDEB0-\uD87A\uDFE0]"
19
12
  };
20
13
  var looseChineseRegExp = chineseDictionary.chineseBasic + '+';
21
14
  var chineseRegExp = '^' + chineseDictionary.chineseBasic + '+$';
22
15
  var chineseWithExtend = '(?:' + chineseDictionary.chineseBasic + '|' + chineseDictionary.chineseExtend + '|' + chineseDictionary.chineseExtendA + '|' + chineseDictionary.chineseExtendB + '|' + chineseDictionary.chineseExtendC + '|' + chineseDictionary.chineseExtendD + '|' + chineseDictionary.chineseExtendE + '|' + chineseDictionary.chineseExtendF + ')';
23
16
  var looseChineseExtendRegExp = chineseWithExtend + '+';
24
17
  var chineseExtendRegExp = '^' + chineseWithExtend + '+$';
25
-
26
- // eslint-disable-next-line no-prototype-builtins
27
18
  var supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');
28
-
29
- /**
30
- * 检测值是否为中文
31
- *
32
- * @static
33
- * @alias module:Validator.isChinese
34
- * @since 1.1.0
35
- * @see {@link http://www.unicode.org/reports/tr38/#BlockListing|4.4 Listing of Characters Covered by the Unihan Database}
36
- * @see {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射|Unicode字符平面映射}
37
- * @see {@link https://zh.wikipedia.org/wiki/Unicode區段|Unicode区段}
38
- * @param {*} value 要检测的值
39
- * @param {Object} [options] 配置项
40
- * @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
41
- * @param {boolean} [options.useExtend=false] 使用统一表意文字扩展A-F。注意:如果不支持 `RegExp.prototype.unicode`,扩展字符集将自动不生效,如IE浏览器。
42
- * @returns {boolean} 值是否为中文
43
- * @example
44
- *
45
- * isChinese('林某某'); // true
46
- * isChinese('林A'); // false
47
- *
48
- * // 宽松模式,只要包含中文即为true
49
- * isChinese('林A', { loose: true }); // true
50
- * isChinese('A林A', { loose: true }); // true
51
- *
52
- * // 扩展字符集的字符
53
- * isChinese('𠮷'); // false
54
- *
55
- * // 使用中文扩展字符集,需要浏览器支持 RegExp.prototype.unicode 才生效。
56
- * isChinese('𠮷', { useExtend: true }); // true
57
- * isChinese('𠮷aa', { useExtend: true, loose: true }); // true
58
- *
59
- */
60
- function isChinese(value) {
61
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
62
- var _options$loose = options.loose,
63
- loose = _options$loose === void 0 ? false : _options$loose,
64
- _options$useExtend = options.useExtend,
65
- useExtend = _options$useExtend === void 0 ? false : _options$useExtend;
66
- var valueStr = normalizeString(value);
67
- var basicRegExp = loose ? looseChineseRegExp : chineseRegExp;
68
- var extendRegExp = loose ? looseChineseExtendRegExp : chineseExtendRegExp;
69
- var hasExtend = useExtend && supportRegExpUnicode;
70
- var resultRegExp = hasExtend ? extendRegExp : basicRegExp;
71
- var flag = hasExtend ? 'u' : undefined;
72
- var reg = new RegExp(resultRegExp, flag);
73
- return reg.test(valueStr);
19
+ function isChinese(value, options) {
20
+ if (options === void 0) { options = {}; }
21
+ var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.useExtend, useExtend = _b === void 0 ? false : _b;
22
+ var valueStr = normalizeString(value);
23
+ var basicRegExp = loose ? looseChineseRegExp : chineseRegExp;
24
+ var extendRegExp = loose ? looseChineseExtendRegExp : chineseExtendRegExp;
25
+ var hasExtend = useExtend && supportRegExpUnicode;
26
+ var resultRegExp = hasExtend ? extendRegExp : basicRegExp;
27
+ var flag = hasExtend ? 'u' : undefined;
28
+ var reg = new RegExp(resultRegExp, flag);
29
+ return reg.test(valueStr);
74
30
  }
75
- export default isChinese;
31
+
32
+ export { isChinese as default };
package/esm/isEmail.js CHANGED
@@ -1,24 +1,9 @@
1
- import normalizeString from './normalizeString';
1
+ import normalizeString from './normalizeString.js';
2
2
 
3
- // 邮箱
4
- var reg = /^[\da-z]+([\-\.\_]?[\da-z]+)*@[\da-z]+([\-\.]?[\da-z]+)*(\.[a-z]{2,})+$/i;
5
-
6
- /**
7
- * 检测值是否为Email
8
- *
9
- * @static
10
- * @alias module:Validator.isEmail
11
- * @since 1.1.0
12
- * @param {*} value 要检测的值
13
- * @returns {boolean} 值是否为Email
14
- * @example
15
- *
16
- * isEmail('1232@qq.com'); // true
17
- * isEmail('123@'); // false
18
- *
19
- */
3
+ var reg = /^[\da-z]+([-._]?[\da-z]+)*@[\da-z]+([-.]?[\da-z]+)*(\.[a-z]{2,})+$/i;
20
4
  function isEmail(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 isEmail;
8
+
9
+ export { isEmail as default };
package/esm/isHMCard.js CHANGED
@@ -1,32 +1,9 @@
1
- import normalizeString from './normalizeString';
1
+ import normalizeString from './normalizeString.js';
2
2
 
3
- // 港澳居民来往内地通行证正则
4
3
  var regHMCard = /^[hm]{1}([0-9]{10}|[0-9]{8})$/i;
5
-
6
- /**
7
- * 检测值是否为港澳居民来往内地通行证,俗称回乡证或回乡卡。
8
- *
9
- * @static
10
- * @alias module:Validator.isHMCard
11
- * @since 4.0.0
12
- * @see {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证|港澳居民来往内地通行证}
13
- * @param {*} value 要检测的值
14
- * @returns {boolean} 是否为港澳居民来往内地通行证
15
- * @example
16
- * // 第一代 11 位
17
- * isHMCard('h3203117707'); // true
18
- * isHMCard('H3203117707'); // true
19
- * isHMCard('m3203117707'); // true
20
- * isHMCard('M3203117707'); // true
21
- *
22
- * // 第二代 9 位
23
- * isHMCard('h32031177'); // true
24
- * isHMCard('H32031177'); // true
25
- * isHMCard('m32031177'); // true
26
- * isHMCard('M32031177'); // true
27
- */
28
4
  function isHMCard(value) {
29
- var valueStr = normalizeString(value);
30
- return regHMCard.test(valueStr);
5
+ var valueStr = normalizeString(value);
6
+ return regHMCard.test(valueStr);
31
7
  }
32
- export default isHMCard;
8
+
9
+ export { isHMCard as default };
package/esm/isIPv4.js CHANGED
@@ -1,26 +1,9 @@
1
- import normalizeString from './normalizeString';
1
+ import normalizeString from './normalizeString.js';
2
2
 
3
- // ipv4正则
4
3
  var reg = /^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
5
-
6
- /**
7
- * 检测值是否为ipv4
8
- *
9
- * @static
10
- * @alias module:Validator.isIPv4
11
- * @since 1.1.0
12
- * @param {*} value 要检测的值
13
- * @returns {boolean} 值是否为ipv4
14
- * @example
15
- *
16
- * isIPv4('192.168.1.1'); // true
17
- * isIPv4('255.255.255.255'); // true
18
- * isIPv4('256.256.256.256'); // false
19
- * isIPv4('0.0'); // false
20
- *
21
- */
22
4
  function isIPv4(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 isIPv4;
8
+
9
+ export { isIPv4 as default };
package/esm/isIPv6.js CHANGED
@@ -1,40 +1,9 @@
1
- import normalizeString from './normalizeString';
1
+ import normalizeString from './normalizeString.js';
2
2
 
3
- // ipv6正则
4
3
  var reg = /^((([0-9A-F]{1,4}:){7}([0-9A-F]{1,4}|:))|(([0-9A-F]{1,4}:){6}(:[0-9A-F]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3})|:))|(([0-9A-F]{1,4}:){5}(((:[0-9A-F]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3})|:))|(([0-9A-F]{1,4}:){4}(((:[0-9A-F]{1,4}){1,3})|((:[0-9A-F]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){3}(((:[0-9A-F]{1,4}){1,4})|((:[0-9A-F]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){2}(((:[0-9A-F]{1,4}){1,5})|((:[0-9A-F]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){1}(((:[0-9A-F]{1,4}){1,6})|((:[0-9A-F]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(:(((:[0-9A-F]{1,4}){1,7})|((:[0-9A-F]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:)))(%.+)?$/i;
5
-
6
- /**
7
- * 检测值是否为ipv6
8
- *
9
- * @static
10
- * @alias module:Validator.isIPv6
11
- * @since 1.1.0
12
- * @param {*} value 要检测的值
13
- * @returns {boolean} 值是否为ipv6
14
- * @example
15
- *
16
- * // 冒分十六进制表示法
17
- * isIPv6('2001:0DB8:0000:0023:0008:0800:200C:417A'); // true
18
- *
19
- * // 前导0省略
20
- * isIPv6('2001:DB8:0:23:8:800:200C:417A'); // true
21
- * isIPv6('FF01:0:0:0:0:0:0:1101'); // true
22
- *
23
- * // 0位压缩表示法
24
- * isIPv6('FF01::1101'); // true
25
- * isIPv6('::1'); // true
26
- * isIPv6('::'); // true
27
- * isIPv6('0:0:0:0:0:0:0:1'); // true
28
- * isIPv6('0:0:0:0:0:0:0:0'); // true
29
- *
30
- * // 内嵌IPv4地址表示法
31
- * isIPv6('::192.168.1.1'); // true
32
- * isIPv6('::FFFF:192.168.1.1'); // true
33
- * isIPv6('192.168.1.1'); // false
34
- *
35
- */
36
4
  function isIPv6(value) {
37
- var valueStr = normalizeString(value);
38
- return reg.test(valueStr);
5
+ var valueStr = normalizeString(value);
6
+ return reg.test(valueStr);
39
7
  }
40
- export default isIPv6;
8
+
9
+ export { isIPv6 as default };