util-helpers 4.12.6 → 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 (130) hide show
  1. package/README.md +8 -4
  2. package/dist/util-helpers.js +216 -342
  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 +3 -3
  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/waitTime.js +3 -1
  48. package/lib/bytesToSize.js +5 -11
  49. package/lib/calculateCursorPosition.js +1 -1
  50. package/lib/dataURLToBlob.js +1 -1
  51. package/lib/divide.js +1 -0
  52. package/lib/formatBankCard.js +4 -8
  53. package/lib/formatMobile.js +9 -7
  54. package/lib/formatMoney.js +8 -14
  55. package/lib/isBankCard.js +6 -11
  56. package/lib/isBusinessLicense.js +7 -10
  57. package/lib/isChinese.js +10 -17
  58. package/lib/isEmail.js +2 -5
  59. package/lib/isHMCard.js +8 -8
  60. package/lib/isIPv4.js +4 -11
  61. package/lib/isIPv6.js +11 -29
  62. package/lib/isIdCard.js +9 -12
  63. package/lib/isMobile.js +2 -5
  64. package/lib/isPassport.js +2 -5
  65. package/lib/isPassword.js +14 -21
  66. package/lib/isPostcode.js +2 -5
  67. package/lib/isPromiseLike.js +4 -8
  68. package/lib/isQQ.js +2 -5
  69. package/lib/isSocialCreditCode.js +6 -11
  70. package/lib/isSwiftCode.js +5 -5
  71. package/lib/isTWCard.js +7 -4
  72. package/lib/isTelephone.js +7 -10
  73. package/lib/isUrl.js +8 -20
  74. package/lib/isVehicle.js +9 -14
  75. package/lib/isWX.js +2 -5
  76. package/lib/minus.js +4 -8
  77. package/lib/normalizeString.js +2 -0
  78. package/lib/numberToChinese.js +13 -19
  79. package/lib/padZero.js +9 -8
  80. package/lib/parseIdCard.js +3 -3
  81. package/lib/plus.js +4 -8
  82. package/lib/randomString.js +2 -0
  83. package/lib/replaceChar.js +9 -17
  84. package/lib/round.js +4 -8
  85. package/lib/safeDate.js +2 -0
  86. package/lib/setDataURLPrefix.js +2 -0
  87. package/lib/times.js +4 -8
  88. package/lib/utils/config.js +1 -1
  89. package/lib/waitTime.js +3 -1
  90. package/package.json +1 -1
  91. package/types/src/bytesToSize.d.ts +4 -10
  92. package/types/src/dataURLToBlob.d.ts +1 -1
  93. package/types/src/divide.d.ts +1 -0
  94. package/types/src/formatBankCard.d.ts +4 -8
  95. package/types/src/formatMobile.d.ts +9 -7
  96. package/types/src/formatMoney.d.ts +8 -14
  97. package/types/src/isBankCard.d.ts +5 -10
  98. package/types/src/isBusinessLicense.d.ts +6 -9
  99. package/types/src/isChinese.d.ts +9 -16
  100. package/types/src/isEmail.d.ts +2 -5
  101. package/types/src/isHMCard.d.ts +8 -8
  102. package/types/src/isIPv4.d.ts +4 -11
  103. package/types/src/isIPv6.d.ts +11 -29
  104. package/types/src/isIdCard.d.ts +8 -11
  105. package/types/src/isMobile.d.ts +2 -5
  106. package/types/src/isPassport.d.ts +2 -5
  107. package/types/src/isPassword.d.ts +10 -17
  108. package/types/src/isPostcode.d.ts +2 -5
  109. package/types/src/isPromiseLike.d.ts +3 -7
  110. package/types/src/isQQ.d.ts +2 -5
  111. package/types/src/isSocialCreditCode.d.ts +6 -11
  112. package/types/src/isSwiftCode.d.ts +5 -5
  113. package/types/src/isTWCard.d.ts +7 -4
  114. package/types/src/isTelephone.d.ts +6 -9
  115. package/types/src/isUrl.d.ts +7 -19
  116. package/types/src/isVehicle.d.ts +8 -13
  117. package/types/src/isWX.d.ts +2 -5
  118. package/types/src/minus.d.ts +3 -7
  119. package/types/src/normalizeString.d.ts +2 -0
  120. package/types/src/numberToChinese.d.ts +10 -18
  121. package/types/src/padZero.d.ts +9 -8
  122. package/types/src/parseIdCard.d.ts +3 -3
  123. package/types/src/plus.d.ts +3 -7
  124. package/types/src/randomString.d.ts +2 -0
  125. package/types/src/replaceChar.d.ts +9 -17
  126. package/types/src/round.d.ts +3 -7
  127. package/types/src/safeDate.d.ts +2 -0
  128. package/types/src/setDataURLPrefix.d.ts +2 -0
  129. package/types/src/times.d.ts +3 -7
  130. 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
