util-helpers 4.12.4 → 4.12.7

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 (132) hide show
  1. package/README.md +9 -5
  2. package/dist/util-helpers.js +225 -363
  3. package/dist/util-helpers.js.map +1 -1
  4. package/dist/util-helpers.min.js +1 -1
  5. package/dist/util-helpers.min.js.map +1 -1
  6. package/esm/bytesToSize.js +5 -11
  7. package/esm/calculateCursorPosition.js +1 -1
  8. package/esm/dataURLToBlob.js +1 -1
  9. package/esm/divide.js +1 -0
  10. package/esm/formatBankCard.js +4 -8
  11. package/esm/formatMobile.js +9 -7
  12. package/esm/formatMoney.js +8 -14
  13. package/esm/isBankCard.js +6 -11
  14. package/esm/isBusinessLicense.js +7 -10
  15. package/esm/isChinese.js +10 -17
  16. package/esm/isEmail.js +2 -5
  17. package/esm/isHMCard.js +8 -8
  18. package/esm/isIPv4.js +4 -11
  19. package/esm/isIPv6.js +11 -29
  20. package/esm/isIdCard.js +9 -12
  21. package/esm/isMobile.js +2 -5
  22. package/esm/isPassport.js +2 -5
  23. package/esm/isPassword.js +14 -21
  24. package/esm/isPostcode.js +2 -5
  25. package/esm/isPromiseLike.js +4 -8
  26. package/esm/isQQ.js +2 -5
  27. package/esm/isSocialCreditCode.js +6 -11
  28. package/esm/isSwiftCode.js +5 -5
  29. package/esm/isTWCard.js +7 -4
  30. package/esm/isTelephone.js +7 -10
  31. package/esm/isUrl.js +8 -20
  32. package/esm/isVehicle.js +9 -14
  33. package/esm/isWX.js +2 -5
  34. package/esm/minus.js +4 -8
  35. package/esm/normalizeString.js +2 -0
  36. package/esm/numberToChinese.js +13 -19
  37. package/esm/padZero.js +9 -8
  38. package/esm/parseIdCard.js +8 -17
  39. package/esm/plus.js +4 -8
  40. package/esm/randomString.js +2 -0
  41. package/esm/replaceChar.js +9 -17
  42. package/esm/round.js +4 -8
  43. package/esm/safeDate.js +2 -0
  44. package/esm/setDataURLPrefix.js +2 -0
  45. package/esm/times.js +4 -8
  46. package/esm/utils/config.js +1 -1
  47. package/esm/utils/math.util.js +4 -9
  48. package/esm/waitTime.js +3 -1
  49. package/lib/bytesToSize.js +5 -11
  50. package/lib/calculateCursorPosition.js +1 -1
  51. package/lib/dataURLToBlob.js +1 -1
  52. package/lib/divide.js +1 -0
  53. package/lib/formatBankCard.js +4 -8
  54. package/lib/formatMobile.js +9 -7
  55. package/lib/formatMoney.js +8 -14
  56. package/lib/isBankCard.js +6 -11
  57. package/lib/isBusinessLicense.js +7 -10
  58. package/lib/isChinese.js +10 -17
  59. package/lib/isEmail.js +2 -5
  60. package/lib/isHMCard.js +8 -8
  61. package/lib/isIPv4.js +4 -11
  62. package/lib/isIPv6.js +11 -29
  63. package/lib/isIdCard.js +9 -12
  64. package/lib/isMobile.js +2 -5
  65. package/lib/isPassport.js +2 -5
  66. package/lib/isPassword.js +14 -21
  67. package/lib/isPostcode.js +2 -5
  68. package/lib/isPromiseLike.js +4 -8
  69. package/lib/isQQ.js +2 -5
  70. package/lib/isSocialCreditCode.js +6 -11
  71. package/lib/isSwiftCode.js +5 -5
  72. package/lib/isTWCard.js +7 -4
  73. package/lib/isTelephone.js +7 -10
  74. package/lib/isUrl.js +8 -20
  75. package/lib/isVehicle.js +9 -14
  76. package/lib/isWX.js +2 -5
  77. package/lib/minus.js +4 -8
  78. package/lib/normalizeString.js +2 -0
  79. package/lib/numberToChinese.js +13 -19
  80. package/lib/padZero.js +9 -8
  81. package/lib/parseIdCard.js +8 -19
  82. package/lib/plus.js +4 -8
  83. package/lib/randomString.js +2 -0
  84. package/lib/replaceChar.js +9 -17
  85. package/lib/round.js +4 -8
  86. package/lib/safeDate.js +2 -0
  87. package/lib/setDataURLPrefix.js +2 -0
  88. package/lib/times.js +4 -8
  89. package/lib/utils/config.js +1 -1
  90. package/lib/utils/math.util.js +4 -9
  91. package/lib/waitTime.js +3 -1
  92. package/package.json +1 -1
  93. package/types/src/bytesToSize.d.ts +4 -10
  94. package/types/src/dataURLToBlob.d.ts +1 -1
  95. package/types/src/divide.d.ts +1 -0
  96. package/types/src/formatBankCard.d.ts +4 -8
  97. package/types/src/formatMobile.d.ts +9 -7
  98. package/types/src/formatMoney.d.ts +8 -14
  99. package/types/src/isBankCard.d.ts +5 -10
  100. package/types/src/isBusinessLicense.d.ts +6 -9
  101. package/types/src/isChinese.d.ts +9 -16
  102. package/types/src/isEmail.d.ts +2 -5
  103. package/types/src/isHMCard.d.ts +8 -8
  104. package/types/src/isIPv4.d.ts +4 -11
  105. package/types/src/isIPv6.d.ts +11 -29
  106. package/types/src/isIdCard.d.ts +8 -11
  107. package/types/src/isMobile.d.ts +2 -5
  108. package/types/src/isPassport.d.ts +2 -5
  109. package/types/src/isPassword.d.ts +10 -17
  110. package/types/src/isPostcode.d.ts +2 -5
  111. package/types/src/isPromiseLike.d.ts +3 -7
  112. package/types/src/isQQ.d.ts +2 -5
  113. package/types/src/isSocialCreditCode.d.ts +6 -11
  114. package/types/src/isSwiftCode.d.ts +5 -5
  115. package/types/src/isTWCard.d.ts +7 -4
  116. package/types/src/isTelephone.d.ts +6 -9
  117. package/types/src/isUrl.d.ts +7 -19
  118. package/types/src/isVehicle.d.ts +8 -13
  119. package/types/src/isWX.d.ts +2 -5
  120. package/types/src/minus.d.ts +3 -7
  121. package/types/src/normalizeString.d.ts +2 -0
  122. package/types/src/numberToChinese.d.ts +10 -18
  123. package/types/src/padZero.d.ts +9 -8
  124. package/types/src/parseIdCard.d.ts +3 -3
  125. package/types/src/plus.d.ts +3 -7
  126. package/types/src/randomString.d.ts +2 -0
  127. package/types/src/replaceChar.d.ts +9 -17
  128. package/types/src/round.d.ts +3 -7
  129. package/types/src/safeDate.d.ts +2 -0
  130. package/types/src/setDataURLPrefix.d.ts +2 -0
  131. package/types/src/times.d.ts +3 -7
  132. package/types/src/waitTime.d.ts +3 -1
