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
@@ -10,25 +10,13 @@ export default isUrl;
10
10
  * @returns {boolean} 值是否为url
11
11
  * @example
12
12
  *
13
- * isUrl('');
14
- * // => false
13
+ * isUrl(''); // false
14
+ * isUrl('8.8.8.8'); // false
15
+ * isUrl('example.com'); // true
16
+ * isUrl('http://example.com'); // true
17
+ * isUrl('https://example.com:8080'); // true
18
+ * isUrl('http://www.example.com/test/123'); // true
19
+ * isUrl('http://www.example.com/test/123?foo=bar'); // true
15
20
  *
16
- * isUrl('8.8.8.8');
17
- * // => false
18
- *
19
- * isUrl('example.com');
20
- * // => true
21
- *
22
- * isUrl('http://example.com');
23
- * // => true
24
- *
25
- * isUrl('https://example.com:8080');
26
- * // => true
27
- *
28
- * isUrl('http://www.example.com/test/123');
29
- * // => true
30
- *
31
- * isUrl('http://www.example.com/test/123?foo=bar');
32
- * // => true
33
21
  */
34
22
  declare function isUrl(value: any): boolean;
@@ -10,20 +10,15 @@ export default isVehicle;
10
10
  * @returns {boolean} 值是否为车牌号
11
11
  * @example
12
12
  *
13
- * isVehicle('京L12345');
14
- * // => true
13
+ * isVehicle('京L12345'); // true
14
+ * isVehicle('京L1234学'); // true
15
+ * isVehicle('BL1234警'); // true
15
16
  *
16
- * isVehicle('粤BD12345');
17
- * // => true
18
- *
19
- * isVehicle('粤BF12345');
20
- * // => true
21
- *
22
- * isVehicle('粤B12345D');
23
- * // => true
24
- *
25
- * isVehicle('粤B12345F');
26
- * // => true
17
+ * // 新能源车牌
18
+ * isVehicle('粤BD12345'); // true
19
+ * isVehicle('粤BF12345'); // true
20
+ * isVehicle('粤B12345D'); // true
21
+ * isVehicle('粤B12345F'); // true
27
22
  *
28
23
  */
29
24
  declare function isVehicle(value: any): boolean;
@@ -9,11 +9,8 @@ export default isWX;
9
9
  * @returns {boolean} 值是否为微信号
10
10
  * @example
11
11
  *
12
- * isWX('a12345');
13
- * // => true
14
- *
15
- * isWX('123');
16
- * // => false
12
+ * isWX('a12345'); // true
13
+ * isWX('123'); // false
17
14
  *
18
15
  */
19
16
  declare function isWX(value: any): boolean;
@@ -9,13 +9,9 @@ export default minus;
9
9
  * @returns {number} 差
10
10
  * @example
11
11
  *
12
- * minus(1, 0.9);
13
- * // => 0.1
12
+ * minus(1, 0.9); // 0.1
13
+ * minus(1, 0.9, 0.02); // 0.08
14
+ * minus(1, 0.9, 0.02, 0.08); // 0
14
15
  *
15
- * minus(1, 0.9, 0.02);
16
- * // => 0.08
17
- *
18
- * minus(1, 0.9, 0.02, 0.08);
19
- * // => 0
20
16
  */
21
17
  declare function minus(...nums: (number | string)[]): number;
@@ -9,6 +9,7 @@ export default normalizeString;
9
9
  * @param {*} value 待处理的值
10
10
  * @returns {string} 规整化的值
11
11
  * @example
12
+ *
12
13
  * normalizeString(); // ''
13
14
  * normalizeString(undefined); // ''
14
15
  * normalizeString(void 0); // ''
@@ -18,5 +19,6 @@ export default normalizeString;
18
19
  * normalizeString(NaN); // 'NaN'
19
20
  * normalizeString(1); // '1'
20
21
  * normalizeString('a'); // 'a'
22
+ *
21
23
  */
22
24
  declare function normalizeString(value: any): string;
@@ -10,7 +10,7 @@ export default numberToChinese;
10
10
  * @param {Object} [options] 配置项
11
11
  * @param {boolean} [options.big5=false] 繁体
12
12
  * @param {boolean} [options.unit=true] 计数单位
13
- * @param {string} [options.decimal="点"] 中文小数点
13
+ * @param {string} [options.decimal="点"] 中文小数点,繁体字为點
14
14
  * @param {string} [options.zero="零"] 设置0。常用配置 〇
15
15
  * @param {string} [options.negative="负"] 负数前面的字
16
16
  * @param {Object} [options.unitConfig] 节点单位配置
@@ -19,29 +19,21 @@ export default numberToChinese;
19
19
  * @returns {string} 中文数字
20
20
  * @example
21
21
  *
22
- * numberToChinese(100);
23
- * // => 一百
24
- *
25
- * numberToChinese(100.3);
26
- * // => 一百点三
22
+ * numberToChinese(100); // 一百
23
+ * numberToChinese(100.3); // 一百点三
24
+ * numberToChinese(1234567890); // 一十二亿三千四百五十六万七千八百九十
25
+ * numberToChinese(1234567890.11); // 一十二亿三千四百五十六万七千八百九十点一一
27
26
  *
