util-helpers 4.12.0 → 4.12.1

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 (80) hide show
  1. package/dist/util-helpers.js +3 -0
  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/index.js +5 -3
  6. package/esm/utils/config.js +2 -1
  7. package/lib/index.js +6 -0
  8. package/lib/utils/config.js +3 -1
  9. package/package.json +3 -1
  10. package/types/src/blobToDataURL.d.ts +25 -0
  11. package/types/src/bytesToSize.d.ts +24 -0
  12. package/types/src/calculateCursorPosition.d.ts +26 -0
  13. package/types/src/dataURLToBlob.d.ts +15 -0
  14. package/types/src/divide.d.ts +21 -0
  15. package/types/src/formatBankCard.d.ts +35 -0
  16. package/types/src/formatMobile.d.ts +27 -0
  17. package/types/src/formatMoney.d.ts +50 -0
  18. package/types/src/index.d.ts +45 -0
  19. package/types/src/isBankCard.d.ts +32 -0
  20. package/types/src/isBusinessLicense.d.ts +29 -0
  21. package/types/src/isChinese.d.ts +41 -0
  22. package/types/src/isEmail.d.ts +19 -0
  23. package/types/src/isHMCard.d.ts +24 -0
  24. package/types/src/isIPv4.d.ts +25 -0
  25. package/types/src/isIPv6.d.ts +50 -0
  26. package/types/src/isIdCard.d.ts +34 -0
  27. package/types/src/isMobile.d.ts +19 -0
  28. package/types/src/isPassport.d.ts +21 -0
  29. package/types/src/isPassword.d.ts +46 -0
  30. package/types/src/isPostcode.d.ts +19 -0
  31. package/types/src/isPromiseLike.d.ts +21 -0
  32. package/types/src/isQQ.d.ts +19 -0
  33. package/types/src/isSocialCreditCode.d.ts +31 -0
  34. package/types/src/isSwiftCode.d.ts +22 -0
  35. package/types/src/isTWCard.d.ts +23 -0
  36. package/types/src/isTelephone.d.ts +25 -0
  37. package/types/src/isUrl.d.ts +34 -0
  38. package/types/src/isVehicle.d.ts +29 -0
  39. package/types/src/isWX.d.ts +19 -0
  40. package/types/src/minus.d.ts +21 -0
  41. package/types/src/normalizeString.d.ts +22 -0
  42. package/types/src/numberToChinese.d.ts +57 -0
  43. package/types/src/padZero.d.ts +24 -0
  44. package/types/src/parseIdCard.d.ts +107 -0
  45. package/types/src/plus.d.ts +21 -0
  46. package/types/src/randomString.d.ts +19 -0
  47. package/types/src/replaceChar.d.ts +54 -0
  48. package/types/src/round.d.ts +22 -0
  49. package/types/src/safeDate.d.ts +22 -0
  50. package/types/src/setDataURLPrefix.d.ts +24 -0
  51. package/types/src/strlen.d.ts +20 -0
  52. package/types/src/times.d.ts +21 -0
  53. package/types/src/utils/config.d.ts +13 -0
  54. package/types/src/utils/constants.d.ts +2 -0
  55. package/types/src/utils/convertToString.d.ts +8 -0
  56. package/types/src/utils/devWarn.d.ts +7 -0
  57. package/types/src/utils/math.util.d.ts +63 -0
  58. package/types/src/utils/type/index.d.ts +19 -0
  59. package/types/src/utils/type/isArguments.d.ts +18 -0
  60. package/types/src/utils/type/isArray.d.ts +18 -0
  61. package/types/src/utils/type/isBoolean.d.ts +18 -0
  62. package/types/src/utils/type/isDate.d.ts +18 -0
  63. package/types/src/utils/type/isError.d.ts +18 -0
  64. package/types/src/utils/type/isFunction.d.ts +18 -0
  65. package/types/src/utils/type/isMap.d.ts +18 -0
  66. package/types/src/utils/type/isNaN.d.ts +18 -0
  67. package/types/src/utils/type/isNil.d.ts +11 -0
  68. package/types/src/utils/type/isNull.d.ts +18 -0
  69. package/types/src/utils/type/isNumber.d.ts +27 -0
  70. package/types/src/utils/type/isObject.d.ts +21 -0
  71. package/types/src/utils/type/isRegExp.d.ts +18 -0
  72. package/types/src/utils/type/isSet.d.ts +18 -0
  73. package/types/src/utils/type/isString.d.ts +18 -0
  74. package/types/src/utils/type/isSymbol.d.ts +18 -0
  75. package/types/src/utils/type/isType.d.ts +11 -0
  76. package/types/src/utils/type/isUndefined.d.ts +21 -0
  77. package/types/src/utils/type/isWeakMap.d.ts +18 -0
  78. package/types/src/utils/type/isWeakSet.d.ts +18 -0
  79. package/types/src/validatePassword.d.ts +134 -0
  80. package/types/src/waitTime.d.ts +20 -0