@@ -118,6 +118,7 @@
118
118
  * @param {*} value 待处理的值
119
119
  * @returns {string} 规整化的值
120
120
  * @example
121
+ *
121
122
  * normalizeString(); // ''
122
123
  * normalizeString(undefined); // ''
123
124
  * normalizeString(void 0); // ''
@@ -127,6 +128,7 @@
127
128
  * normalizeString(NaN); // 'NaN'
128
129
  * normalizeString(1); // '1'
129
130
  * normalizeString('a'); // 'a'
131
+ *
130
132
  */
131
133
 
132
134
  function normalizeString(value) {
@@ -148,11 +150,8 @@
148
150
  * @returns {boolean} 值是否为手机号码
149
151
  * @example
150
152
  *
151
- * isMobile('13000000000');
152
- * // => true
153
- *
154
- * isMobile('13000');
155
- * // => false
153
+ * isMobile('13000000000'); // true
154
+ * isMobile('13000'); // false
156
155
  *
157
156
  */
158
157
 
@@ -172,17 +171,14 @@
172
171
  * @returns {boolean} 值是否为固定电话
173
172
  * @example
174
173
  *
175
- * isTelephone('22033212');
176
- * // => true
177
- *
178
- * isTelephone('021-22033212');
179
- * // => true
180
- *
181
- * isTelephone('021-22033212-123');
182
- * // => true
174
+ * isTelephone('22033212'); // true
175
+ * isTelephone('13000000000'); // false
176
+ *
177
+ * // 含区号
178
+ * isTelephone('021-22033212'); // true
183
179
  *
184
- * isTelephone('13000000000');
185
- * // => false
180
+ * // 含区号和分机号
181
+ * isTelephone('021-22033212-123'); // true
186
182
  *
187
183
  */
188
184
 
@@ -202,11 +198,8 @@
202
198
  * @returns {boolean} 值是否为邮政编码
203
199
  * @example
204
200
  *
205
- * isPostcode('101111');
206
- * // => true
207
- *
208
- * isPostcode('123');
209
- * // => false
201
+ * isPostcode('101111'); // true
202
+ * isPostcode('123'); // false
210
203
  *
211
204
  */
212
205
 
@@ -254,20 +247,17 @@
254
247
  * @returns {boolean} 值是否为身份证号
255
248
  * @example
256
249
  *
257
- * isIdCard('130701199310302288');
258
- * // => true
259
- *
260
- * isIdCard('13070119931030228X');
261
- * // => false
262
- *
263
- * isIdCard('13070119931030228X', { checkCode: false }); // 不校验校验码
264
- * // => true
250
+ * isIdCard('130701199310302288'); // true
251
+ * isIdCard('13070119931030228X'); // false
265
252
  *
266
- * isIdCard('320311770706001');
267
- * // => false
253
+ * // 不校验校验码
254
+ * isIdCard('13070119931030228X', { checkCode: false }); // true
268
255
  *
269
- * isIdCard('320311770706001', { loose: true });
270
- * // => true
256
+ * // 默认不支持15位身份证号码
257
+ * isIdCard('320311770706001'); // false
258
+ *
259
+ * // 宽松模式,支持15位身份证号
260
+ * isIdCard('320311770706001', { loose: true }); // true
271
261
  *
272
262
  */
273
263
 
@@ -307,11 +297,8 @@
307
297
  * @returns {boolean} 值是否为Email
308
298
  * @example
309
299
  *
310
- * isEmail('1232@qq.com');
311
- * // => true
312
- *
313
- * isEmail('123@');
314
- * // => false
300
+ * isEmail('1232@qq.com'); // true
301
+ * isEmail('123@'); // false
315
302
  *
316
303
  */
317
304
 
@@ -331,11 +318,8 @@
331
318
  * @returns {boolean} 值是否为QQ号
332
319
  * @example
333
320
  *
334
- * isQQ('12345');
335
- * // => true
336
- *
337
- * isQQ('123');
338
- * // => false
321
+ * isQQ('12345'); // true
322
+ * isQQ('123'); // false
339
323
  *
340
324
  */
341
325
 
@@ -355,11 +339,8 @@
355
339
  * @returns {boolean} 值是否为微信号
356
340
  * @example
357
341
  *
358
- * isWX('a12345');
359
- * // => true
360
- *
361
- * isWX('123');
362
- * // => false
342
+ * isWX('a12345'); // true
343
+ * isWX('123'); // false
363
344
  *
364
345
  */
365
346
 
@@ -380,20 +361,15 @@
380
361
  * @returns {boolean} 值是否为车牌号
381
362
  * @example
382
363
  *
383
- * isVehicle('京L12345');
384
- * // => true
385
- *
386
- * isVehicle('粤BD12345');
387
- * // => true
388
- *
389
- * isVehicle('粤BF12345');
390
- * // => true
391
- *
392
- * isVehicle('粤B12345D');
393
- * // => true
394
- *
395
- * isVehicle('粤B12345F');
396
- * // => true
364
+ * isVehicle('京L12345'); // true
365
+ * isVehicle('京L1234学'); // true
366
+ * isVehicle('BL1234警'); // true
367
+ *
368
+ * // 新能源车牌
369
+ * isVehicle('粤BD12345'); // true
370
+ * isVehicle('粤BF12345'); // true
371
+ * isVehicle('粤B12345D'); // true
372
+ * isVehicle('粤B12345F'); // true
397
373
  *
398
374
  */
399
375
 
@@ -438,17 +414,12 @@
438
414
  * @returns {boolean} 值是否为银行卡号
439
415
  * @example
440
416
  *
441
- * isBankCard('6228480402564890018');
442
- * // => true
443
- *
444
- * isBankCard('6228480402564890');
445
- * // => true
446
- *
447
- * isBankCard('123456789');
448
- * // => false
449
- *
450
- * isBankCard('123456789', { loose: true });
451
- * // => true
417
+ * isBankCard('6228480402564890018'); // true
418
+ * isBankCard('6228480402564890'); // true
419
+ * isBankCard('123456789'); // false
420
+ *
421
+ * // 宽松模式
422
+ * isBankCard('123456789', { loose: true }); // true
452
423
  *
453
424
  */
454
425
 
@@ -521,18 +492,13 @@
521
492
  * @returns {boolean} 值是否为统一社会信用代码
522
493
  * @example
523
494
  *
524
- * isSocialCreditCode('91350100M000100Y43');
525
- * // => true
526
- *
527
- * isSocialCreditCode('91350100M000100Y4A');
528
- * // => false
529
- *
530
- * // 不校验校验位
531
- * isSocialCreditCode('91350100M000100Y4A', { checkCode: false });
532
- * // => true
495
+ * isSocialCreditCode('91350100M000100Y43'); // true
496
+ * isSocialCreditCode('91350100M000100Y4A'); // false
533
497
  *
534
- * isSocialCreditCode('91350100M000100Y', { checkCode: false });
535
- * // => false
498
+ * // 不校验校验位,长度和类型还是有校验的
499
+ * isSocialCreditCode('91350100M000100Y4A', { checkCode: false }); // true
500
+ * isSocialCreditCode('91350100M000100YIO', { checkCode: false }); // false
501
+ * isSocialCreditCode('91350100M000100Y', { checkCode: false }); // false
536
502
  *
537
503
  */
538
504
 
@@ -562,7 +528,7 @@
562
528
  return lastCode === checkCode;
563
529
  }