28
27
  * // 繁体
29
- * numberToChinese(100, {big5: true});
30
- * // => 壹佰
31
- *
32
- * numberToChinese(100.3, {big5: true});
33
- * // => 壹佰点叁
34
- *
35
- * numberToChinese(1234567890, {big5: true});
36
- * // => 壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾
28
+ * numberToChinese(100, {big5: true}); // 壹佰
29
+ * numberToChinese(100.3, {big5: true}); // 壹佰點叁
30
+ * numberToChinese(1234567890.11, {big5: true}); // 壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾點壹壹
37
31
  *
38
32
  * // 不带计数单位
39
- * numberToChinese(1990, {unit: false});
40
- * // => 一九九零
33
+ * numberToChinese(1990, {unit: false}); // 一九九零
41
34
  *
42
35
  * // 不带计数单位,修改0
43
- * numberToChinese(1990, {unit: false, zero:'〇'});
44
- * // => 一九九〇
36
+ * numberToChinese(1990, {unit: false, zero:'〇'}); // 一九九〇
45
37
  *
46
38
  */
47
39
  declare function numberToChinese(num: number, { big5, unit, decimal, zero, negative, unitConfig }?: {
@@ -9,16 +9,17 @@ export default padZero;
9
9
  * @param {number} [size=2] 指定字符串长度
10
10
  * @returns {string} 用零填充数字到给定长度的字符串
11
11
  * @example
12
- * padZero(5); // '05'
13
- * padZero('5'); // '05'
12
+ * padZero(5); // 05
13
+ * padZero('5'); // 05
14
14
  *
15
- * padZero(12); // '12'
16
- * padZero('12'); // '12'
15
+ * padZero(12); // 12
16
+ * padZero('12'); // 12
17
17
  *
18
- * padZero(688); // '688'
19
- * padZero('688'); // '688'
18
+ * padZero(688); // 688
19
+ * padZero('688'); // 688
20
+ *
21
+ * padZero(688, 5); // 00688
22
+ * padZero('688', 5); // 00688
20
23
  *
21
- * padZero(688, 5); // '00688'
22
- * padZero('688', 5); // '00688'
23
24
  */
24
25
  declare function padZero(value: string | number, size?: number | undefined): string;
@@ -80,11 +80,11 @@ export type IdCardInfo = {
80
80
  * @param {string} id 身份证号码,支持15位
81
81
  * @returns {null|IdCardInfo} null 或 省份、生日、性别,省/市/区/年/月/日/性别编码
82
82
  * @example
83
- * parseIdCard('123456789123456');
84
- * // => null
83
+ *
84
+ * parseIdCard('123456789123456'); // null
85
85
  *
86
86
  * // 18位身份证号码
87
- * parseIdCard('130701199310302288')
87
+ * parseIdCard('130701199310302288');
88
88
  * // =>
89
89
  * {
90
90
  * birthday: "1993-10-30",
@@ -9,13 +9,9 @@ export default plus;
9
9
  * @returns {number} 总和
10
10
  * @example
11
11
  *
12
- * plus(0.1, 0.2);
13
- * // => 0.3
12
+ * plus(0.1, 0.2); // 0.3
13
+ * plus(0.1, 0.2, 0.3); // 0.6
14
+ * plus(0.1, 0.2, 0.3, 0.4); // 1
14
15
  *
15
- * plus(0.1, 0.2, 0.3);
16
- * // => 0.6
17
- *
18
- * plus(0.1, 0.2, 0.3, 0.4);
19
- * // => 1
20
16
  */
21
17
  declare function plus(...nums: (number | string)[]): number;
@@ -9,11 +9,13 @@ export default randomString;
9
9
  * @param {string} [optionalChars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'] 允许的字符,默认为数字和大小写字母
10
10
  * @returns {string} 随机字符串
11
11
  * @example
12
+ *
12
13
  * randomString(5); // slk23
13
14
  * randomString(8); // 71mHqo2A
14
15
  *
15
16
  * // 自定义允许的字符
16
17
  * randomString(5, 'abc'); // ccbcb
17
18
  * randomString(8, 'abcefg'); // bcgcfabg
19
+ *
18
20
  */
19
21
  declare function randomString(len?: number | undefined, optionalChars?: string | undefined): string;
@@ -16,33 +16,25 @@ export default replaceChar;
16
16
  * @example
17
17
  *
18
18
  * // 手机号
19
- * replaceChar('13000000000');
20
- * // => 130****0000
19
+ * replaceChar('13000000000'); // 130****0000
21
20
  *
22
21
  * // 身份证
23
- * replaceChar('130701199310302288');
24
- * // => 130***********2288
22
+ * replaceChar('130701199310302288'); // 130***********2288
25
23
  *
26
24
  * // 邮箱
27
25
  * const email = '12345@qq.com'
28
- * replaceChar(email, {start: 2, end: email.indexOf('@'), repeat: 4});
29
- * // => 12****@qq.com
26
+ * replaceChar(email, {start: 2, end: email.indexOf('@'), repeat: 4}); // 12****@qq.com
30
27
  *
31
28
  * // 银行卡号
32
- * replaceChar('6228480402564890018', {start: 0, end: -4, repeat: 4});
33
- * // => ****0018
29
+ * replaceChar('6228480402564890018', {start: 0, end: -4, repeat: 4}); // ****0018
34
30
  *
35
- * // 带格式的银行卡号
36
- * replaceChar('6228 4804 0256 4890 018', {start: 4, end: -4, exclude: ' '});
37
- * // => 6228 **** **** **** 018
31
+ * // 带格式的银行卡号,忽略空字符串
32
+ * replaceChar('6228 4804 0256 4890 018', {start: 4, end: -4, exclude: ' '}); // 6228 **** **** **** 018
38
33
  *
39
34
  * // 用户名
40
- * replaceChar('林某某', {start: 1, end: Infinity, repeat: 2});
41
- * // => 林**
42
- * replaceChar('林某', {start: 1, end: Infinity, repeat: 2});
43
- * // => 林**
44
- * replaceChar('林某某某', {start: 1, end: Infinity, repeat: 2});
45
- * // => 林**
35
+ * replaceChar('林某某', {start: 1, end: Infinity, repeat: 2}); // 林**
36
+ * replaceChar('林某', {start: 1, end: Infinity, repeat: 2}); // 林**
37
+ * replaceChar('林某某某', {start: 1, end: Infinity, repeat: 2}); // 林**
46
38
  *
47
39
  */
48
40
  declare function replaceChar(str: string, { start, end, char, repeat, exclude }?: {
@@ -10,13 +10,9 @@ export default round;
10
10
  * @returns {number} 四舍五入的数字
11
11
  * @example
12
12
  *
13
- * round(4.006);
14
- * // => 4
13
+ * round(4.006); // 4
14
+ * round(4.006, 2); // 4.01
15
+ * round(4060, -2); // 4100
15
16
  *
16
- * round(4.006, 2);
17
- * // => 4.01
18
- *
19
- * round(4060, -2);
20
- * // => 4100
21
17
  */
22
18
  declare function round(num: number | string, precision?: number | undefined): number;
@@ -11,6 +11,7 @@ export default safeDate;
11
11
  * @param {...number} args 月/日/时/分/秒/毫秒
12
12
  * @returns {Date} Date 实例日期对象
13
13
  * @example
14
+ *
14
15
  * safeDate('2022-1-1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
15
16
  * safeDate('2022/1/1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
16
17
  * safeDate('2022.1.1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
@@ -18,5 +19,6 @@ export default safeDate;
18
19
  * safeDate(99, 1); // Mon Feb 01 1999 00:00:00 GMT+0800 (中国标准时间)
19
20
  * safeDate(1646711233171); // Tue Mar 08 2022 11:47:13 GMT+0800 (中国标准时间)
20
21
  *
22
+ *
21
23
  */
22
24
  declare function safeDate(value?: string | number | Date | undefined, ...args: number[]): Date;
@@ -13,6 +13,7 @@ export default setDataURLPrefix;
13
13
  * @param {boolean} [base64=true] 添加 base64 标识
14
14
  * @returns {string} DataURL 格式的字符串
15
15
  * @example
16
+ *
16
17
  * const data = 'PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=';
17
18
  * setDataURLPrefix(data); // data:image/png;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
18
19
  * setDataURLPrefix(data, 'image/png', false); // data:image/png,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
@@ -20,5 +21,6 @@ export default setDataURLPrefix;
20
21
  * setDataURLPrefix(data, 'text/html'); // data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
21
22
  * setDataURLPrefix(data, ''); // data:;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
22
23
  * setDataURLPrefix(data, '', false); // data:,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
24
+ *
23
25
  */
24
26
  declare function setDataURLPrefix(data: string, mimetype?: string | undefined, base64?: boolean | undefined): string;
@@ -9,13 +9,9 @@ export default times;
9
9
  * @returns {number} 乘积
10
10
  * @example
11
11
  *
12
- * times(3, 0.6);
13
- * // => 1.8
12
+ * times(3, 0.6); // 1.8
13
+ * times(3, 0.6, 2); // 3.6
14
+ * times(3, 0.6, 2, 10); // 36
14
15
  *
15
- * times(3, 0.6, 2);
16
- * // => 3.6
17
- *
18
- * times(3, 0.6, 2, 10);
19
- * // => 36
20
16
  */
21
17
  declare function times(...nums: (number | string)[]): number;
@@ -8,6 +8,7 @@ export default waitTime;
8
8
  * @param {number} [time=1000] 延时时间,单位毫秒
9
9
  * @returns {Promise<void>}
10
10
  * @example
11
+ *
11
12
  * const test = async ()=>{
12
13
  * await waitTime();
13
14
  * // do something
@@ -15,6 +16,7 @@ export default waitTime;
15
16
  *
16
17
  * waitTime(500).then(()=>{
17
18
  * // do something
18
- * })
19
+ * });
20
+ *
19
21
  */
20
22
  declare function waitTime(time?: number | undefined): Promise<void>;