util-helpers 4.10.3 → 4.12.0
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.
- package/dist/util-helpers.js +1076 -668
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/bytesToSize.js +4 -3
- package/esm/divide.js +6 -6
- package/esm/formatMoney.js +7 -10
- package/esm/index.js +32 -0
- package/esm/isBusinessLicense.js +2 -2
- package/esm/isChinese.js +24 -11
- package/esm/minus.js +6 -6
- package/esm/numberToChinese.js +30 -36
- package/esm/parseIdCard.js +9 -24
- package/esm/plus.js +6 -6
- package/esm/replaceChar.js +8 -7
- package/esm/round.js +7 -0
- package/esm/times.js +6 -6
- package/esm/utils/devWarn.js +16 -0
- package/esm/utils/math.util.js +82 -29
- package/esm/validatePassword.js +25 -20
- package/lib/bytesToSize.js +4 -3
- package/lib/divide.js +5 -6
- package/lib/formatMoney.js +7 -10
- package/lib/isBusinessLicense.js +2 -2
- package/lib/isChinese.js +24 -11
- package/lib/minus.js +5 -6
- package/lib/numberToChinese.js +32 -36
- package/lib/parseIdCard.js +9 -24
- package/lib/plus.js +5 -6
- package/lib/replaceChar.js +11 -8
- package/lib/round.js +8 -0
- package/lib/times.js +5 -6
- package/lib/utils/devWarn.js +24 -0
- package/lib/utils/math.util.js +87 -29
- package/lib/validatePassword.js +27 -20
- package/package.json +4 -2
- package/types/isChinese.d.ts +13 -3
- package/types/replaceChar.d.ts +1 -1
- package/types/utils/devWarn.d.ts +7 -0
- package/types/utils/math.util.d.ts +9 -2
- package/types/validatePassword.d.ts +3 -3
package/lib/plus.js
CHANGED
|
@@ -9,8 +9,6 @@ var _math = require("./utils/math.util");
|
|
|
9
9
|
|
|
10
10
|
var _times = _interopRequireDefault(require("./times"));
|
|
11
11
|
|
|
12
|
-
var _type = require("./utils/type");
|
|
13
|
-
|
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
13
|
|
|
16
14
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
@@ -55,12 +53,13 @@ function plus() {
|
|
|
55
53
|
|
|
56
54
|
if (rest.length > 0) {
|
|
57
55
|
return plus.apply(void 0, [plus(num1, num2)].concat(_toConsumableArray(rest)));
|
|
58
|
-
} //
|
|
56
|
+
} // 兼容处理,如果参数包含无效数值时,尝试取出有效数值参数
|
|
59
57
|
|
|
60
58
|
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
if (!(0, _math.isEffectiveNumeric)(num1)) {
|
|
60
|
+
return (0, _math.isEffectiveNumeric)(num2) ? Number(num2) : NaN;
|
|
61
|
+
} else if (!(0, _math.isEffectiveNumeric)(num2)) {
|
|
62
|
+
return Number(num1);
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
var baseNum = Math.pow(10, Math.max((0, _math.digitLength)(num1), (0, _math.digitLength)(num2)));
|
package/lib/replaceChar.js
CHANGED
|
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
|
|
8
|
+
var _normalizeString = _interopRequireDefault(require("./normalizeString"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* 替换字符,应用场景如:脱敏
|
|
10
14
|
*
|
|
@@ -51,9 +55,7 @@ exports["default"] = void 0;
|
|
|
51
55
|
* // => 林**
|
|
52
56
|
*
|
|
53
57
|
*/
|
|
54
|
-
function replaceChar() {
|
|
55
|
-
var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
56
|
-
|
|
58
|
+
function replaceChar(str) {
|
|
57
59
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
58
60
|
_ref$start = _ref.start,
|
|
59
61
|
start = _ref$start === void 0 ? 3 : _ref$start,
|
|
@@ -64,20 +66,21 @@ function replaceChar() {
|
|
|
64
66
|
repeat = _ref.repeat,
|
|
65
67
|
exclude = _ref.exclude;
|
|
66
68
|
|
|
67
|
-
var
|
|
69
|
+
var realStr = (0, _normalizeString["default"])(str);
|
|
70
|
+
var strLen = realStr.length; // 开始位置超过str长度
|
|
68
71
|
|
|
69
72
|
if (Math.abs(start) >= strLen) {
|
|
70
|
-
return
|
|
73
|
+
return realStr;
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
start = start >= 0 ? start : strLen + start;
|
|
74
77
|
end = end >= 0 ? end : strLen + end; // 开始位置大于结束位置
|
|
75
78
|
|
|
76
79
|
if (start >= end) {
|
|
77
|
-
return
|
|
80
|
+
return realStr;
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
var middleStr =
|
|
83
|
+
var middleStr = realStr.substring(start, end);
|
|
81
84
|
|
|
82
85
|
if (exclude) {
|
|
83
86
|
var reg = new RegExp("[^".concat(exclude, "]"), 'g');
|
|
@@ -87,7 +90,7 @@ function replaceChar() {
|
|
|
87
90
|
middleStr = _char.repeat(repeat);
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
return
|
|
93
|
+
return realStr.substring(0, start) + middleStr + realStr.substring(end);
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
var _default = replaceChar;
|
package/lib/round.js
CHANGED
|
@@ -9,6 +9,8 @@ var _divide = _interopRequireDefault(require("./divide"));
|
|
|
9
9
|
|
|
10
10
|
var _times = _interopRequireDefault(require("./times"));
|
|
11
11
|
|
|
12
|
+
var _math = require("./utils/math.util");
|
|
13
|
+
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -33,6 +35,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
33
35
|
*/
|
|
34
36
|
function round(num) {
|
|
35
37
|
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
38
|
+
|
|
39
|
+
// 兼容处理,如果参数包含无效数值时,返回第一个参数
|
|
40
|
+
if (!(0, _math.isEffectiveNumeric)(num)) {
|
|
41
|
+
return NaN;
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
var base = Math.pow(10, precision);
|
|
37
45
|
return (0, _divide["default"])(Math.round((0, _times["default"])(num, base)), base);
|
|
38
46
|
}
|
package/lib/times.js
CHANGED
|
@@ -7,8 +7,6 @@ exports["default"] = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _math = require("./utils/math.util");
|
|
9
9
|
|
|
10
|
-
var _type = require("./utils/type");
|
|
11
|
-
|
|
12
10
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
13
11
|
|
|
14
12
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -51,12 +49,13 @@ function times() {
|
|
|
51
49
|
|
|
52
50
|
if (rest.length > 0) {
|
|
53
51
|
return times.apply(void 0, [times(num1, num2)].concat(_toConsumableArray(rest)));
|
|
54
|
-
} //
|
|
52
|
+
} // 兼容处理,如果参数包含无效数值时,尝试取出有效数值参数
|
|
55
53
|
|
|
56
54
|
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
if (!(0, _math.isEffectiveNumeric)(num1)) {
|
|
56
|
+
return (0, _math.isEffectiveNumeric)(num2) ? Number(num2) : NaN;
|
|
57
|
+
} else if (!(0, _math.isEffectiveNumeric)(num2)) {
|
|
58
|
+
return Number(num1);
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
var num1Changed = (0, _math.float2Fixed)(num1);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _config = require("./config");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 打印警告信息
|
|
12
|
+
*
|
|
13
|
+
* @param {any[]} args 打印的信息
|
|
14
|
+
*/
|
|
15
|
+
function devWarn() {
|
|
16
|
+
if (!_config.config.disableWarning) {
|
|
17
|
+
var _console;
|
|
18
|
+
|
|
19
|
+
(_console = console).warn.apply(_console, arguments);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var _default = devWarn;
|
|
24
|
+
exports["default"] = _default;
|
package/lib/utils/math.util.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.isEffectiveNumeric = isEffectiveNumeric;
|
|
6
7
|
exports.isScientificNumber = isScientificNumber;
|
|
7
8
|
exports.strip = strip;
|
|
8
9
|
exports.digitLength = digitLength;
|
|
@@ -13,7 +14,11 @@ exports.scientificToNumber = scientificToNumber;
|
|
|
13
14
|
|
|
14
15
|
var _constants = require("./constants");
|
|
15
16
|
|
|
16
|
-
var
|
|
17
|
+
var _devWarn = _interopRequireDefault(require("./devWarn"));
|
|
18
|
+
|
|
19
|
+
var _type = require("./type");
|
|
20
|
+
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
22
|
|
|
18
23
|
/**
|
|
19
24
|
* 参考: https://github.com/nefe/number-precision/blob/master/src/index.ts
|
|
@@ -22,12 +27,42 @@ var _config = require("./config");
|
|
|
22
27
|
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
|
|
23
28
|
*/
|
|
24
29
|
|
|
30
|
+
/**
|
|
31
|
+
* 值是否为有效的数值
|
|
32
|
+
*
|
|
33
|
+
* @param {*} value 待检测的值
|
|
34
|
+
* @returns {boolean} 是否为有效的数值
|
|
35
|
+
*/
|
|
36
|
+
function isEffectiveNumeric(value) {
|
|
37
|
+
if ((0, _type.isNumber)(value) && !isNaN(value)) {
|
|
38
|
+
return true;
|
|
39
|
+
} // 避免空字符串 或 带空格的字符串
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if ((0, _type.isString)(value)) {
|
|
43
|
+
var fmtStrValue = value.trim(); // 带空格的字符串也不转换数字
|
|
44
|
+
// Number(' ') => 0
|
|
45
|
+
|
|
46
|
+
if (fmtStrValue === value) {
|
|
47
|
+
var numValue = fmtStrValue ? Number(fmtStrValue) : NaN;
|
|
48
|
+
|
|
49
|
+
if ((0, _type.isNumber)(numValue) && !isNaN(numValue)) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
(0, _devWarn["default"])("".concat(value, " is not a valid number."));
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
25
58
|
/**
|
|
26
59
|
* 是否为科学计数法数字
|
|
27
60
|
*
|
|
28
61
|
* @param {string} num 检查值
|
|
29
62
|
* @returns {boolean}
|
|
30
63
|
*/
|
|
64
|
+
|
|
65
|
+
|
|
31
66
|
function isScientificNumber(num) {
|
|
32
67
|
return /\d+\.?\d*e[\+\-]*\d+/i.test(num);
|
|
33
68
|
}
|
|
@@ -70,8 +105,10 @@ function digitLength(num) {
|
|
|
70
105
|
|
|
71
106
|
|
|
72
107
|
function float2Fixed(num) {
|
|
73
|
-
|
|
74
|
-
|
|
108
|
+
var strNum = String(num);
|
|
109
|
+
|
|
110
|
+
if (!isScientificNumber(strNum)) {
|
|
111
|
+
return Number(strNum.replace('.', ''));
|
|
75
112
|
}
|
|
76
113
|
|
|
77
114
|
var dLen = digitLength(num);
|
|
@@ -86,9 +123,7 @@ function float2Fixed(num) {
|
|
|
86
123
|
|
|
87
124
|
function checkBoundary(num) {
|
|
88
125
|
if (+num > _constants.MAX_SAFE_INTEGER || +num < _constants.MIN_SAFE_INTEGER) {
|
|
89
|
-
|
|
90
|
-
console.warn("".concat(num, " is beyond boundary when transfer to integer, the results may not be accurate"));
|
|
91
|
-
}
|
|
126
|
+
(0, _devWarn["default"])("".concat(num, " is beyond boundary when transfer to integer, the results may not be accurate"));
|
|
92
127
|
}
|
|
93
128
|
}
|
|
94
129
|
/**
|
|
@@ -119,40 +154,63 @@ function trimLeftZero(num) {
|
|
|
119
154
|
* 2.小数点前边是0,小数点后十分位(包含十分位)之后连续零的个数大于等于6个
|
|
120
155
|
*
|
|
121
156
|
* @param {string | number} num 科学计数法数字
|
|
122
|
-
* @returns {string} 转换后的数字字符串
|
|
157
|
+
* @returns {string | number} 转换后的数字字符串
|
|
123
158
|
*/
|
|
124
159
|
|
|
125
160
|
|
|
126
161
|
function scientificToNumber(num) {
|
|
127
|
-
|
|
128
|
-
var zero = '0';
|
|
129
|
-
var parts = String(num).toLowerCase().split('e');
|
|
130
|
-
var e = parts.pop(); // 存储指数
|
|
131
|
-
// @ts-ignore
|
|
162
|
+
var strNum = String(num);
|
|
132
163
|
|
|
133
|
-
|
|
134
|
-
|
|
164
|
+
if (!isScientificNumber(strNum)) {
|
|
165
|
+
return num;
|
|
166
|
+
}
|
|
167
|
+
/** @type string */
|
|
135
168
|
|
|
136
|
-
var sign = e / l; //判断正负
|
|
137
169
|
|
|
138
|
-
|
|
139
|
-
|
|
170
|
+
var ret;
|
|
171
|
+
var zero = '0';
|
|
172
|
+
var parts = strNum.toLowerCase().split('e');
|
|
173
|
+
var e = parts.pop(); // 存储指数
|
|
174
|
+
// @ts-ignore
|
|
140
175
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
176
|
+
var l = Math.abs(e); // 取绝对值,l-1就是0的个数
|
|
177
|
+
// @ts-ignore
|
|
178
|
+
|
|
179
|
+
var sign = e / l; //判断正负
|
|
180
|
+
|
|
181
|
+
var coeff_array = parts[0].split('.'); // 将系数按照小数点拆分
|
|
182
|
+
// 如果是小数
|
|
183
|
+
|
|
184
|
+
if (sign === -1) {
|
|
185
|
+
// 整数部分
|
|
186
|
+
var intVal = trimLeftZero(coeff_array[0]); // 整数部分大于科学计数后面部分
|
|
187
|
+
// 如: 10e-1, 10.2e-1
|
|
146
188
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
189
|
+
if (intVal.length > l) {
|
|
190
|
+
var thanLen = intVal.length - l;
|
|
191
|
+
var dec = coeff_array[1] || '';
|
|
192
|
+
ret = intVal.slice(0, thanLen); // 处理 10e-1, 100e-1
|
|
193
|
+
|
|
194
|
+
if (intVal.slice(thanLen) !== '0' || dec) {
|
|
195
|
+
ret += '.' + intVal.slice(thanLen) + dec;
|
|
152
196
|
}
|
|
197
|
+
} else {
|
|
198
|
+
// 整数部分小于等于科学计数后面部分
|
|
199
|
+
// 如: 1e-1, 0.2e-1, 1.2e-2, 1.2e-1
|
|
200
|
+
ret = zero + '.' + new Array(l - intVal.length + 1).join(zero) + coeff_array.join('');
|
|
153
201
|
}
|
|
154
|
-
}
|
|
202
|
+
} else {
|
|
203
|
+
// 小数部分
|
|
204
|
+
var _dec = coeff_array[1] || ''; // 如果是整数,将整数除第一位之外的非零数字计入位数,相应的减少0的个数
|
|
155
205
|
|
|
156
206
|
|
|
157
|
-
|
|
207
|
+
if (l - _dec.length < 0) {
|
|
208
|
+
ret = trimLeftZero(coeff_array[0] + _dec.substring(0, l)) + '.' + _dec.substring(l);
|
|
209
|
+
} else {
|
|
210
|
+
// 拼接字符串,如果是整数,不需要拼接小数点
|
|
211
|
+
ret = coeff_array.join('') + new Array(l - _dec.length + 1).join(zero);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return trimLeftZero(ret);
|
|
158
216
|
}
|
package/lib/validatePassword.js
CHANGED
|
@@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _devWarn = _interopRequireDefault(require("./utils/devWarn"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
9
11
|
|
|
10
12
|
var regNumber = /[\d]/;
|
|
11
13
|
var regLowerCaseLetter = /[a-z]/;
|
|
@@ -63,19 +65,22 @@ function hasHex(val) {
|
|
|
63
65
|
*
|
|
64
66
|
* @private
|
|
65
67
|
* @param {string} val 检测的值
|
|
66
|
-
* @param {string}
|
|
68
|
+
* @param {string} chars 特殊字符
|
|
67
69
|
* @returns {boolean} 是否包含特殊字符
|
|
68
70
|
*/
|
|
69
71
|
|
|
70
72
|
|
|
71
|
-
function hasSpecialCharacter(val) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (!chars) {
|
|
73
|
+
function hasSpecialCharacter(val, chars) {
|
|
74
|
+
if (!chars || !val) {
|
|
75
75
|
return false;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
var specialChars = val.replace(regAllNumberAndLetter, '');
|
|
79
|
+
|
|
80
|
+
if (!specialChars) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
79
84
|
var regChars = hasHex(chars) ? new RegExp("[".concat(chars, "]")) : null;
|
|
80
85
|
|
|
81
86
|
if (regChars) {
|
|
@@ -97,16 +102,21 @@ function hasSpecialCharacter(val) {
|
|
|
97
102
|
*
|
|
98
103
|
* @private
|
|
99
104
|
* @param {string} val 检测的值
|
|
100
|
-
* @param {string} chars
|
|
105
|
+
* @param {string} chars 特殊字符
|
|
101
106
|
* @returns {boolean} 是否包含非法字符
|
|
102
107
|
*/
|
|
103
108
|
|
|
104
109
|
|
|
105
|
-
function hasUnallowableCharacter(val) {
|
|
106
|
-
|
|
110
|
+
function hasUnallowableCharacter(val, chars) {
|
|
111
|
+
if (!val) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
107
115
|
var specialChars = val.replace(regAllNumberAndLetter, '');
|
|
108
116
|
|
|
109
|
-
if (!
|
|
117
|
+
if (!specialChars) {
|
|
118
|
+
return false;
|
|
119
|
+
} else if (!chars) {
|
|
110
120
|
return true;
|
|
111
121
|
}
|
|
112
122
|
|
|
@@ -171,7 +181,7 @@ function hasUnallowableCharacter(val) {
|
|
|
171
181
|
* }
|
|
172
182
|
* }
|
|
173
183
|
*
|
|
174
|
-
* validatePassword('a12345678', {level: 3});
|
|
184
|
+
* validatePassword('a12345678', { level: 3 });
|
|
175
185
|
* // =>
|
|
176
186
|
* {
|
|
177
187
|
* validated: false,
|
|
@@ -185,7 +195,7 @@ function hasUnallowableCharacter(val) {
|
|
|
185
195
|
* }
|
|
186
196
|
* }
|
|
187
197
|
*
|
|
188
|
-
* validatePassword('_Aa一二三45678', {level: 3, ignoreCase: true});
|
|
198
|
+
* validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true });
|
|
189
199
|
* // =>
|
|
190
200
|
* {
|
|
191
201
|
* validated: false,
|
|
@@ -200,7 +210,7 @@ function hasUnallowableCharacter(val) {
|
|
|
200
210
|
* }
|
|
201
211
|
*
|
|
202
212
|
* // 自定义特殊字符
|
|
203
|
-
* validatePassword('_Aa一二三45678', {level: 3, ignoreCase: true, special: '_一二三'});
|
|
213
|
+
* validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true, special: '_一二三' });
|
|
204
214
|
* // =>
|
|
205
215
|
* {
|
|
206
216
|
* validated: true,
|
|
@@ -228,10 +238,7 @@ function validatePassword(value) {
|
|
|
228
238
|
var valStr = value;
|
|
229
239
|
|
|
230
240
|
if (typeof value !== 'string') {
|
|
231
|
-
|
|
232
|
-
console.warn("[validatePassword] value must be a string.");
|
|
233
|
-
}
|
|
234
|
-
|
|
241
|
+
(0, _devWarn["default"])("[validatePassword] value must be a string.");
|
|
235
242
|
valStr = '';
|
|
236
243
|
}
|
|
237
244
|
|
|
@@ -243,16 +250,16 @@ function validatePassword(value) {
|
|
|
243
250
|
|
|
244
251
|
var containesUpperCaseLetter = hasUpperCaseLetter(valStr); // 包含特殊字符
|
|
245
252
|
|
|
246
|
-
var containesSpecialCharacter = hasSpecialCharacter(valStr, special); //
|
|
253
|
+
var containesSpecialCharacter = hasSpecialCharacter(valStr, special); // 包含非法字符,即含有非数字字母特殊字符以外的其他字符
|
|
247
254
|
|
|
248
255
|
var containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
|
|
249
256
|
|
|
250
257
|
if (containesNumber) {
|
|
251
258
|
currentLevel += 1;
|
|
252
|
-
}
|
|
259
|
+
} // 不区分大小写
|
|
260
|
+
|
|
253
261
|
|
|
254
262
|
if (ignoreCase) {
|
|
255
|
-
// 不区分大小写
|
|
256
263
|
if (containesLowerCaseLetter || containesUpperCaseLetter) {
|
|
257
264
|
currentLevel += 1;
|
|
258
265
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "util-helpers",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.12.0",
|
|
4
4
|
"description": "一个基于业务场景的工具方法库",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
"types": "types/index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "jest --verbose",
|
|
11
|
+
"test:coverage": "jest --coverage",
|
|
11
12
|
"test:math": "jest --verbose test/math",
|
|
12
13
|
"test:type": "jest --verbose test/type",
|
|
13
14
|
"test:validator": "jest --verbose test/validator",
|
|
14
15
|
"test:processor": "jest --verbose test/processor",
|
|
15
|
-
"build": "npm
|
|
16
|
+
"build": "npm run build:lib && npm run build:esm && npm run build:dist && npm run types",
|
|
16
17
|
"build:lib": "rm -rf lib && cross-env MODULE_TYPE=cjs babel src --out-dir lib",
|
|
17
18
|
"build:esm": "rm -rf esm && cross-env MODULE_TYPE=esm babel src --out-dir esm",
|
|
18
19
|
"build:dist": "rm -rf dist && rollup -c",
|
|
@@ -61,6 +62,7 @@
|
|
|
61
62
|
"@babel/preset-env": "^7.9.0",
|
|
62
63
|
"@commitlint/cli": "^11.0.0",
|
|
63
64
|
"@commitlint/config-conventional": "^11.0.0",
|
|
65
|
+
"@rollup/plugin-babel": "^5.3.1",
|
|
64
66
|
"@rollup/plugin-commonjs": "^19.0.0",
|
|
65
67
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
66
68
|
"@types/jest": "^26.0.23",
|
package/types/isChinese.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export default isChinese;
|
|
|
9
9
|
* @param {*} value 要检测的值
|
|
10
10
|
* @param {Object} [options] 配置项
|
|
11
11
|
* @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
|
|
12
|
+
* @param {boolean} [options.useExtend=false] 使用统一表意文字扩展A-F。注意:如果不支持 `RegExp.prototype.unicode`,扩展字符集将自动不生效,如IE浏览器。
|
|
12
13
|
* @returns {boolean} 值是否为中文
|
|
13
14
|
* @example
|
|
14
15
|
*
|
|
@@ -19,13 +20,22 @@ export default isChinese;
|
|
|
19
20
|
* // => false
|
|
20
21
|
*
|
|
21
22
|
* // 宽松模式,只要包含中文即为true
|
|
22
|
-
* isChinese('林A', {loose: true});
|
|
23
|
+
* isChinese('林A', { loose: true });
|
|
23
24
|
* // => true
|
|
24
25
|
*
|
|
25
|
-
* isChinese('A林A', {loose: true});
|
|
26
|
+
* isChinese('A林A', { loose: true });
|
|
26
27
|
* // => true
|
|
27
28
|
*
|
|
29
|
+
* isChinese('𠮷');
|
|
30
|
+
* // => false
|
|
31
|
+
*
|
|
32
|
+
* // 使用中文扩展字符集,需要浏览器支持 RegExp.prototype.unicode 才生效。
|
|
33
|
+
* isChinese('𠮷', { useExtend: true });
|
|
34
|
+
* // => true
|
|
35
|
+
* isChinese('𠮷aa', { useExtend: true, loose: true });
|
|
36
|
+
* // => true
|
|
28
37
|
*/
|
|
29
|
-
declare function isChinese(value: any, { loose }?: {
|
|
38
|
+
declare function isChinese(value: any, { loose, useExtend }?: {
|
|
30
39
|
loose?: boolean | undefined;
|
|
40
|
+
useExtend?: boolean | undefined;
|
|
31
41
|
} | undefined): boolean;
|
package/types/replaceChar.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export default replaceChar;
|
|
|
45
45
|
* // => 林**
|
|
46
46
|
*
|
|
47
47
|
*/
|
|
48
|
-
declare function replaceChar(str
|
|
48
|
+
declare function replaceChar(str: string, { start, end, char, repeat, exclude }?: {
|
|
49
49
|
start?: number | undefined;
|
|
50
50
|
end?: number | undefined;
|
|
51
51
|
char?: string | undefined;
|
|
@@ -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
|
*
|
|
@@ -51,6 +58,6 @@ export function trimLeftZero(num: string): string;
|
|
|
51
58
|
* 2.小数点前边是0,小数点后十分位(包含十分位)之后连续零的个数大于等于6个
|
|
52
59
|
*
|
|
53
60
|
* @param {string | number} num 科学计数法数字
|
|
54
|
-
* @returns {string} 转换后的数字字符串
|
|
61
|
+
* @returns {string | number} 转换后的数字字符串
|
|
55
62
|
*/
|
|
56
|
-
export function scientificToNumber(num: string | number): string;
|
|
63
|
+
export function scientificToNumber(num: string | number): string | number;
|
|
@@ -84,7 +84,7 @@ export type ValidatePasswordReturn = {
|
|
|
84
84
|
* }
|
|
85
85
|
* }
|
|
86
86
|
*
|
|
87
|
-
* validatePassword('a12345678', {level: 3});
|
|
87
|
+
* validatePassword('a12345678', { level: 3 });
|
|
88
88
|
* // =>
|
|
89
89
|
* {
|
|
90
90
|
* validated: false,
|
|
@@ -98,7 +98,7 @@ export type ValidatePasswordReturn = {
|
|
|
98
98
|
* }
|
|
99
99
|
* }
|
|
100
100
|
*
|
|
101
|
-
* validatePassword('_Aa一二三45678', {level: 3, ignoreCase: true});
|
|
101
|
+
* validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true });
|
|
102
102
|
* // =>
|
|
103
103
|
* {
|
|
104
104
|
* validated: false,
|
|
@@ -113,7 +113,7 @@ export type ValidatePasswordReturn = {
|
|
|
113
113
|
* }
|
|
114
114
|
*
|
|
115
115
|
* // 自定义特殊字符
|
|
116
|
-
* validatePassword('_Aa一二三45678', {level: 3, ignoreCase: true, special: '_一二三'});
|
|
116
|
+
* validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true, special: '_一二三' });
|
|
117
117
|
* // =>
|
|
118
118
|
* {
|
|
119
119
|
* validated: true,
|