util-helpers 4.11.1 → 4.12.2

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 (93) hide show
  1. package/dist/util-helpers.js +106 -71
  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/divide.js +6 -6
  6. package/esm/index.js +35 -1
  7. package/esm/minus.js +6 -6
  8. package/esm/plus.js +6 -6
  9. package/esm/round.js +4 -5
  10. package/esm/times.js +6 -6
  11. package/esm/utils/config.js +2 -1
  12. package/esm/utils/math.util.js +30 -0
  13. package/lib/divide.js +5 -6
  14. package/lib/index.js +6 -0
  15. package/lib/minus.js +5 -6
  16. package/lib/plus.js +5 -6
  17. package/lib/round.js +4 -5
  18. package/lib/times.js +5 -6
  19. package/lib/utils/config.js +3 -1
  20. package/lib/utils/math.util.js +33 -0
  21. package/package.json +3 -1
  22. package/types/src/blobToDataURL.d.ts +25 -0
  23. package/types/src/bytesToSize.d.ts +24 -0
  24. package/types/src/calculateCursorPosition.d.ts +26 -0
  25. package/types/src/dataURLToBlob.d.ts +15 -0
  26. package/types/src/divide.d.ts +21 -0
  27. package/types/src/formatBankCard.d.ts +35 -0
  28. package/types/src/formatMobile.d.ts +27 -0
  29. package/types/src/formatMoney.d.ts +50 -0
  30. package/types/src/index.d.ts +45 -0
  31. package/types/src/isBankCard.d.ts +32 -0
  32. package/types/src/isBusinessLicense.d.ts +29 -0
  33. package/types/src/isChinese.d.ts +41 -0
  34. package/types/src/isEmail.d.ts +19 -0
  35. package/types/src/isHMCard.d.ts +24 -0
  36. package/types/src/isIPv4.d.ts +25 -0
  37. package/types/src/isIPv6.d.ts +50 -0
  38. package/types/src/isIdCard.d.ts +34 -0
  39. package/types/src/isMobile.d.ts +19 -0
  40. package/types/src/isPassport.d.ts +21 -0
  41. package/types/src/isPassword.d.ts +46 -0
  42. package/types/src/isPostcode.d.ts +19 -0
  43. package/types/src/isPromiseLike.d.ts +21 -0
  44. package/types/src/isQQ.d.ts +19 -0
  45. package/types/src/isSocialCreditCode.d.ts +31 -0
  46. package/types/src/isSwiftCode.d.ts +22 -0
  47. package/types/src/isTWCard.d.ts +23 -0
  48. package/types/src/isTelephone.d.ts +25 -0
  49. package/types/src/isUrl.d.ts +34 -0
  50. package/types/src/isVehicle.d.ts +29 -0
  51. package/types/src/isWX.d.ts +19 -0
  52. package/types/src/minus.d.ts +21 -0
  53. package/types/src/normalizeString.d.ts +22 -0
  54. package/types/src/numberToChinese.d.ts +57 -0
  55. package/types/src/padZero.d.ts +24 -0
  56. package/types/src/parseIdCard.d.ts +107 -0
  57. package/types/src/plus.d.ts +21 -0
  58. package/types/src/randomString.d.ts +19 -0
  59. package/types/src/replaceChar.d.ts +54 -0
  60. package/types/src/round.d.ts +22 -0
  61. package/types/src/safeDate.d.ts +22 -0
  62. package/types/src/setDataURLPrefix.d.ts +24 -0
  63. package/types/src/strlen.d.ts +20 -0
  64. package/types/src/times.d.ts +21 -0
  65. package/types/src/utils/config.d.ts +13 -0
  66. package/types/src/utils/constants.d.ts +2 -0
  67. package/types/src/utils/convertToString.d.ts +8 -0
  68. package/types/src/utils/devWarn.d.ts +7 -0
  69. package/types/src/utils/math.util.d.ts +63 -0
  70. package/types/src/utils/type/index.d.ts +19 -0
  71. package/types/src/utils/type/isArguments.d.ts +18 -0
  72. package/types/src/utils/type/isArray.d.ts +18 -0
  73. package/types/src/utils/type/isBoolean.d.ts +18 -0
  74. package/types/src/utils/type/isDate.d.ts +18 -0
  75. package/types/src/utils/type/isError.d.ts +18 -0
  76. package/types/src/utils/type/isFunction.d.ts +18 -0
  77. package/types/src/utils/type/isMap.d.ts +18 -0
  78. package/types/src/utils/type/isNaN.d.ts +18 -0
  79. package/types/src/utils/type/isNil.d.ts +11 -0
  80. package/types/src/utils/type/isNull.d.ts +18 -0
  81. package/types/src/utils/type/isNumber.d.ts +27 -0
  82. package/types/src/utils/type/isObject.d.ts +21 -0
  83. package/types/src/utils/type/isRegExp.d.ts +18 -0
  84. package/types/src/utils/type/isSet.d.ts +18 -0
  85. package/types/src/utils/type/isString.d.ts +18 -0
  86. package/types/src/utils/type/isSymbol.d.ts +18 -0
  87. package/types/src/utils/type/isType.d.ts +11 -0
  88. package/types/src/utils/type/isUndefined.d.ts +21 -0
  89. package/types/src/utils/type/isWeakMap.d.ts +18 -0
  90. package/types/src/utils/type/isWeakSet.d.ts +18 -0
  91. package/types/src/validatePassword.d.ts +134 -0
  92. package/types/src/waitTime.d.ts +20 -0
  93. package/types/utils/math.util.d.ts +7 -0