250
+ * isIdCard('130701199310302288'); // true
251
+ * isIdCard('13070119931030228X'); // false
259
252
  *
260
- * isIdCard('13070119931030228X');
261
- * // => false
253
+ * // 不校验校验码
254
+ * isIdCard('13070119931030228X', { checkCode: false }); // true
262
255
  *
263
- * isIdCard('13070119931030228X', { checkCode: false }); // 不校验校验码
264
- * // => true
265
- *
266
- * isIdCard('320311770706001');
267
- * // => false
268
- *
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.6";
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
1124
+ * isBusinessLicense('310115600985533'); // true
1125
+ * isBusinessLicense('310115600985535'); // false
1214
1126
  *
1215
- * isBusinessLicense('310115600985535');
1216
- * // => false
1217
- *
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
 
@@ -1938,32 +1846,26 @@
1938
1846
  * @example
1939
1847
  *
1940
1848
  * // 整数
1941
- * formatMoney('1000');
1942
- * // => 1,000.00
1849
+ * formatMoney('1000'); // 1,000.00
1943
1850
  *
1944
1851
  * // 小数(默认保留2位小数)
1945
- * formatMoney('3000.03');
1946
- * // => 3,000.03
1852
+ * formatMoney('3000.03'); // 3,000.03
1947
1853
  *
1948
1854
  * // 保留4位小数
1949
- * formatMoney('3000.0300', { precision: 4 });
1950
- * // => 3,000.0300
1855
+ * formatMoney('3000.0300', { precision: 4 }); // 3,000.0300
1951
1856
  *
1952
1857
  * // 保留10位小数
1953
- * formatMoney('1500.2', { precision: 10 });
1954
- * // => 1,500.2000000000
1858
+ * formatMoney('1500.2', { precision: 10 }); // 1,500.2000000000
1955
1859
  *
1956
1860
  * // 自定义单位符号
1957
- * formatMoney(1000.00, { symbol: '$' });
1958
- * // => $1,000.00
1861
+ * formatMoney(1000.00, { symbol: '$' }); // $1,000.00
1959
1862
  *
1960
1863
  * // 自定义千位分割符(默认',')
1961
- * formatMoney(1000.00, { thousand: '|' });
1962
- * // => 1|000.00
1864
+ * formatMoney(1000.00, { thousand: '|' }); // 1|000.00
1963
1865
  *
1964
1866
  * // 自定义小数位分割符(默认'.')
1965
- * formatMoney(1000.00, { decimal: '&' });
1966
- * // => 1,000&00
1867
+ * formatMoney(1000.00, { decimal: '&' }); // 1,000&00
1868
+ *
1967
1869
  */
1968
1870
 
1969
1871
 
@@ -2018,20 +1920,16 @@
2018
1920
  * @example
2019
1921
  *
2020
1922
  * // 19位银行卡
2021
- * formatBankCard('6228480402564890018');
2022
- * // => 6228 4804 0256 4890 018
1923
+ * formatBankCard('6228480402564890018'); // 6228 4804 0256 4890 018
2023
1924
  *
2024
1925
  * // 16位银行卡
2025
- * formatBankCard('6228480402564890');
2026
- * // => 6228 4804 0256 4890
1926
+ * formatBankCard('6228480402564890'); // 6228 4804 0256 4890
2027
1927
  *
2028
1928
  * // 脱敏银行卡