564
530
 
565
- const version = "4.12.4";
531
+ const version = "4.12.7";
566
532
 
567
533
  var config = {
568
534
  // 禁用warning提示
@@ -896,27 +862,20 @@
896
862
  * @returns {boolean} 值是否符合密码强度
897
863
  * @example
898
864
  *
899
- * isPassword('a12345678');
900
- * // => true
901
- *
902
- * isPassword('a12345678', {level: 3});
903
- * // => false
904
- *
905
- * isPassword('Aa12345678', {level: 3});
906
- * // => true
907
- *
908
- * isPassword('Aa12345678', {level: 3, ignoreCase: true});
909
- * // => false
910
- *
911
- * isPassword('_Aa12345678', {level: 3, ignoreCase: true});
912
- * // => true
913
- *
914
- * // 仅支持 数字、字母、特殊字符,其他字符如中文字符是校验不通过的
915
- * isPassword('_Aa一二三45678', {level: 3, ignoreCase: true});
916
- * // => false
865
+ * isPassword('a12345678'); // true
866
+ *
867
+ * // 3级密码强度
868
+ * isPassword('a12345678', {level: 3}); // false
869
+ * isPassword('Aa12345678', {level: 3}); // true
870
+ *
871
+ * // 3级密码强度,大小写字符仅计算1级强度
872
+ * isPassword('Aa12345678', {level: 3, ignoreCase: true}); // false
873
+ * isPassword('_Aa12345678', {level: 3, ignoreCase: true}); // true
917
874
  *
918
- * isPassword(' _Aa12345678', {level: 3, ignoreCase: true});
919
- * // => false
875
+ * // 仅支持 数字、字母、特殊字符,其他非法字符如中文字符是校验不通过的
876
+ * isPassword('_Aa一二三45678', {level: 3, ignoreCase: true}); // false
877
+ * isPassword(' _Aa12345678', {level: 3, ignoreCase: true}); // false
878
+ *
920
879
  */
921
880
 
922
881
  function isPassword(value) {
@@ -948,11 +907,8 @@
948
907
  * @returns {boolean} 值是否为护照号
949
908
  * @example
950
909
  *
951
- * isPassport('E12345678');
952
- * // => true
953
- *
954
- * isPassport('abc');
955
- * // => false
910
+ * isPassport('E12345678'); // true
911
+ * isPassport('abc'); // false
956
912
  *
957
913
  */
958
914
 
@@ -1000,27 +956,20 @@
1000
956
  * @returns {boolean} 值是否为中文
1001
957
  * @example
1002
958
  *
1003
- * isChinese('林某某');
1004
- * // => true
1005
- *
1006
- * isChinese('林A');
1007
- * // => false
959
+ * isChinese('林某某'); // true
960
+ * isChinese('林A'); // false
1008
961
  *
1009
962
  * // 宽松模式,只要包含中文即为true
1010
- * isChinese('林A', { loose: true });
1011
- * // => true
1012
- *
1013
- * isChinese('A林A', { loose: true });
1014
- * // => true
1015
- *
1016
- * isChinese('𠮷');
1017
- * // => false
963
+ * isChinese('林A', { loose: true }); // true
964
+ * isChinese('A林A', { loose: true }); // true
1018
965
  *
966
+ * // 扩展字符集的字符
967
+ * isChinese('𠮷'); // false
968
+ *
1019
969
  * // 使用中文扩展字符集,需要浏览器支持 RegExp.prototype.unicode 才生效。
1020
- * isChinese('𠮷', { useExtend: true });
1021
- * // => true
1022
- * isChinese('𠮷aa', { useExtend: true, loose: true });
1023
- * // => true
970
+ * isChinese('𠮷', { useExtend: true }); // true
971
+ * isChinese('𠮷aa', { useExtend: true, loose: true }); // true
972
+ *
1024
973
  */
1025
974
 
1026
975
  function isChinese(value) {
@@ -1051,17 +1000,10 @@
1051
1000
  * @returns {boolean} 值是否为ipv4
1052
1001
  * @example
1053
1002
  *
1054
- * isIPv4('192.168.1.1');
1055
- * // => true
1056
- *
1057
- * isIPv4('255.255.255.255');
1058
- * // => true
1059
- *
1060
- * isIPv4('256.256.256.256');
1061
- * // => false
1062
- *
1063
- * isIPv4('0.0');
1064
- * // => false
1003
+ * isIPv4('192.168.1.1'); // true
1004
+ * isIPv4('255.255.255.255'); // true
1005
+ * isIPv4('256.256.256.256'); // false
1006
+ * isIPv4('0.0'); // false
1065
1007
  *
1066
1008
  */
1067
1009
 
@@ -1082,41 +1024,23 @@
1082
1024
  * @example
1083
1025
  *
1084
1026
  * // 冒分十六进制表示法
1085
- * isIPv6('2001:0DB8:0000:0023:0008:0800:200C:417A');
1086
- * // => true
1027
+ * isIPv6('2001:0DB8:0000:0023:0008:0800:200C:417A'); // true
1087
1028
  *
1088
1029
  * // 前导0省略
1089
- * isIPv6('2001:DB8:0:23:8:800:200C:417A');
1090
- * // => true
1091
- *
1092
- * isIPv6('FF01:0:0:0:0:0:0:1101');
1093
- * // => true
1030
+ * isIPv6('2001:DB8:0:23:8:800:200C:417A'); // true
1031
+ * isIPv6('FF01:0:0:0:0:0:0:1101'); // true
1094
1032
  *
1095
1033
  * // 0位压缩表示法
1096
- * isIPv6('FF01::1101');
1097
- * // => true
1098
- *
1099
- * isIPv6('::1');
1100
- * // => true
1101
- *
1102
- * isIPv6('::');
1103
- * // => true
1104
- *
1105
- * isIPv6('0:0:0:0:0:0:0:1');
1106
- * // => true
1107
- *
1108
- * isIPv6('0:0:0:0:0:0:0:0');
1109
- * // => true
1034
+ * isIPv6('FF01::1101'); // true
1035
+ * isIPv6('::1'); // true
1036
+ * isIPv6('::'); // true
1037
+ * isIPv6('0:0:0:0:0:0:0:1'); // true
1038
+ * isIPv6('0:0:0:0:0:0:0:0'); // true
1110
1039
  *
1111
1040
  * // 内嵌IPv4地址表示法
1112
- * isIPv6('::192.168.1.1');
1113
- * // => true
1114
- *
1115
- * isIPv6('::FFFF:192.168.1.1');
1116
- * // => true
1117
- *
1118
- * isIPv6('192.168.1.1');
1119
- * // => false
1041
+ * isIPv6('::192.168.1.1'); // true
1042
+ * isIPv6('::FFFF:192.168.1.1'); // true
1043
+ * isIPv6('192.168.1.1'); // false
1120
1044
  *
1121
1045
  */
1122
1046
 
@@ -1137,26 +1061,14 @@
1137
1061
  * @returns {boolean} 值是否为url
1138
1062
  * @example
1139
1063
  *
1140
- * isUrl('');
1141
- * // => false
1142
- *
1143
- * isUrl('8.8.8.8');
1144
- * // => false
1145
- *
1146
- * isUrl('example.com');
1147
- * // => true
1148
- *
1149
- * isUrl('http://example.com');
1150
- * // => true
1151
- *
1152
- * isUrl('https://example.com:8080');
1153
- * // => true
1154
- *
1155
- * isUrl('http://www.example.com/test/123');
1156
- * // => true
1157
- *
1158
- * isUrl('http://www.example.com/test/123?foo=bar');
1159
- * // => true
1064
+ * isUrl(''); // false
1065
+ * isUrl('8.8.8.8'); // false
1066
+ * isUrl('example.com'); // true
1067
+ * isUrl('http://example.com'); // true
1068
+ * isUrl('https://example.com:8080'); // true
1069
+ * isUrl('http://www.example.com/test/123'); // true
1070
+ * isUrl('http://www.example.com/test/123?foo=bar'); // true
1071
+ *
1160
1072
  */
1161
1073
 
1162
1074
  function isUrl(value) {
@@ -1209,17 +1121,14 @@
1209
1121
  * @returns {boolean} 值是否为营业执照号
1210
1122
  * @example
1211
1123
  *
1212
- * isBusinessLicense('310115600985533');
1213
- * // => true
1214
- *
1215
- * isBusinessLicense('310115600985535');
1216
- * // => false
1124
+ * isBusinessLicense('310115600985533'); // true
1125
+ * isBusinessLicense('310115600985535'); // false
1217
1126
  *
1218
- * isBusinessLicense('310115600985535', { checkCode: false });
1219
- * // => true
1220
- *
1221
- * isBusinessLicense('31011560098', { checkCode: false });
1222
- * // => false
1127
+ * // 不校验验证码,长度和类型还是有校验
1128
+ * isBusinessLicense('310115600985535', { checkCode: false }); // true
1129
+ * isBusinessLicense('ac115600985535', { checkCode: false }); // false
1130
+ * isBusinessLicense('31011560098', { checkCode: false }); // false
1131
+ *
1223
1132
  */
1224
1133
 
1225
1134
 
@@ -1466,14 +1375,10 @@
1466
1375
  * @returns {boolean} 是否类似Promise对象
1467
1376
  * @example
1468
1377
  *
1469
- * isPromiseLike([]);
1470
- * => false
1471
- *
1472
- * isPromiseLike({then:()=>{}});
1473
- * => true
1474
- *
1475
- * isPromiseLike(Promise.resolve());
1476
- * => true
1378
+ * isPromiseLike([]); // false
1379
+ * isPromiseLike({ then: () => { } }); // true
1380
+ * isPromiseLike(Promise.resolve()); // true
1381
+ *
1477
1382
  */
1478
1383
  function isPromiseLike(obj) {
1479
1384
  return obj !== null && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
@@ -1491,16 +1396,16 @@
1491
1396
  * @returns {boolean} 是否为港澳居民来往内地通行证
1492
1397
  * @example
1493
1398
  * // 第一代 11 位
1494
- * isHMCard('h3203117707') // true
1495
- * isHMCard('H3203117707') // true
1496
- * isHMCard('m3203117707') // true
1497
- * isHMCard('M3203117707') // true
1399
+ * isHMCard('h3203117707'); // true
1400
+ * isHMCard('H3203117707'); // true
1401
+ * isHMCard('m3203117707'); // true
1402
+ * isHMCard('M3203117707'); // true
1498
1403
  *
1499
1404
  * // 第二代 9 位
1500
- * isHMCard('h32031177') // true
1501
- * isHMCard('H32031177') // true
1502
- * isHMCard('m32031177') // true
1503
- * isHMCard('M32031177') // true
1405
+ * isHMCard('h32031177'); // true
1406
+ * isHMCard('H32031177'); // true
1407
+ * isHMCard('m32031177'); // true
1408
+ * isHMCard('M32031177'); // true
1504
1409
  */
1505
1410
 
1506
1411
  function isHMCard(value) {
@@ -1523,12 +1428,15 @@
1523
1428
  * @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
1524
1429
  * @returns {boolean} 是否为台湾居民来往大陆通行证
1525
1430
  * @example
1526
- * isTWCard('12345678') // true
1527
- * isTWCard('07257456') // true
1431
+ *
1432
+ * isTWCard('12345678'); // true
1433
+ * isTWCard('07257456'); // true
1528
1434
  *
1529
1435
  * // 一次性短期
1530
- * isTWCard('F290299977') // false
1531
- * isTWCard('F290299977', { loose: true }) // true
1436
+ * isTWCard('F290299977'); // false
1437
+ *
1438
+ * // 宽松模式,支持一次性短期通行证
1439
+ * isTWCard('F290299977', { loose: true }); // true
1532
1440
  */
1533
1441
 
1534
1442
  function isTWCard(value) {
@@ -1557,13 +1465,13 @@
1557
1465
  * @returns {boolean} 值是否为 Swift Code
1558
1466
  * @example
1559
1467
  *
1560
- * isSwiftCode('DEUTDEFF') // true
1561
- * isSwiftCode('deutdeff') // false
1468
+ * isSwiftCode('DEUTDEFF'); // true
1469
+ * isSwiftCode('deutdeff'); // false
1562
1470
  *
1563
- * isSwiftCode('BKTWTWTP010') // true
1564
- * isSwiftCode('010BKTWTWTP') // false
1471
+ * isSwiftCode('BKTWTWTP010'); // true
1472
+ * isSwiftCode('010BKTWTWTP'); // false
1565
1473
  *
1566
- * isSwiftCode('ICBKCNBJBJM') // true
1474
+ * isSwiftCode('ICBKCNBJBJM'); // true
1567
1475
  *
1568
1476
  */
1569
1477
 
@@ -1676,18 +1584,13 @@
1676
1584
  ret = Number.NaN;
1677
1585
  }
1678
1586
  } else if (isSymbol(value)) {
1679
- ret = Number.NaN;
1680
- } else if (!isNumber(value)) {
1681
- // 其余非数字类型通过 Number 转换
1682
1587
  // 例如 Symbol 包装器对象将会报错
1683
1588
  // symObj = Object(Symbol());
1684
1589
  // Number(symObj); // TypeError: Cannot convert a Symbol value to a number
1685
- try {
1686
- ret = Number(value);
1687
- } catch (err) {
1688
- ret = Number.NaN;
1689
- console.error(err);
1690
- }
1590
+ ret = Number.NaN;
1591
+ } else if (!isNumber(value)) {
1592
+ // 其余非数字类型通过 Number 转换
1593
+ ret = Number(value);
1691
1594
  } else {
1692
1595
  ret = value;
1693
1596
  }
@@ -1943,32 +1846,26 @@
1943
1846
  * @example
1944
1847
  *
1945
1848
  * // 整数
1946
- * formatMoney('1000');
1947
- * // => 1,000.00
1849
+ * formatMoney('1000'); // 1,000.00
1948
1850
  *
1949
1851
  * // 小数(默认保留2位小数)
1950
- * formatMoney('3000.03');
1951
- * // => 3,000.03
1852
+ * formatMoney('3000.03'); // 3,000.03
1952
1853
  *
1953
1854
  * // 保留4位小数
1954
- * formatMoney('3000.0300', { precision: 4 });
1955
- * // => 3,000.0300
1855
+ * formatMoney('3000.0300', { precision: 4 }); // 3,000.0300
1956
1856
  *
1957
1857
  * // 保留10位小数
1958
- * formatMoney('1500.2', { precision: 10 });
1959
- * // => 1,500.2000000000
1858
+ * formatMoney('1500.2', { precision: 10 }); // 1,500.2000000000
1960
1859
  *
1961
1860
  * // 自定义单位符号
1962
- * formatMoney(1000.00, { symbol: '$' });
1963
- * // => $1,000.00
1861
+ * formatMoney(1000.00, { symbol: '$' }); // $1,000.00
1964
1862
  *
1965
1863
  * // 自定义千位分割符(默认',')
1966
- * formatMoney(1000.00, { thousand: '|' });
1967
- * // => 1|000.00
1864
+ * formatMoney(1000.00, { thousand: '|' }); // 1|000.00
1968
1865
  *
1969
1866
  * // 自定义小数位分割符(默认'.')
1970
- * formatMoney(1000.00, { decimal: '&' });
1971
- * // => 1,000&00
1867
+ * formatMoney(1000.00, { decimal: '&' }); // 1,000&00
1868
+ *
1972
1869
  */
1973
1870
 
1974
1871
 
@@ -2023,20 +1920,16 @@
2023
1920
  * @example
2024
1921
  *
2025
1922
  * // 19位银行卡
2026
- * formatBankCard('6228480402564890018');
2027
- * // => 6228 4804 0256 4890 018
1923
+ * formatBankCard('6228480402564890018'); // 6228 4804 0256 4890 018
2028
1924
  *
2029
1925
  * // 16位银行卡
2030
- * formatBankCard('6228480402564890');
2031
- * // => 6228 4804 0256 4890
1926
+ * formatBankCard('6228480402564890'); // 6228 4804 0256 4890
2032
1927
  *
2033
1928
  * // 脱敏银行卡
2034
- * formatBankCard('6228********890');
2035
- * // => 6228 **** **** 890
1929
+ * formatBankCard('6228********890'); // 6228 **** **** 890
2036
1930
  *
2037
1931
  * // 16位银行卡,"-"间隔
2038
- * formatBankCard('6228480402564890', {char: '-'});
2039
- * // => 6228-4804-0256-4890
1932
+ * formatBankCard('6228480402564890', {char: '-'}); // 6228-4804-0256-4890
2040
1933
  *
2041
1934
  */
2042
1935
 
@@ -2073,33 +1966,25 @@
2073
1966
  * @example
2074
1967
  *
2075
1968
  * // 手机号
2076
- * replaceChar('13000000000');
2077
- * // => 130****0000
1969
+ * replaceChar('13000000000'); // 130****0000
2078
1970
  *
2079
1971
  * // 身份证
2080
- * replaceChar('130701199310302288');
2081
- * // => 130***********2288
1972
+ * replaceChar('130701199310302288'); // 130***********2288
2082
1973
  *
2083
1974
  * // 邮箱
2084
1975
  * const email = '12345@qq.com'
2085
- * replaceChar(email, {start: 2, end: email.indexOf('@'), repeat: 4});
2086
- * // => 12****@qq.com
1976
+ * replaceChar(email, {start: 2, end: email.indexOf('@'), repeat: 4}); // 12****@qq.com
2087
1977
  *
2088
1978
  * // 银行卡号
2089
- * replaceChar('6228480402564890018', {start: 0, end: -4, repeat: 4});
2090
- * // => ****0018
1979
+ * replaceChar('6228480402564890018', {start: 0, end: -4, repeat: 4}); // ****0018
2091
1980
  *
2092
- * // 带格式的银行卡号
2093
- * replaceChar('6228 4804 0256 4890 018', {start: 4, end: -4, exclude: ' '});
2094
- * // => 6228 **** **** **** 018
1981
+ * // 带格式的银行卡号,忽略空字符串
1982
+ * replaceChar('6228 4804 0256 4890 018', {start: 4, end: -4, exclude: ' '}); // 6228 **** **** **** 018
2095
1983
  *
2096
1984
  * // 用户名
2097
- * replaceChar('林某某', {start: 1, end: Infinity, repeat: 2});
2098
- * // => 林**
2099
- * replaceChar('林某', {start: 1, end: Infinity, repeat: 2});
2100
- * // => 林**
2101
- * replaceChar('林某某某', {start: 1, end: Infinity, repeat: 2});
2102
- * // => 林**
1985
+ * replaceChar('林某某', {start: 1, end: Infinity, repeat: 2}); // 林**
1986
+ * replaceChar('林某', {start: 1, end: Infinity, repeat: 2}); // 林**
1987
+ * replaceChar('林某某某', {start: 1, end: Infinity, repeat: 2}); // 林**
2103
1988
  *
2104
1989
  */
2105
1990
 
@@ -2291,7 +2176,7 @@
2291
2176
  * @param {Object} [options] 配置项
2292
2177
  * @param {boolean} [options.big5=false] 繁体
2293
2178
  * @param {boolean} [options.unit=true] 计数单位
2294
- * @param {string} [options.decimal="点"] 中文小数点
2179
+ * @param {string} [options.decimal="点"] 中文小数点,繁体字为點
2295
2180
  * @param {string} [options.zero="零"] 设置0。常用配置 〇
2296
2181
  * @param {string} [options.negative="负"] 负数前面的字
2297
2182
  * @param {Object} [options.unitConfig] 节点单位配置
@@ -2300,29 +2185,21 @@
2300
2185
  * @returns {string} 中文数字
2301
2186
  * @example
2302
2187
  *
2303
- * numberToChinese(100);
2304
- * // => 一百
2305
- *
2306
- * numberToChinese(100.3);
2307
- * // => 一百点三
2188
+ * numberToChinese(100); // 一百
2189
+ * numberToChinese(100.3); // 一百点三
2190
+ * numberToChinese(1234567890); // 一十二亿三千四百五十六万七千八百九十
2191
+ * numberToChinese(1234567890.11); // 一十二亿三千四百五十六万七千八百九十点一一
2308
2192
  *
2309
2193
  * // 繁体
2310
- * numberToChinese(100, {big5: true});
2311
- * // => 壹佰
2312
- *
2313
- * numberToChinese(100.3, {big5: true});
2314
- * // => 壹佰点叁
2315
- *
2316
- * numberToChinese(1234567890, {big5: true});
2317
- * // => 壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾
2194
+ * numberToChinese(100, {big5: true}); // 壹佰
2195
+ * numberToChinese(100.3, {big5: true}); // 壹佰點叁
2196
+ * numberToChinese(1234567890.11, {big5: true}); // 壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾點壹壹
2318
2197
  *
2319
2198
  * // 不带计数单位
2320
- * numberToChinese(1990, {unit: false});
2321
- * // => 一九九零
2199
+ * numberToChinese(1990, {unit: false}); // 一九九零
2322
2200
  *
2323
2201
  * // 不带计数单位,修改0
2324
- * numberToChinese(1990, {unit: false, zero:'〇'});
2325
- * // => 一九九〇
2202
+ * numberToChinese(1990, {unit: false, zero:'〇'}); // 一九九〇
2326
2203
  *
2327
2204
  */
2328
2205
 
@@ -2334,7 +2211,7 @@
2334
2211
  _ref$unit = _ref.unit,
2335
2212
  unit = _ref$unit === void 0 ? true : _ref$unit,
2336
2213
  _ref$decimal = _ref.decimal,
2337
- decimal = _ref$decimal === void 0 ? '' : _ref$decimal,
2214
+ decimal = _ref$decimal === void 0 ? '' : _ref$decimal,
2338
2215
  _ref$zero = _ref.zero,
2339
2216
  zero = _ref$zero === void 0 ? '' : _ref$zero,
2340
2217
  _ref$negative = _ref.negative,
@@ -2354,9 +2231,11 @@
2354
2231
  if (big5) {
2355
2232
  numberChar = big5NumberChar.slice();
2356
2233
  unitChar = big5UnitChar.slice();
2234
+ decimal = decimal || '點';
2357
2235
  } else {
2358
2236
  numberChar = chnNumberChar.slice();
2359
2237
  unitChar = chnUnitChar.slice();
2238
+ decimal = decimal || '点';
2360
2239
  } // 设置节点计数单位,万、亿、万亿
2361
2240
 
2362
2241
 
@@ -2396,17 +2275,11 @@
2396
2275
  * @returns {string} 存储单位值
2397
2276
  * @example
2398
2277
  *
2399
- * bytesToSize(0);
2400
- * // => 0 B
2401
- *
2402
- * bytesToSize(1024);
2403
- * // => 1 KB
2404
- *
2405
- * bytesToSize(3.213243*1024*1024);
2406
- * // => 3.21 MB
2407
- *
2408
- * bytesToSize(1024*1024*1024);
2409
- * // => 1 GB
2278
+ * bytesToSize(0); // 0 B
2279
+ * bytesToSize(1024); // 1 KB
2280
+ * bytesToSize(3.213243*1024*1024); // 3.21 MB
2281
+ * bytesToSize(1024*1024*1024); // 1 GB
2282
+ *
2410
2283
  */
2411
2284
  function bytesToSize(bytes) {
2412
2285
  var numBytes = typeof bytes !== 'number' ? Number(bytes) : bytes;
@@ -2479,11 +2352,11 @@
2479
2352
  * @param {string} id 身份证号码,支持15位
2480
2353
  * @returns {null|IdCardInfo} null 或 省份、生日、性别,省/市/区/年/月/日/性别编码
2481
2354
  * @example
2482
- * parseIdCard('123456789123456');
2483
- * // => null
2355
+ *
2356
+ * parseIdCard('123456789123456'); // null
2484
2357
  *
2485
2358
  * // 18位身份证号码
2486
- * parseIdCard('130701199310302288')
2359
+ * parseIdCard('130701199310302288');
2487
2360
  * // =>
2488
2361
  * {
2489
2362
  * birthday: "1993-10-30",
@@ -2505,24 +2378,17 @@
2505
2378
  */
2506
2379
 
2507
2380
  function parseIdCard(id) {
2508
- if (!isIdCard(id, {
2509
- loose: true
2510
- })) {
2381
+ if (!regIdCard.test(id)) {
2511
2382
  return null;
2512
2383
  }
2384
+ /** @type {RegExpExecArray} */
2385
+ // @ts-ignore
2513
2386
 
2514
- var info = regIdCard.exec(id);
2515
2387
 
2516
- if (!info) {
2517
- return null;
2518
- }
2519
- /**
2520
- * @type {{ province: string, city: string, area: string, year: string, month: string, day: string, gender: string }}
2521
- *
2522
- */
2388
+ var info = regIdCard.exec(id);
2389
+ /** @type {{ province: string, city: string, area: string, year: string, month: string, day: string, gender: string }} */
2523
2390
  // @ts-ignore
2524
2391
 
2525
-
2526
2392
  var origin = (info === null || info === void 0 ? void 0 : info.groups) || {
2527
2393
  province: info[1],
2528
2394
  city: info[2],
@@ -2605,7 +2471,7 @@
2605
2471
  * @returns {Blob} Blob 对象
2606
2472
  * @example
2607
2473
  * const dataurl = 'data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=';
2608
- * dataURLToBlob(dataurl);
2474
+ * dataURLToBlob(dataurl); // Blob {size: 32, type: 'text/html'}
2609
2475
  */
2610
2476
  function dataURLToBlob(dataurl) {
2611
2477
  var arr = dataurl.split(','); // @ts-ignore
@@ -2638,6 +2504,7 @@
2638
2504
  * @param {boolean} [base64=true] 添加 base64 标识
2639
2505
  * @returns {string} DataURL 格式的字符串
2640
2506
  * @example
2507
+ *
2641
2508
  * const data = 'PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=';
2642
2509
  * setDataURLPrefix(data); // data:image/png;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
2643
2510
  * setDataURLPrefix(data, 'image/png', false); // data:image/png,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
@@ -2645,6 +2512,7 @@
2645
2512
  * setDataURLPrefix(data, 'text/html'); // data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
2646
2513
  * setDataURLPrefix(data, ''); // data:;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
2647
2514
  * setDataURLPrefix(data, '', false); // data:,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
2515
+ *
2648
2516
  */
2649
2517
  function setDataURLPrefix(data) {
2650
2518
  var mimetype = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'image/png';
@@ -2664,12 +2532,14 @@
2664
2532
  * @param {...number} args 月/日/时/分/秒/毫秒
2665
2533
  * @returns {Date} Date 实例日期对象
2666
2534
  * @example
2535
+ *
2667
2536
  * safeDate('2022-1-1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
2668
2537
  * safeDate('2022/1/1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
2669
2538
  * safeDate('2022.1.1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
2670
2539
  * safeDate('2022.1.1 11:11'); // Sat Jan 01 2022 11:11:00 GMT+0800 (中国标准时间)
2671
2540
  * safeDate(99, 1); // Mon Feb 01 1999 00:00:00 GMT+0800 (中国标准时间)
2672
2541
  * safeDate(1646711233171); // Tue Mar 08 2022 11:47:13 GMT+0800 (中国标准时间)
2542
+ *
2673
2543
  *
2674
2544
  */
2675
2545
 
@@ -2700,17 +2570,19 @@
2700
2570
  * @param {string} [options.char=' '] 间隔字符
2701
2571
  * @returns {string} 格式化后的手机号码
2702
2572
  * @example
2703
- * formatMobile('13345678900') // '133 4567 8900'
2704
- * formatMobile('13345678900', { char: '-' }) // '133-4567-8900'
2573
+ *
2574
+ * formatMobile('13345678900'); // 133 4567 8900
2575
+ * formatMobile('13345678900', { char: '-' }); // 133-4567-8900
2705
2576
  *
2706
2577
  * // 脱敏手机号码
2707
- * formatMobile('133****1234') // '133 **** 1234'
2708
- * formatMobile('133****1234', { char: '-' }) // '133-****-1234'
2578
+ * formatMobile('133****1234'); // 133 **** 1234
2579
+ * formatMobile('133****1234', { char: '-' }); // 133-****-1234
2709
2580
  *
2710
2581
  * // 手机号码位数不够
2711
- * formatMobile('133') // '133'
2712
- * formatMobile('133456') // '133 456'
2713
- * formatMobile('13345678') // '133 4567 8'
2582
+ * formatMobile('133'); // 133
2583
+ * formatMobile('133456'); // 133 456
2584
+ * formatMobile('13345678'); // 133 4567 8
2585
+ *
2714
2586
  */
2715
2587
 
2716
2588
  function formatMobile(mobileNo) {
@@ -2742,17 +2614,18 @@
2742
2614
  * @param {number} [size=2] 指定字符串长度
2743
2615
  * @returns {string} 用零填充数字到给定长度的字符串
2744
2616
  * @example
2745
- * padZero(5); // '05'
2746
- * padZero('5'); // '05'
2617
+ * padZero(5); // 05
2618
+ * padZero('5'); // 05
2747
2619
  *
2748
- * padZero(12); // '12'
2749
- * padZero('12'); // '12'
2620
+ * padZero(12); // 12
2621
+ * padZero('12'); // 12
2750
2622
  *
2751
- * padZero(688); // '688'
2752
- * padZero('688'); // '688'
2623
+ * padZero(688); // 688
2624
+ * padZero('688'); // 688
2753
2625
  *
2754
- * padZero(688, 5); // '00688'
2755
- * padZero('688', 5); // '00688'
2626
+ * padZero(688, 5); // 00688
2627
+ * padZero('688', 5); // 00688
2628
+ *
2756
2629
  */
2757
2630
 
2758
2631
  function padZero(value) {
@@ -2781,14 +2654,10 @@
2781
2654
  * @returns {number} 乘积
2782
2655
  * @example
2783
2656
  *
2784
- * times(3, 0.6);
2785
- * // => 1.8
2786
- *
2787
- * times(3, 0.6, 2);
2788
- * // => 3.6
2789
- *
2790
- * times(3, 0.6, 2, 10);
2791
- * // => 36
2657
+ * times(3, 0.6); // 1.8
2658
+ * times(3, 0.6, 2); // 3.6
2659
+ * times(3, 0.6, 2, 10); // 36
2660
+ *
2792
2661
  */
2793
2662
 
2794
2663
  function times() {
@@ -2831,14 +2700,10 @@
2831
2700
  * @returns {number} 总和
2832
2701
  * @example
2833
2702
  *
2834
- * plus(0.1, 0.2);
2835
- * // => 0.3
2836
- *
2837
- * plus(0.1, 0.2, 0.3);
2838
- * // => 0.6
2839
- *
2840
- * plus(0.1, 0.2, 0.3, 0.4);
2841
- * // => 1
2703
+ * plus(0.1, 0.2); // 0.3
2704
+ * plus(0.1, 0.2, 0.3); // 0.6
2705
+ * plus(0.1, 0.2, 0.3, 0.4); // 1
2706
+ *
2842
2707
  */
2843
2708
 
2844
2709
  function plus() {
@@ -2877,14 +2742,10 @@
2877
2742
  * @returns {number} 差
2878
2743
  * @example
2879
2744
  *
2880
- * minus(1, 0.9);
2881
- * // => 0.1
2882
- *
2883
- * minus(1, 0.9, 0.02);
2884
- * // => 0.08
2885
- *
2886
- * minus(1, 0.9, 0.02, 0.08);
2887
- * // => 0
2745
+ * minus(1, 0.9); // 0.1
2746
+ * minus(1, 0.9, 0.02); // 0.08
2747
+ * minus(1, 0.9, 0.02, 0.08); // 0
2748
+ *
2888
2749
  */
2889
2750
 
2890
2751
  function minus() {
@@ -2931,6 +2792,7 @@
2931
2792
  * divide(); // NaN 如果没有传入参数,被除数默认为 undefined 。 Number(undefined) 转换为 NaN ,NaN/1 = NaN
2932
2793
  * divide(null); // 0 Number(null) 转换为 0 , 0/1 = 0
2933
2794
  * divide('1.5 ', 0.5); // 3 Number('1.5 ') 转换为 1.5 ,1.5/0.5 = 3
2795
+ *
2934
2796
  */
2935
2797
 
2936
2798
  function divide() {
@@ -2974,14 +2836,10 @@
2974
2836
  * @returns {number} 四舍五入的数字
2975
2837
  * @example
2976
2838
  *
2977
- * round(4.006);
2978
- * // => 4
2979
- *
2980
- * round(4.006, 2);
2981
- * // => 4.01
2982
- *
2983
- * round(4060, -2);
2984
- * // => 4100
2839
+ * round(4.006); // 4
2840
+ * round(4.006, 2); // 4.01
2841
+ * round(4060, -2); // 4100
2842
+ *
2985
2843
  */
2986
2844
 
2987
2845
  function round(num) {
@@ -3006,6 +2864,7 @@
3006
2864
  * @param {number} [time=1000] 延时时间,单位毫秒
3007
2865
  * @returns {Promise<void>}
3008
2866
  * @example
2867
+ *
3009
2868
  * const test = async ()=>{
3010
2869
  * await waitTime();
3011
2870
  * // do something
@@ -3013,7 +2872,8 @@
3013
2872
  *
3014
2873
  * waitTime(500).then(()=>{
3015
2874
  * // do something
3016
- * })
2875
+ * });
2876
+ *
3017
2877
  */
3018
2878
  function waitTime() {
3019
2879
  var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
@@ -3115,12 +2975,14 @@
3115
2975
  * @param {string} [optionalChars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'] 允许的字符,默认为数字和大小写字母
3116
2976
  * @returns {string} 随机字符串
3117
2977
  * @example
2978
+ *
3118
2979
  * randomString(5); // slk23
3119
2980
  * randomString(8); // 71mHqo2A
3120
2981
  *
3121
2982
  * // 自定义允许的字符
3122
2983
  * randomString(5, 'abc'); // ccbcb
3123
2984
  * randomString(8, 'abcefg'); // bcgcfabg
2985
+ *
3124
2986
  */
3125
2987
 
3126
2988