@@ -0,0 +1,18 @@
1
+ export default isDate;
2
+ /**
3
+ * 检查值是否为Date
4
+ *
5
+ * @static
6
+ * @alias module:Type.isDate
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为Date
10
+ * @example
11
+ *
12
+ * isDate(new Date)
13
+ * // => true
14
+ *
15
+ * isDate('Mon April 23 2012')
16
+ * // => false
17
+ */
18
+ declare function isDate(value: any): boolean;
@@ -0,0 +1,18 @@
1
+ export default isError;
2
+ /**
3
+ * 检查值是否为Error、EvalError、RangeError、ReferenceError、SyntaxError、TypeError、URIError|DOMException
4
+ *
5
+ * @static
6
+ * @alias module:Type.isError
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为Error、EvalError、RangeError、ReferenceError、SyntaxError、TypeError、URIError|DOMException
10
+ * @example
11
+ *
12
+ * isError(new Error)
13
+ * // => true
14
+ *
15
+ * isError(Error)
16
+ * // => false
17
+ */
18
+ declare function isError(value: any): boolean;
@@ -0,0 +1,18 @@
1
+ export default isFunction;
2
+ /**
3
+ * 检查值是否为Function|AsyncFunction|GeneratorFunction|Proxy
4
+ *
5
+ * @static
6
+ * @alias module:Type.isFunction
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为Function|AsyncFunction|GeneratorFunction|Proxy
10
+ * @example
11
+ *
12
+ * isFunction(()=>{}))
13
+ * // => true
14
+ *
15
+ * isFunction(/abc/)
16
+ * // => false
17
+ */
18
+ declare function isFunction(value: any): boolean;
@@ -0,0 +1,18 @@
1
+ export default isMap;
2
+ /**
3
+ * 检查值是否为Map
4
+ *
5
+ * @static
6
+ * @alias module:Type.isMap
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为Map
10
+ * @example
11
+ *
12
+ * isMap(new Map)
13
+ * // => true
14
+ *
15
+ * isMap(new WeakMap)
16
+ * // => false
17
+ */
18
+ declare function isMap(value: any): boolean;
@@ -0,0 +1,18 @@
1
+ export default _isNaN;
2
+ /**
3
+ * 检查值是否为NaN
4
+ *
5
+ * @static
6
+ * @alias module:Type.isNaN
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为NaN
10
+ * @example
11
+ *
12
+ * isNaN(NaN)
13
+ * // => true
14
+ *
15
+ * isNaN(1)
16
+ * // => false
17
+ */
18
+ declare function _isNaN(value: any): boolean;
@@ -0,0 +1,11 @@
1
+ export default isNil;
2
+ /**
3
+ * 检查值是否为 undefined 或 null
4
+ *
5
+ * @static
6
+ * @alias module:Type.isNaN
7
+ * @since 4.3.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为 undefined 或 null
10
+ */
11
+ declare function isNil(value: any): boolean;
@@ -0,0 +1,18 @@
1
+ export default isNull;
2
+ /**
3
+ * 检查值是否为Null
4
+ *
5
+ * @static
6
+ * @alias module:Type.isNull
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为Null
10
+ * @example
11
+ *
12
+ * isNull(null)
13
+ * // => true
14
+ *
15
+ * isNull(void 0)
16
+ * // => false
17
+ */
18
+ declare function isNull(value: any): boolean;
@@ -0,0 +1,27 @@
1
+ export default isNumber;
2
+ /**
3
+ * 检查值是否为Number
4
+ *
5
+ * @static
6
+ * @alias module:Type.isNumber
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为Number
10
+ * @example
11
+ *
12
+ * isNumber(1)
13
+ * // => true
14
+ *
15
+ * isNumber(Number.MIN_VALUE)
16
+ * // => true
17
+ *
18
+ * isNumber(Infinity)
19
+ * // => true
20
+ *
21
+ * isNumber(NaN)
22
+ * // => true
23
+ *
24
+ * isNumber('1')
25
+ * // => false
26
+ */
27
+ declare function isNumber(value: any): boolean;
@@ -0,0 +1,21 @@
1
+ export default isObject;
2
+ /**
3
+ * 检查值是否为Object
4
+ *
5
+ * @static
6
+ * @alias module:Type.isObject
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为Object
10
+ * @example
11
+ *
12
+ * isObject({})
13
+ * // => true
14
+ *
15
+ * isObject([1,2,3])
16
+ * // => true
17
+ *
18
+ * isObject(null)
19
+ * // => false
20
+ */
21
+ declare function isObject(value: any): boolean;
@@ -0,0 +1,18 @@
1
+ export default isRegExp;
2
+ /**
3
+ * 检查值是否为RegExp
4
+ *
5
+ * @static
6
+ * @alias module:Type.isRegExp
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为RegExp
10
+ * @example
11
+ *
12
+ * isRegExp(/abc/)
13
+ * // => true
14
+ *
15
+ * isRegExp('/abc/')
16
+ * // => false
17
+ */
18
+ declare function isRegExp(value: any): boolean;
@@ -0,0 +1,18 @@
1
+ export default isSet;
2
+ /**
3
+ * 检查值是否为Set
4
+ *
5
+ * @static
6
+ * @alias module:Type.isSet
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为Set
10
+ * @example
11
+ *
12
+ * isSet(new Set)
13
+ * // => true
14
+ *
15
+ * isSet(new WeakSet)
16
+ * // => false
17
+ */
18
+ declare function isSet(value: any): boolean;
@@ -0,0 +1,18 @@
1
+ export default isString;
2
+ /**
3
+ * 检查值是否为String
4
+ *
5
+ * @static
6
+ * @alias module:Type.isString
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为String
10
+ * @example
11
+ *
12
+ * isString('abc')
13
+ * // => true
14
+ *
15
+ * isString(1)
16
+ * // => false
17
+ */
18
+ declare function isString(value: any): boolean;
@@ -0,0 +1,18 @@
1
+ export default isSymbol;
2
+ /**
3
+ * 检查值是否为Symbol
4
+ *
5
+ * @static
6
+ * @alias module:Type.isSymbol
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为Symbol
10
+ * @example
11
+ *
12
+ * isSymbol(Symbol.iterator)
13
+ * // => true
14
+ *
15
+ * isSymbol("abc")
16
+ * // => false
17
+ */
18
+ declare function isSymbol(value: any): boolean;
@@ -0,0 +1,11 @@
1
+ export default isType;
2
+ /**
3
+ * 检测值的 `toString` 类型
4
+ *
5
+ * @private
6
+ * @since 1.1.0
7
+ * @param {*} value 检查值
8
+ * @param {string} typename 类型名称
9
+ * @returns {boolean} 返回值的 `toString` 类型是否匹配
10
+ */
11
+ declare function isType(value: any, typename: string): boolean;
@@ -0,0 +1,21 @@
1
+ export default isUndefined;
2
+ /**
3
+ * 检查值是否为Undefined
4
+ *
5
+ * @static
6
+ * @alias module:Type.isUndefined
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为Undefined
10
+ * @example
11
+ *
12
+ * isUndefined(undefined)
13
+ * // => true
14
+ *
15
+ * isUndefined(void 0)
16
+ * // => true
17
+ *
18
+ * isUndefined(null)
19
+ * // => false
20
+ */
21
+ declare function isUndefined(value: any): boolean;
@@ -0,0 +1,18 @@
1
+ export default isWeakMap;
2
+ /**
3
+ * 检查值是否为WeakMap
4
+ *
5
+ * @static
6
+ * @alias module:Type.isWeakMap
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为WeakMap
10
+ * @example
11
+ *
12
+ * isWeakMap(new WeakMap)
13
+ * // => true
14
+ *
15
+ * isWeakMap(new Map)
16
+ * // => false
17
+ */
18
+ declare function isWeakMap(value: any): boolean;
@@ -0,0 +1,18 @@
1
+ export default isWeakSet;
2
+ /**
3
+ * 检查值是否为WeakSet
4
+ *
5
+ * @static
6
+ * @alias module:Type.isWeakSet
7
+ * @since 1.1.0
8
+ * @param {*} value 检查值
9
+ * @returns {boolean} 是否为WeakSet
10
+ * @example
11
+ *
12
+ * isWeakSet(new WeakSet)
13
+ * // => true
14
+ *
15
+ * isWeakSet(new Set)
16
+ * // => false
17
+ */
18
+ declare function isWeakSet(value: any): boolean;
@@ -0,0 +1,134 @@
1
+ export default validatePassword;
2
+ /**
3
+ * - 验证密码的包含内容
4
+ */
5
+ export type PasswordContaines = {
6
+ /**
7
+ * - 包含数字
8
+ */
9
+ number: boolean;
10
+ /**
11
+ * - 包含小写字母
12
+ */
13
+ lowerCaseLetter: boolean;
14
+ /**
15
+ * - 包含大写字母
16
+ */
17
+ upperCaseLetter: boolean;
18
+ /**
19
+ * - 包含特殊字符
20
+ */
21
+ specialCharacter: boolean;
22
+ /**
23
+ * - 包含非法字符
24
+ */
25
+ unallowableCharacter: boolean;
26
+ };
27
+ /**
28
+ * - 验证结果
29
+ */
30
+ export type ValidatePasswordReturn = {
31
+ /**
32
+ * - 验证结果,根据密码强度、是否包含非法字符得出
33
+ */
34
+ validated: boolean;
35
+ /**
36
+ * - 强度级别,包含数字/大小写字母/特殊字符
37
+ */
38
+ level: number;
39
+ /**
40
+ * - 包含内容
41
+ */
42
+ containes: PasswordContaines;
43
+ };
44
+ /**
45
+ * @typedef {Object} PasswordContaines - 验证密码的包含内容
46
+ * @property {boolean} number - 包含数字
47
+ * @property {boolean} lowerCaseLetter - 包含小写字母
48
+ * @property {boolean} upperCaseLetter - 包含大写字母
49
+ * @property {boolean} specialCharacter - 包含特殊字符
50
+ * @property {boolean} unallowableCharacter - 包含非法字符
51
+ */
52
+ /**
53
+ * @typedef {Object} ValidatePasswordReturn - 验证结果
54
+ * @property {boolean} validated - 验证结果,根据密码强度、是否包含非法字符得出
55
+ * @property {number} level - 强度级别,包含数字/大小写字母/特殊字符
56
+ * @property {PasswordContaines} containes - 包含内容
57
+ */
58
+ /**
59
+ * 验证密码(数字、大小写字母、特殊字符、非法字符)
60
+ *
61
+ * @see 参考 {@link https://baike.baidu.com/item/ASCII#3|ASCII}
62
+ * @static
63
+ * @alias module:Validator.validatePassword
64
+ * @since 3.7.0
65
+ * @param {string} value 要检测的值
66
+ * @param {Object} [options] 配置项
67
+ * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
68
+ * @param {boolean} [options.ignoreCase=false] 是否忽略大小写,为 ture 时,大小写字母视为一种字符
69
+ * @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符
70
+ * @returns {ValidatePasswordReturn} 验证结果
71
+ * @example
72
+ *
73
+ * validatePassword('a12345678');
74
+ * // =>
75
+ * {
76
+ * validated: true, // 验证结果,根据密码强度、是否包含非法字符得出
77
+ * level: 2, // 强度级别
78
+ * containes: {
79
+ * number: true, // 包含数字
80
+ * lowerCaseLetter: true, // 包含小写字母
81
+ * upperCaseLetter: false, // 包含大写字母
82
+ * specialCharacter: false, // 包含特殊字符
83
+ * unallowableCharacter: false // 包含非法字符
84
+ * }
85
+ * }
86
+ *
87
+ * validatePassword('a12345678', { level: 3 });
88
+ * // =>
89
+ * {
90
+ * validated: false,
91
+ * level: 2,
92
+ * containes: {
93
+ * number: true,
94
+ * lowerCaseLetter: true,
95
+ * upperCaseLetter: false,
96
+ * specialCharacter: false,
97
+ * unallowableCharacter: false
98
+ * }
99
+ * }
100
+ *
101
+ * validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true });
102
+ * // =>
103
+ * {
104
+ * validated: false,
105
+ * level: 3,
106
+ * containes: {
107
+ * number: true,
108
+ * lowerCaseLetter: true,
109
+ * upperCaseLetter: true,
110
+ * specialCharacter: true,
111
+ * unallowableCharacter: true
112
+ * }
113
+ * }
114
+ *
115
+ * // 自定义特殊字符
116
+ * validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true, special: '_一二三' });
117
+ * // =>
118
+ * {
119
+ * validated: true,
120
+ * level: 3,
121
+ * containes: {
122
+ * number: true,
123
+ * lowerCaseLetter: true,
124
+ * upperCaseLetter: true,
125
+ * specialCharacter: true,
126
+ * unallowableCharacter: false
127
+ * }
128
+ * }
129
+ */
130
+ declare function validatePassword(value: string, { level, ignoreCase, special }?: {
131
+ level?: number | undefined;
132
+ ignoreCase?: boolean | undefined;
133
+ special?: string | undefined;
134
+ } | undefined): ValidatePasswordReturn;
@@ -0,0 +1,20 @@
1
+ export default waitTime;
2
+ /**
3
+ * 等待时间返回 Promise 。常用于异步方法中延时。
4
+ *
5
+ * @static
6
+ * @alias module:Other.waitTime
7
+ * @since 4.2.0
8
+ * @param {number} [time=1000] 延时时间,单位毫秒
9
+ * @returns {Promise<void>}
10
+ * @example
11
+ * const test = async ()=>{
12
+ * await waitTime();
13
+ * // do something
14
+ * }
15
+ *
16
+ * waitTime(500).then(()=>{
17
+ * // do something
18
+ * })
19
+ */
20
+ declare function waitTime(time?: number | undefined): Promise<void>;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * 值是否为有效的数值
3
+ *
4
+ * @param {*} value 待检测的值
5
+ * @returns {boolean} 是否为有效的数值
6
+ */
7
+ export function isEffectiveNumeric(value: any): boolean;
1
8
  /**
2
9
  * 是否为科学计数法数字
3
10
  *