2029
- * formatBankCard('6228********890');
2030
- * // => 6228 **** **** 890
1929
+ * formatBankCard('6228********890'); // 6228 **** **** 890
2031
1930
  *
2032
1931
  * // 16位银行卡,"-"间隔
2033
- * formatBankCard('6228480402564890', {char: '-'});
2034
- * // => 6228-4804-0256-4890
1932
+ * formatBankCard('6228480402564890', {char: '-'}); // 6228-4804-0256-4890
2035
1933
  *
2036
1934
  */
2037
1935
 
@@ -2068,33 +1966,25 @@
2068
1966
  * @example
2069
1967
  *
2070
1968
  * // 手机号
2071
- * replaceChar('13000000000');
2072
- * // => 130****0000
1969
+ * replaceChar('13000000000'); // 130****0000
2073
1970
  *
2074
1971
  * // 身份证
2075
- * replaceChar('130701199310302288');
2076
- * // => 130***********2288
1972
+ * replaceChar('130701199310302288'); // 130***********2288
2077
1973
  *
2078
1974
  * // 邮箱
2079
1975
  * const email = '12345@qq.com'
2080
- * replaceChar(email, {start: 2, end: email.indexOf('@'), repeat: 4});
2081
- * // => 12****@qq.com
1976
+ * replaceChar(email, {start: 2, end: email.indexOf('@'), repeat: 4}); // 12****@qq.com
2082
1977
  *
2083
1978
  * // 银行卡号
2084
- * replaceChar('6228480402564890018', {start: 0, end: -4, repeat: 4});
2085
- * // => ****0018
1979
+ * replaceChar('6228480402564890018', {start: 0, end: -4, repeat: 4}); // ****0018
2086
1980
  *
2087
- * // 带格式的银行卡号
2088
- * replaceChar('6228 4804 0256 4890 018', {start: 4, end: -4, exclude: ' '});
2089
- * // => 6228 **** **** **** 018
1981
+ * // 带格式的银行卡号,忽略空字符串
1982
+ * replaceChar('6228 4804 0256 4890 018', {start: 4, end: -4, exclude: ' '}); // 6228 **** **** **** 018
2090
1983
  *
2091
1984
  * // 用户名
2092
- * replaceChar('林某某', {start: 1, end: Infinity, repeat: 2});
2093
- * // => 林**
2094
- * replaceChar('林某', {start: 1, end: Infinity, repeat: 2});
2095
- * // => 林**
2096
- * replaceChar('林某某某', {start: 1, end: Infinity, repeat: 2});
2097
- * // => 林**
1985
+ * replaceChar('林某某', {start: 1, end: Infinity, repeat: 2}); // 林**
1986
+ * replaceChar('林某', {start: 1, end: Infinity, repeat: 2}); // 林**
1987
+ * replaceChar('林某某某', {start: 1, end: Infinity, repeat: 2}); // 林**
2098
1988
  *
2099
1989
  */
2100
1990
 
@@ -2286,7 +2176,7 @@
2286
2176
  * @param {Object} [options] 配置项
2287
2177
  * @param {boolean} [options.big5=false] 繁体
2288
2178
  * @param {boolean} [options.unit=true] 计数单位
2289
- * @param {string} [options.decimal="点"] 中文小数点
2179
+ * @param {string} [options.decimal="点"] 中文小数点,繁体字为點
2290
2180
  * @param {string} [options.zero="零"] 设置0。常用配置 〇
2291
2181
  * @param {string} [options.negative="负"] 负数前面的字
2292
2182
  * @param {Object} [options.unitConfig] 节点单位配置
@@ -2295,29 +2185,21 @@
2295
2185
  * @returns {string} 中文数字
2296
2186
  * @example
2297
2187
  *
2298
- * numberToChinese(100);
2299
- * // => 一百
2300
- *
2301
- * numberToChinese(100.3);
2302
- * // => 一百点三
2188
+ * numberToChinese(100); // 一百
2189
+ * numberToChinese(100.3); // 一百点三
2190
+ * numberToChinese(1234567890); // 一十二亿三千四百五十六万七千八百九十
2191
+ * numberToChinese(1234567890.11); // 一十二亿三千四百五十六万七千八百九十点一一
2303
2192
  *