@@ -0,0 +1,46 @@
1
+ export default isPassword;
2
+ /**
3
+ * 检测值是否符合密码强度
4
+ * <p><strong>注意:该校验只校验是否存在不同字符(大小写字母、数字、特殊符号),不判断长度。</strong></p>
5
+ * <p><i>如果需要更细致的验证,请使用 <a href="#.validatePassword">validatePassword</a></i></p>
6
+ *
7
+ * @see 参考 {@link https://baike.baidu.com/item/ASCII#3|ASCII}
8
+ * @static
9
+ * @alias module:Validator.isPassword
10
+ * @since 1.1.0
11
+ * @requires module:Validator.validatePassword
12
+ * @param {*} value 要检测的值
13
+ * @param {Object} [options] 配置项
14
+ * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
15
+ * @param {boolean} [options.ignoreCase=false] 是否忽略大小写,为 ture 时,大小写字母视为一种字符
16
+ * @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符
17
+ * @returns {boolean} 值是否符合密码强度
18
+ * @example
19
+ *
20
+ * isPassword('a12345678');
21
+ * // => true
22
+ *
23
+ * isPassword('a12345678', {level: 3});
24
+ * // => false
25
+ *
26
+ * isPassword('Aa12345678', {level: 3});
27
+ * // => true
28
+ *
29
+ * isPassword('Aa12345678', {level: 3, ignoreCase: true});
30
+ * // => false
31
+ *
32
+ * isPassword('_Aa12345678', {level: 3, ignoreCase: true});
33
+ * // => true
34
+ *
35
+ * // 仅支持 数字、字母、特殊字符,其他字符如中文字符是校验不通过的
36
+ * isPassword('_Aa一二三45678', {level: 3, ignoreCase: true});
37
+ * // => false
38
+ *
39
+ * isPassword(' _Aa12345678', {level: 3, ignoreCase: true});
40
+ * // => false
41
+ */
42
+ declare function isPassword(value: any, { level, ignoreCase, special }?: {
43
+ level?: number | undefined;
44
+ ignoreCase?: boolean | undefined;
45
+ special?: string | undefined;
46
+ } | undefined): boolean;
@@ -0,0 +1,19 @@
1
+ export default isPostcode;
2
+ /**
3
+ * 检测值是否为邮政编码,6位数字
4
+ *
5
+ * @static
6
+ * @alias module:Validator.isPostcode
7
+ * @since 1.1.0
8
+ * @param {*} value 要检测的值
9
+ * @returns {boolean} 值是否为邮政编码
10
+ * @example
11
+ *
12
+ * isPostcode('101111');
13
+ * // => true
14
+ *
15
+ * isPostcode('123');
16
+ * // => false
17
+ *
18
+ */
19
+ declare function isPostcode(value: any): boolean;
@@ -0,0 +1,21 @@
1
+ export default isPromiseLike;
2
+ /**
3
+ * 检测值是否类似Promise对象
4
+ *
5
+ * @static
6
+ * @alias module:Validator.isPromiseLike
7
+ * @since 3.8.0
8
+ * @param {*} obj 要检测的值
9
+ * @returns {boolean} 是否类似Promise对象
10
+ * @example
11
+ *
12
+ * isPromiseLike([]);
13
+ * => false
14
+ *
15
+ * isPromiseLike({then:()=>{}});
16
+ * => true
17
+ *
18
+ * isPromiseLike(Promise.resolve());
19
+ * => true
20
+ */
21
+ declare function isPromiseLike(obj: any): boolean;
@@ -0,0 +1,19 @@
1
+ export default isQQ;
2
+ /**
3
+ * 检测值是否为QQ号,非0开头,5至11位数字
4
+ *
5
+ * @static
6
+ * @alias module:Validator.isQQ
7
+ * @since 1.1.0
8
+ * @param {*} value 要检测的值
9
+ * @returns {boolean} 值是否为QQ号
10
+ * @example
11
+ *
12
+ * isQQ('12345');
13
+ * // => true
14
+ *
15
+ * isQQ('123');
16
+ * // => false
17
+ *
18
+ */
19
+ declare function isQQ(value: any): boolean;
@@ -0,0 +1,31 @@
1
+ export default isSocialCreditCode;
2
+ /**
3
+ * 检测值是否为统一社会信用代码,也叫三证合一组织代码。由18位数字和大写字母组成,不使用I、O、Z、S、V。
4
+ *
5
+ * @static
6
+ * @alias module:Validator.isSocialCreditCode
7
+ * @see 参考 {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则|GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
8
+ * @since 1.1.0
9
+ * @param {*} value 要检测的值
10
+ * @param {Object} [options] 配置项
11
+ * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
12
+ * @returns {boolean} 值是否为统一社会信用代码
13
+ * @example
14
+ *
15
+ * isSocialCreditCode('91350100M000100Y43');
16
+ * // => true
17
+ *
18
+ * isSocialCreditCode('91350100M000100Y4A');
19
+ * // => false
20
+ *
21
+ * // 不校验校验位
22
+ * isSocialCreditCode('91350100M000100Y4A', { checkCode: false });
23
+ * // => true
24
+ *
25
+ * isSocialCreditCode('91350100M000100Y', { checkCode: false });
26
+ * // => false
27
+ *
28
+ */
29
+ declare function isSocialCreditCode(value: any, options?: {
30
+ checkCode?: boolean | undefined;
31
+ } | undefined): boolean;
@@ -0,0 +1,22 @@
1
+ export default isSwiftCode;
2
+ /**
3
+ * 检测值是否为 Swift Code。8位或11位,前6位为大写字母,7-8位为大写字母或数字,9-11位为可选的大写字母或数字。
4
+ *
5
+ * @static
6
+ * @alias module:Validator.isSwiftCode
7
+ * @see 参考 {@link https://zh.wikipedia.org/wiki/ISO_9362|ISO 9362}
8
+ * @since 4.9.0
9
+ * @param {*} value 要检测的值
10
+ * @returns {boolean} 值是否为 Swift Code
11
+ * @example
12
+ *
13
+ * isSwiftCode('DEUTDEFF') // true
14
+ * isSwiftCode('deutdeff') // false
15
+ *
16
+ * isSwiftCode('BKTWTWTP010') // true
17
+ * isSwiftCode('010BKTWTWTP') // false
18
+ *
19
+ * isSwiftCode('ICBKCNBJBJM') // true
20
+ *
21
+ */
22
+ declare function isSwiftCode(value: any): boolean;
@@ -0,0 +1,23 @@
1
+ export default isTWCard;
2
+ /**
3
+ * 检测值是否为台湾居民来往大陆通行证,俗称台胞证。
4
+ *
5
+ * @static
6
+ * @alias module:Validator.isTWCard
7
+ * @since 4.0.0
8
+ * @see 参考 {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
9
+ * @param {*} value 要检测的值
10
+ * @param {Object} [options] 配置项
11
+ * @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
12
+ * @returns {boolean} 是否为台湾居民来往大陆通行证
13
+ * @example
14
+ * isTWCard('12345678') // true
15
+ * isTWCard('07257456') // true
16
+ *
17
+ * // 一次性短期
18
+ * isTWCard('F290299977') // false
19
+ * isTWCard('F290299977', { loose: true }) // true
20
+ */
21
+ declare function isTWCard(value: any, { loose }?: {
22
+ loose?: boolean | undefined;
23
+ } | undefined): boolean;
@@ -0,0 +1,25 @@
1
+ export default isTelephone;
2
+ /**
3
+ * 检测值是否为固定电话
4
+ *
5
+ * @static
6
+ * @alias module:Validator.isTelephone
7
+ * @since 1.1.0
8
+ * @param {*} value 要检测的值
9
+ * @returns {boolean} 值是否为固定电话
10
+ * @example
11
+ *
12
+ * isTelephone('22033212');
13
+ * // => true
14
+ *
15
+ * isTelephone('021-22033212');
16
+ * // => true
17
+ *
18
+ * isTelephone('021-22033212-123');
19
+ * // => true
20
+ *
21
+ * isTelephone('13000000000');
22
+ * // => false
23
+ *
24
+ */
25
+ declare function isTelephone(value: any): boolean;
@@ -0,0 +1,34 @@
1
+ export default isUrl;
2
+ /**
3
+ * 检测值是否为url
4
+ *
5
+ * @static
6
+ * @alias module:Validator.isUrl
7
+ * @since 3.4.0
8
+ * @see 参考 {@link https://zh.wikipedia.org/wiki/统一资源定位符|统一资源定位符}
9
+ * @param {*} value 要检测的值
10
+ * @returns {boolean} 值是否为url
11
+ * @example
12
+ *
13
+ * isUrl('');
14
+ * // => false
15
+ *
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
+ */
34
+ declare function isUrl(value: any): boolean;
@@ -0,0 +1,29 @@
1
+ export default isVehicle;
2
+ /**
3
+ * 检测值是否为车牌号,支持新能源和非新能源车牌
4
+ *
5
+ * @static
6
+ * @alias module:Validator.isVehicle
7
+ * @see 参考 {@link https://baike.baidu.com/item/车牌号|车牌号}
8
+ * @since 1.1.0
9
+ * @param {*} value 要检测的值
10
+ * @returns {boolean} 值是否为车牌号
11
+ * @example
12
+ *
13
+ * isVehicle('京L12345');
14
+ * // => true
15
+ *
16
+ * isVehicle('粤BD12345');
17
+ * // => true
18
+ *
19
+ * isVehicle('粤BF12345');
20
+ * // => true
21
+ *
22
+ * isVehicle('粤B12345D');
23
+ * // => true
24
+ *
25
+ * isVehicle('粤B12345F');
26
+ * // => true
27
+ *
28
+ */
29
+ declare function isVehicle(value: any): boolean;
@@ -0,0 +1,19 @@
1
+ export default isWX;
2
+ /**
3
+ * 检测值是否为微信号
4
+ *
5
+ * @static
6
+ * @alias module:Validator.isWX
7
+ * @since 1.1.0
8
+ * @param {*} value 要检测的值
9
+ * @returns {boolean} 值是否为微信号
10
+ * @example
11
+ *
12
+ * isWX('a12345');
13
+ * // => true
14
+ *
15
+ * isWX('123');
16
+ * // => false
17
+ *
18
+ */
19
+ declare function isWX(value: any): boolean;
@@ -0,0 +1,21 @@
1
+ export default minus;
2
+ /**
3
+ * 精确减法,支持多个数相减
4
+ *
5
+ * @static
6
+ * @alias module:Math.minus
7
+ * @since 3.1.0
8
+ * @param {...number|string} nums 相减的数
9
+ * @returns {number} 差
10
+ * @example
11
+ *
12
+ * minus(1, 0.9);
13
+ * // => 0.1
14
+ *
15
+ * minus(1, 0.9, 0.02);
16
+ * // => 0.08
17
+ *
18
+ * minus(1, 0.9, 0.02, 0.08);
19
+ * // => 0
20
+ */
21
+ declare function minus(...nums: (number | string)[]): number;
@@ -0,0 +1,22 @@
1
+ export default normalizeString;
2
+ /**
3
+ * 规整化字符串。如果值为 undefined 或 null 将转为空字符串,如果值不是字符串类型将转为字符串。
4
+ *
5
+ * @static
6
+ * @alias module:Processor.normalizeString
7
+ * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
8
+ * @since 4.3.0
9
+ * @param {*} value 待处理的值
10
+ * @returns {string} 规整化的值
11
+ * @example
12
+ * normalizeString(); // ''
13
+ * normalizeString(undefined); // ''
14
+ * normalizeString(void 0); // ''
15
+ * normalizeString(null); // ''
16
+ *
17
+ * normalizeString(true); // 'true'
18
+ * normalizeString(NaN); // 'NaN'
19
+ * normalizeString(1); // '1'
20
+ * normalizeString('a'); // 'a'
21
+ */
22
+ declare function normalizeString(value: any): string;
@@ -0,0 +1,57 @@
1
+ export default numberToChinese;
2
+ /**
3
+ * 数字转中文数字
4
+ * 不在安全数字 -9007199254740991~9007199254740991 内,处理会有异常
5
+ *
6
+ * @static
7
+ * @alias module:Processor.numberToChinese
8
+ * @since 1.2.0
9
+ * @param {number} num 数字
10
+ * @param {Object} [options] 配置项
11
+ * @param {boolean} [options.big5=false] 繁体
12
+ * @param {boolean} [options.unit=true] 计数单位
13
+ * @param {string} [options.decimal="点"] 中文小数点
14
+ * @param {string} [options.zero="零"] 设置0。常用配置 〇
15
+ * @param {string} [options.negative="负"] 负数前面的字
16
+ * @param {Object} [options.unitConfig] 节点单位配置
17
+ * @param {string} [options.unitConfig.w="万"] 设置计数单位万。常用配置 萬
18
+ * @param {string} [options.unitConfig.y="亿"] 设置计数单位亿。常用配置 億
19
+ * @returns {string} 中文数字
20
+ * @example
21
+ *
22
+ * numberToChinese(100);
23
+ * // => 一百
24
+ *
25
+ * numberToChinese(100.3);
26
+ * // => 一百点三
27
+ *
28
+ * // 繁体
29
+ * numberToChinese(100, {big5: true});
30
+ * // => 壹佰
31
+ *
32
+ * numberToChinese(100.3, {big5: true});
33
+ * // => 壹佰点叁
34
+ *
35
+ * numberToChinese(1234567890, {big5: true});
36
+ * // => 壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾
37
+ *
38
+ * // 不带计数单位
39
+ * numberToChinese(1990, {unit: false});
40
+ * // => 一九九零
41
+ *
42
+ * // 不带计数单位,修改0
43
+ * numberToChinese(1990, {unit: false, zero:'〇'});
44
+ * // => 一九九〇
45
+ *
46
+ */
47
+ declare function numberToChinese(num: number, { big5, unit, decimal, zero, negative, unitConfig }?: {
48
+ big5?: boolean | undefined;
49
+ unit?: boolean | undefined;
50
+ decimal?: string | undefined;
51
+ zero?: string | undefined;
52
+ negative?: string | undefined;
53
+ unitConfig?: {
54
+ w?: string | undefined;
55
+ y?: string | undefined;
56
+ } | undefined;
57
+ } | undefined): string;
@@ -0,0 +1,24 @@
1
+ export default padZero;
2
+ /**
3
+ * 前置补零
4
+ *
5
+ * @static
6
+ * @alias module:Processor.padZero
7
+ * @since 4.7.0
8
+ * @param {string|number} value 要处理的值
9
+ * @param {number} [size=2] 指定字符串长度
10
+ * @returns {string} 用零填充数字到给定长度的字符串
11
+ * @example
12
+ * padZero(5); // '05'
13
+ * padZero('5'); // '05'
14
+ *
15
+ * padZero(12); // '12'
16
+ * padZero('12'); // '12'
17
+ *
18
+ * padZero(688); // '688'
19
+ * padZero('688'); // '688'
20
+ *
21
+ * padZero(688, 5); // '00688'
22
+ * padZero('688', 5); // '00688'
23
+ */
24
+ declare function padZero(value: string | number, size?: number | undefined): string;
@@ -0,0 +1,107 @@
1
+ export default parseIdCard;
2
+ /**
3
+ * - 解析身份证原数据
4
+ */
5
+ export type IdCardOrigin = {
6
+ /**
7
+ * - 省份编码
8
+ */
9
+ province: string;
10
+ /**
11
+ * - 城市编码
12
+ */
13
+ city: string;
14
+ /**
15
+ * - 地区编码
16
+ */
17
+ area: string;
18
+ /**
19
+ * - 出生年
20
+ */
21
+ year: string;
22
+ /**
23
+ * - 出生月
24
+ */
25
+ month: string;
26
+ /**
27
+ * - 出生日
28
+ */
29
+ day: string;
30
+ /**
31
+ * - 性别 能整除2为女,否则为男
32
+ */
33
+ gender: string;
34
+ };
35
+ /**
36
+ * - 身份证信息
37
+ */
38
+ export type IdCardInfo = {
39
+ /**
40
+ * - 省份
41
+ */
42
+ province: string;
43
+ /**
44
+ * - 生日
45
+ */
46
+ birthday: string;
47
+ /**
48
+ * - 性别
49
+ */
50
+ gender: string;
51
+ /**
52
+ * - 解析身份证原数据
53
+ */
54
+ origin: IdCardOrigin;
55
+ };
56
+ /**
57
+ * @typedef {Object} IdCardOrigin - 解析身份证原数据
58
+ * @property {string} province - 省份编码
59
+ * @property {string} city - 城市编码
60
+ * @property {string} area - 地区编码
61
+ * @property {string} year - 出生年
62
+ * @property {string} month - 出生月
63
+ * @property {string} day - 出生日
64
+ * @property {string} gender - 性别 能整除2为女,否则为男
65
+ */
66
+ /**
67
+ * @typedef {Object} IdCardInfo - 身份证信息
68
+ * @property {string} province - 省份
69
+ * @property {string} birthday - 生日
70
+ * @property {string} gender - 性别
71
+ * @property {IdCardOrigin} origin - 解析身份证原数据
72
+ */
73
+ /**
74
+ * 解析身份证号码,支持15、18位身份证号码
75
+ *
76
+ * @static
77
+ * @alias module:Processor.parseIdCard
78
+ * @since 4.0.0
79
+ * @see 参考 {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
80
+ * @param {string} id 身份证号码,支持15位
81
+ * @returns {null|IdCardInfo} null 或 省份、生日、性别,省/市/区/年/月/日/性别编码
82
+ * @example
83
+ * parseIdCard('123456789123456');
84
+ * // => null
85
+ *
86
+ * // 18位身份证号码
87
+ * parseIdCard('130701199310302288')
88
+ * // =>
89
+ * {
90
+ * birthday: "1993-10-30",
91
+ * gender: "女",
92
+ * origin: { province: "13", city: "07", area: "01", year: "1993", month: "10", day: "30", gender: "8" },
93
+ * province: "河北省"
94
+ * }
95
+ *
96
+ * // 15位身份证号码
97
+ * parseIdCard('130701931030228');
98
+ * // =>
99
+ * {
100
+ * birthday: "93-10-30",
101
+ * gender: "女",
102
+ * origin: { province: "13", city: "07", area: "01", year: "93", month: "10", day: "30", gender: "8" },
103
+ * province: "河北省"
104
+ * }
105
+ *
106
+ */
107
+ declare function parseIdCard(id: string): null | IdCardInfo;
@@ -0,0 +1,21 @@
1
+ export default plus;
2
+ /**
3
+ * 精确加法,支持多个数相加
4
+ *
5
+ * @static
6
+ * @alias module:Math.plus
7
+ * @since 3.1.0
8
+ * @param {...number|string} nums 相加的数
9
+ * @returns {number} 总和
10
+ * @example
11
+ *
12
+ * plus(0.1, 0.2);
13
+ * // => 0.3
14
+ *
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
+ */
21
+ declare function plus(...nums: (number | string)[]): number;
@@ -0,0 +1,19 @@
1
+ export default randomString;
2
+ /**
3
+ * 生成随机字符串
4
+ *
5
+ * @static
6
+ * @alias module:Other.randomString
7
+ * @since 4.8.0
8
+ * @param {number} [len=0] 长度
9
+ * @param {string} [optionalChars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'] 允许的字符,默认为数字和大小写字母
10
+ * @returns {string} 随机字符串
11
+ * @example
12
+ * randomString(5); // slk23
13
+ * randomString(8); // 71mHqo2A
14
+ *
15
+ * // 自定义允许的字符
16
+ * randomString(5, 'abc'); // ccbcb
17
+ * randomString(8, 'abcefg'); // bcgcfabg
18
+ */
19
+ declare function randomString(len?: number | undefined, optionalChars?: string | undefined): string;
@@ -0,0 +1,54 @@
1
+ export default replaceChar;
2
+ /**
3
+ * 替换字符,应用场景如:脱敏
4
+ *
5
+ * @static
6
+ * @alias module:Processor.replaceChar
7
+ * @since 1.1.0
8
+ * @param {string} str 要处理的字符串
9
+ * @param {Object} [options] 配置项
10
+ * @param {number} [options.start=3] 开始位置
11
+ * @param {number} [options.end=-4] 结束位置
12
+ * @param {string} [options.char="*"] 替换字符
13
+ * @param {number} [options.repeat] 替换字符的重复次数,默认为替换内容长度,可设置为固定值
14
+ * @param {string} [options.exclude] 排除字符,如果指定排除项,repeat设置无效
15
+ * @returns {string} 处理后的字符
16
+ * @example
17
+ *
18
+ * // 手机号
19
+ * replaceChar('13000000000');
20
+ * // => 130****0000
21
+ *
22
+ * // 身份证
23
+ * replaceChar('130701199310302288');
24
+ * // => 130***********2288
25
+ *
26
+ * // 邮箱
27
+ * const email = '12345@qq.com'
28
+ * replaceChar(email, {start: 2, end: email.indexOf('@'), repeat: 4});
29
+ * // => 12****@qq.com
30
+ *
31
+ * // 银行卡号
32
+ * replaceChar('6228480402564890018', {start: 0, end: -4, repeat: 4});
33
+ * // => ****0018
34
+ *
35
+ * // 带格式的银行卡号
36
+ * replaceChar('6228 4804 0256 4890 018', {start: 4, end: -4, exclude: ' '});
37
+ * // => 6228 **** **** **** 018
38
+ *
39
+ * // 用户名
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
+ * // => 林**
46
+ *
47
+ */
48
+ declare function replaceChar(str: string, { start, end, char, repeat, exclude }?: {
49
+ start?: number | undefined;
50
+ end?: number | undefined;
51
+ char?: string | undefined;
52
+ repeat?: number | undefined;
53
+ exclude?: string | undefined;
54
+ } | undefined): string;
@@ -0,0 +1,22 @@
1
+ export default round;
2
+ /**
3
+ * 四舍五入,支持设置精度
4
+ *
5
+ * @static
6
+ * @alias module:Math.round
7
+ * @since 3.1.0
8
+ * @param {number|string} num 要四舍五入的数字
9
+ * @param {number} [precision=0] 四舍五入的精度
10
+ * @returns {number} 四舍五入的数字
11
+ * @example
12
+ *
13
+ * round(4.006);
14
+ * // => 4
15
+ *
16
+ * round(4.006, 2);
17
+ * // => 4.01
18
+ *
19
+ * round(4060, -2);
20
+ * // => 4100
21
+ */
22
+ declare function round(num: number | string, precision?: number | undefined): number;
@@ -0,0 +1,22 @@
1
+ export default safeDate;
2
+ /**
3
+ * 创建一个 Date 实例日期对象,同 new Date() 。<br/>
4
+ * 规避了苹果设备浏览器不支持部分格式(YYYY-MM-DD HH-mm 或 YYYY.MM.DD)。
5
+ *
6
+ * @static
7
+ * @alias module:Processor.safeDate
8
+ * @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date|Date}
9
+ * @since 4.4.0
10
+ * @param {string|number|Date} [value] 日期时间字符串、毫秒数、日期对象
11
+ * @param {...number} args 月/日/时/分/秒/毫秒
12
+ * @returns {Date} Date 实例日期对象
13
+ * @example
14
+ * safeDate('2022-1-1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
15
+ * safeDate('2022/1/1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
16
+ * safeDate('2022.1.1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
17
+ * safeDate('2022.1.1 11:11'); // Sat Jan 01 2022 11:11:00 GMT+0800 (中国标准时间)
18
+ * safeDate(99, 1); // Mon Feb 01 1999 00:00:00 GMT+0800 (中国标准时间)
19
+ * safeDate(1646711233171); // Tue Mar 08 2022 11:47:13 GMT+0800 (中国标准时间)
20
+ *
21
+ */
22
+ declare function safeDate(value?: string | number | Date | undefined, ...args: number[]): Date;