2304
2193
  * // 繁体
2305
- * numberToChinese(100, {big5: true});
2306
- * // => 壹佰
2307
- *
2308
- * numberToChinese(100.3, {big5: true});
2309
- * // => 壹佰点叁
2310
- *
2311
- * numberToChinese(1234567890, {big5: true});
2312
- * // => 壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾
2194
+ * numberToChinese(100, {big5: true}); // 壹佰
2195
+ * numberToChinese(100.3, {big5: true}); // 壹佰點叁
2196
+ * numberToChinese(1234567890.11, {big5: true}); // 壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾點壹壹
2313
2197
  *
2314
2198
  * // 不带计数单位
2315
- * numberToChinese(1990, {unit: false});
2316
- * // => 一九九零
2199
+ * numberToChinese(1990, {unit: false}); // 一九九零
2317
2200
  *
2318
2201
  * // 不带计数单位,修改0
2319
- * numberToChinese(1990, {unit: false, zero:'〇'});
2320
- * // => 一九九〇
2202
+ * numberToChinese(1990, {unit: false, zero:'〇'}); // 一九九〇
2321
2203
  *
2322
2204
  */
2323
2205
 
@@ -2329,7 +2211,7 @@
2329
2211
  _ref$unit = _ref.unit,
2330
2212
  unit = _ref$unit === void 0 ? true : _ref$unit,
2331
2213
  _ref$decimal = _ref.decimal,
2332
- decimal = _ref$decimal === void 0 ? '' : _ref$decimal,
2214
+ decimal = _ref$decimal === void 0 ? '' : _ref$decimal,
2333
2215
  _ref$zero = _ref.zero,
2334
2216
  zero = _ref$zero === void 0 ? '' : _ref$zero,
2335
2217
  _ref$negative = _ref.negative,
@@ -2349,9 +2231,11 @@
2349
2231
  if (big5) {
2350
2232
  numberChar = big5NumberChar.slice();
2351
2233
  unitChar = big5UnitChar.slice();
2234
+ decimal = decimal || '點';
2352
2235
  } else {
2353
2236
  numberChar = chnNumberChar.slice();
2354
2237
  unitChar = chnUnitChar.slice();
2238
+ decimal = decimal || '点';
2355
2239
  } // 设置节点计数单位,万、亿、万亿
2356
2240
 
2357
2241
 
@@ -2391,17 +2275,11 @@
2391
2275
  * @returns {string} 存储单位值
2392
2276
  * @example
2393
2277
  *
2394
- * bytesToSize(0);
2395
- * // => 0 B
2396
- *
2397
- * bytesToSize(1024);
2398
- * // => 1 KB
2399
- *
2400
- * bytesToSize(3.213243*1024*1024);
2401
- * // => 3.21 MB
2402
- *
2403
- * bytesToSize(1024*1024*1024);
2404
- * // => 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
+ *
2405
2283
  */
2406
2284
  function bytesToSize(bytes) {
2407
2285
  var numBytes = typeof bytes !== 'number' ? Number(bytes) : bytes;
@@ -2474,11 +2352,11 @@
2474
2352
  * @param {string} id 身份证号码,支持15位
2475
2353
  * @returns {null|IdCardInfo} null 或 省份、生日、性别,省/市/区/年/月/日/性别编码
2476
2354
  * @example
2477
- * parseIdCard('123456789123456');
2478
- * // => null
2355
+ *
2356
+ * parseIdCard('123456789123456'); // null
2479
2357
  *
2480
2358
  * // 18位身份证号码
2481
- * parseIdCard('130701199310302288')
2359
+ * parseIdCard('130701199310302288');
2482
2360
  * // =>
2483
2361
  * {
2484
2362
  * birthday: "1993-10-30",
@@ -2593,7 +2471,7 @@
2593
2471
  * @returns {Blob} Blob 对象
2594
2472
  * @example
2595
2473
  * const dataurl = 'data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=';
2596
- * dataURLToBlob(dataurl);
2474
+ * dataURLToBlob(dataurl); // Blob {size: 32, type: 'text/html'}
2597
2475
  */
2598
2476
  function dataURLToBlob(dataurl) {
2599
2477
  var arr = dataurl.split(','); // @ts-ignore
@@ -2626,6 +2504,7 @@
2626
2504
  * @param {boolean} [base64=true] 添加 base64 标识
2627
2505
  * @returns {string} DataURL 格式的字符串
2628
2506
  * @example
2507
+ *
2629
2508
  * const data = 'PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=';
2630
2509
  * setDataURLPrefix(data); // data:image/png;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
2631
2510
  * setDataURLPrefix(data, 'image/png', false); // data:image/png,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
@@ -2633,6 +2512,7 @@
2633
2512
  * setDataURLPrefix(data, 'text/html'); // data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
2634
2513
  * setDataURLPrefix(data, ''); // data:;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
2635
2514
  * setDataURLPrefix(data, '', false); // data:,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
2515
+ *
2636
2516
  */
2637
2517
  function setDataURLPrefix(data) {
2638
2518
  var mimetype = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'image/png';
@@ -2652,12 +2532,14 @@
2652
2532
  * @param {...number} args 月/日/时/分/秒/毫秒
2653
2533
  * @returns {Date} Date 实例日期对象
2654
2534
  * @example
2535
+ *
2655
2536
  * safeDate('2022-1-1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
2656
2537
  * safeDate('2022/1/1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
2657
2538
  * safeDate('2022.1.1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
2658
2539
  * safeDate('2022.1.1 11:11'); // Sat Jan 01 2022 11:11:00 GMT+0800 (中国标准时间)
2659
2540
  * safeDate(99, 1); // Mon Feb 01 1999 00:00:00 GMT+0800 (中国标准时间)
2660
2541
  * safeDate(1646711233171); // Tue Mar 08 2022 11:47:13 GMT+0800 (中国标准时间)
2542
+ *
2661
2543
  *
2662
2544
  */
2663
2545
 
@@ -2688,17 +2570,19 @@
2688
2570
  * @param {string} [options.char=' '] 间隔字符
2689
2571
  * @returns {string} 格式化后的手机号码
2690
2572
  * @example
2691
- * formatMobile('13345678900') // '133 4567 8900'
2692
- * formatMobile('13345678900', { char: '-' }) // '133-4567-8900'
2573
+ *
2574
+ * formatMobile('13345678900'); // 133 4567 8900
2575
+ * formatMobile('13345678900', { char: '-' }); // 133-4567-8900
2693
2576
  *
2694
2577
  * // 脱敏手机号码
2695
- * formatMobile('133****1234') // '133 **** 1234'
2696
- * formatMobile('133****1234', { char: '-' }) // '133-****-1234'
2578
+ * formatMobile('133****1234'); // 133 **** 1234
2579
+ * formatMobile('133****1234', { char: '-' }); // 133-****-1234
2697
2580
  *
2698
2581
  * // 手机号码位数不够
2699
- * formatMobile('133') // '133'
2700
- * formatMobile('133456') // '133 456'
2701
- * formatMobile('13345678') // '133 4567 8'
2582
+ * formatMobile('133'); // 133
2583
+ * formatMobile('133456'); // 133 456
2584
+ * formatMobile('13345678'); // 133 4567 8
2585
+ *
2702
2586
  */
2703
2587
 
2704
2588
  function formatMobile(mobileNo) {
@@ -2730,17 +2614,18 @@
2730
2614
  * @param {number} [size=2] 指定字符串长度
2731
2615
  * @returns {string} 用零填充数字到给定长度的字符串
2732
2616
  * @example
2733
- * padZero(5); // '05'
2734
- * padZero('5'); // '05'
2617
+ * padZero(5); // 05
2618
+ * padZero('5'); // 05
2735
2619
  *
2736
- * padZero(12); // '12'
2737
- * padZero('12'); // '12'
2620
+ * padZero(12); // 12
2621
+ * padZero('12'); // 12
2738
2622
  *
2739
- * padZero(688); // '688'
2740
- * padZero('688'); // '688'
2623
+ * padZero(688); // 688
2624
+ * padZero('688'); // 688
2741
2625
  *
2742
- * padZero(688, 5); // '00688'
2743
- * padZero('688', 5); // '00688'
2626
+ * padZero(688, 5); // 00688
2627
+ * padZero('688', 5); // 00688
2628
+ *
2744
2629
  */
2745
2630
 
2746
2631
  function padZero(value) {
@@ -2769,14 +2654,10 @@
2769
2654
  * @returns {number} 乘积
2770
2655
  * @example
2771
2656
  *
2772
- * times(3, 0.6);
2773
- * // => 1.8
2774
- *
2775
- * times(3, 0.6, 2);
2776
- * // => 3.6
2777
- *
2778
- * times(3, 0.6, 2, 10);
2779
- * // => 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
+ *
2780
2661
  */
2781
2662
 
2782
2663
  function times() {
@@ -2819,14 +2700,10 @@
2819
2700
  * @returns {number} 总和
2820
2701
  * @example
2821
2702
  *
2822
- * plus(0.1, 0.2);
2823
- * // => 0.3
2824
- *
2825
- * plus(0.1, 0.2, 0.3);
2826
- * // => 0.6
2827
- *
2828
- * plus(0.1, 0.2, 0.3, 0.4);
2829
- * // => 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
+ *
2830
2707
  */
2831
2708
 
2832
2709
  function plus() {
@@ -2865,14 +2742,10 @@
2865
2742
  * @returns {number} 差
2866
2743
  * @example
2867
2744
  *
2868
- * minus(1, 0.9);
2869
- * // => 0.1
2870
- *
2871
- * minus(1, 0.9, 0.02);
2872
- * // => 0.08
2873
- *
2874
- * minus(1, 0.9, 0.02, 0.08);
2875
- * // => 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
+ *
2876
2749
  */
2877
2750
 
2878
2751
  function minus() {
@@ -2919,6 +2792,7 @@
2919
2792
  * divide(); // NaN 如果没有传入参数,被除数默认为 undefined 。 Number(undefined) 转换为 NaN ,NaN/1 = NaN
2920
2793
  * divide(null); // 0 Number(null) 转换为 0 , 0/1 = 0
2921
2794
  * divide('1.5 ', 0.5); // 3 Number('1.5 ') 转换为 1.5 ,1.5/0.5 = 3
2795
+ *
2922
2796
  */
2923
2797
 
2924
2798
  function divide() {
@@ -2962,14 +2836,10 @@
2962
2836
  * @returns {number} 四舍五入的数字
2963
2837
  * @example
2964
2838
  *
2965
- * round(4.006);
2966
- * // => 4
2967
- *
2968
- * round(4.006, 2);
2969
- * // => 4.01
2970
- *
2971
- * round(4060, -2);
2972
- * // => 4100
2839
+ * round(4.006); // 4
2840
+ * round(4.006, 2); // 4.01
2841
+ * round(4060, -2); // 4100
2842
+ *
2973
2843
  */
2974
2844
 
2975
2845
  function round(num) {
@@ -2994,6 +2864,7 @@
2994
2864
  * @param {number} [time=1000] 延时时间,单位毫秒
2995
2865
  * @returns {Promise<void>}
2996
2866
  * @example
2867
+ *
2997
2868
  * const test = async ()=>{
2998
2869
  * await waitTime();
2999
2870
  * // do something
@@ -3001,7 +2872,8 @@
3001
2872
  *
3002
2873
  * waitTime(500).then(()=>{
3003
2874
  * // do something
3004
- * })
2875
+ * });
2876
+ *
3005
2877
  */
3006
2878
  function waitTime() {
3007
2879
  var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
@@ -3103,12 +2975,14 @@
3103
2975
  * @param {string} [optionalChars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'] 允许的字符,默认为数字和大小写字母
3104
2976
  * @returns {string} 随机字符串
3105
2977
  * @example
2978
+ *
3106
2979
  * randomString(5); // slk23
3107
2980
  * randomString(8); // 71mHqo2A
3108
2981
  *
3109
2982
  * // 自定义允许的字符
3110
2983
  * randomString(5, 'abc'); // ccbcb
3111
2984
  * randomString(8, 'abcefg'); // bcgcfabg
2985
+ *
3112
2986
  */
3113
2987
 
3114
2988