util-helpers 4.10.3 → 4.11.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 +171 -133
- 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/formatMoney.js +7 -10
- package/esm/isBusinessLicense.js +2 -2
- package/esm/isChinese.js +24 -11
- package/esm/numberToChinese.js +30 -36
- package/esm/parseIdCard.js +9 -24
- package/esm/replaceChar.js +8 -7
- package/esm/round.js +8 -0
- package/esm/utils/devWarn.js +16 -0
- package/esm/utils/math.util.js +52 -29
- package/esm/validatePassword.js +25 -20
- package/lib/bytesToSize.js +4 -3
- package/lib/formatMoney.js +7 -10
- package/lib/isBusinessLicense.js +2 -2
- package/lib/isChinese.js +24 -11
- package/lib/numberToChinese.js +32 -36
- package/lib/parseIdCard.js +9 -24
- package/lib/replaceChar.js +11 -8
- package/lib/round.js +9 -0
- package/lib/utils/devWarn.js +24 -0
- package/lib/utils/math.util.js +54 -29
- package/lib/validatePassword.js +27 -20
- package/package.json +3 -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 +2 -2
- package/types/validatePassword.d.ts +3 -3
package/lib/formatMoney.js
CHANGED
|
@@ -9,7 +9,7 @@ var _math = require("./utils/math.util");
|
|
|
9
9
|
|
|
10
10
|
var _isNaN = _interopRequireDefault(require("./utils/type/isNaN"));
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _devWarn = _interopRequireDefault(require("./utils/devWarn"));
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
15
|
|
|
@@ -36,10 +36,7 @@ var reg = /^[+-]?\d*\.?\d*$/;
|
|
|
36
36
|
|
|
37
37
|
function checkNumber(num) {
|
|
38
38
|
if (!(reg.test(num) || (0, _math.isScientificNumber)(num)) || (0, _isNaN["default"])(num) || typeof num !== 'number' && typeof num !== 'string' || num === '') {
|
|
39
|
-
|
|
40
|
-
console.warn("".concat(num, " invalid parameter."));
|
|
41
|
-
}
|
|
42
|
-
|
|
39
|
+
(0, _devWarn["default"])("".concat(num, " invalid parameter."));
|
|
43
40
|
return false;
|
|
44
41
|
} // 数字超限如果不是是字符串,可能有异常
|
|
45
42
|
// 如 1111111111111111111111 // => 1.1111111111111111e+21
|
|
@@ -175,12 +172,12 @@ var formatMoney = function formatMoney(num) {
|
|
|
175
172
|
thousand = typeof thousand === 'string' ? thousand : ',';
|
|
176
173
|
decimal = typeof decimal === 'string' ? decimal : '.'; // 转换数字字符串,支持科学记数法
|
|
177
174
|
|
|
178
|
-
var
|
|
175
|
+
var strNum = (0, _math.scientificToNumber)(num) + ''; // 整数和小数部分
|
|
179
176
|
|
|
180
|
-
var
|
|
181
|
-
|
|
182
|
-
intStr =
|
|
183
|
-
decStr =
|
|
177
|
+
var _strNum$split = strNum.split('.'),
|
|
178
|
+
_strNum$split2 = _slicedToArray(_strNum$split, 2),
|
|
179
|
+
intStr = _strNum$split2[0],
|
|
180
|
+
decStr = _strNum$split2[1];
|
|
184
181
|
|
|
185
182
|
return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
|
|
186
183
|
};
|
package/lib/isBusinessLicense.js
CHANGED
package/lib/isChinese.js
CHANGED
|
@@ -28,14 +28,12 @@ var chineseDictionary = {
|
|
|
28
28
|
chineseExtendF: "[\uD873\uDEB0-\uD87A\uDFE0]"
|
|
29
29
|
};
|
|
30
30
|
var looseChineseRegExp = chineseDictionary.chineseBasic + '+';
|
|
31
|
-
var chineseRegExp = '^' + chineseDictionary.chineseBasic + '+$';
|
|
31
|
+
var chineseRegExp = '^' + chineseDictionary.chineseBasic + '+$';
|
|
32
|
+
var chineseWithExtend = '(?:' + chineseDictionary.chineseBasic + '|' + chineseDictionary.chineseExtend + '|' + chineseDictionary.chineseExtendA + '|' + chineseDictionary.chineseExtendB + '|' + chineseDictionary.chineseExtendC + '|' + chineseDictionary.chineseExtendD + '|' + chineseDictionary.chineseExtendE + '|' + chineseDictionary.chineseExtendF + ')';
|
|
33
|
+
var looseChineseExtendRegExp = chineseWithExtend + '+';
|
|
34
|
+
var chineseExtendRegExp = '^' + chineseWithExtend + '+$'; // eslint-disable-next-line no-prototype-builtins
|
|
32
35
|
|
|
33
36
|
var supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');
|
|
34
|
-
|
|
35
|
-
if (supportRegExpUnicode) {
|
|
36
|
-
looseChineseRegExp = '(?:' + chineseDictionary.chineseBasic + '|' + chineseDictionary.chineseExtend + '|' + chineseDictionary.chineseExtendA + '|' + chineseDictionary.chineseExtendB + '|' + chineseDictionary.chineseExtendC + '|' + chineseDictionary.chineseExtendD + '|' + chineseDictionary.chineseExtendE + '|' + chineseDictionary.chineseExtendF + ')+';
|
|
37
|
-
chineseRegExp = '^(?:' + chineseDictionary.chineseBasic + '|' + chineseDictionary.chineseExtend + '|' + chineseDictionary.chineseExtendA + '|' + chineseDictionary.chineseExtendB + '|' + chineseDictionary.chineseExtendC + '|' + chineseDictionary.chineseExtendD + '|' + chineseDictionary.chineseExtendE + '|' + chineseDictionary.chineseExtendF + ')+$';
|
|
38
|
-
}
|
|
39
37
|
/**
|
|
40
38
|
* 检测值是否为中文
|
|
41
39
|
*
|
|
@@ -46,6 +44,7 @@ if (supportRegExpUnicode) {
|
|
|
46
44
|
* @param {*} value 要检测的值
|
|
47
45
|
* @param {Object} [options] 配置项
|
|
48
46
|
* @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
|
|
47
|
+
* @param {boolean} [options.useExtend=false] 使用统一表意文字扩展A-F。注意:如果不支持 `RegExp.prototype.unicode`,扩展字符集将自动不生效,如IE浏览器。
|
|
49
48
|
* @returns {boolean} 值是否为中文
|
|
50
49
|
* @example
|
|
51
50
|
*
|
|
@@ -56,22 +55,36 @@ if (supportRegExpUnicode) {
|
|
|
56
55
|
* // => false
|
|
57
56
|
*
|
|
58
57
|
* // 宽松模式,只要包含中文即为true
|
|
59
|
-
* isChinese('林A', {loose: true});
|
|
58
|
+
* isChinese('林A', { loose: true });
|
|
60
59
|
* // => true
|
|
61
60
|
*
|
|
62
|
-
* isChinese('A林A', {loose: true});
|
|
61
|
+
* isChinese('A林A', { loose: true });
|
|
63
62
|
* // => true
|
|
64
63
|
*
|
|
64
|
+
* isChinese('𠮷');
|
|
65
|
+
* // => false
|
|
66
|
+
*
|
|
67
|
+
* // 使用中文扩展字符集,需要浏览器支持 RegExp.prototype.unicode 才生效。
|
|
68
|
+
* isChinese('𠮷', { useExtend: true });
|
|
69
|
+
* // => true
|
|
70
|
+
* isChinese('𠮷aa', { useExtend: true, loose: true });
|
|
71
|
+
* // => true
|
|
65
72
|
*/
|
|
66
73
|
|
|
67
|
-
|
|
68
74
|
function isChinese(value) {
|
|
69
75
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
70
76
|
_ref$loose = _ref.loose,
|
|
71
|
-
loose = _ref$loose === void 0 ? false : _ref$loose
|
|
77
|
+
loose = _ref$loose === void 0 ? false : _ref$loose,
|
|
78
|
+
_ref$useExtend = _ref.useExtend,
|
|
79
|
+
useExtend = _ref$useExtend === void 0 ? false : _ref$useExtend;
|
|
72
80
|
|
|
73
81
|
var valueStr = (0, _normalizeString["default"])(value);
|
|
74
|
-
var
|
|
82
|
+
var basicRegExp = loose ? looseChineseRegExp : chineseRegExp;
|
|
83
|
+
var extendRegExp = loose ? looseChineseExtendRegExp : chineseExtendRegExp;
|
|
84
|
+
var hasExtend = useExtend && supportRegExpUnicode;
|
|
85
|
+
var resultRegExp = hasExtend ? extendRegExp : basicRegExp;
|
|
86
|
+
var flag = hasExtend ? 'u' : undefined;
|
|
87
|
+
var reg = new RegExp(resultRegExp, flag);
|
|
75
88
|
return reg.test(valueStr);
|
|
76
89
|
}
|
|
77
90
|
|
package/lib/numberToChinese.js
CHANGED
|
@@ -7,7 +7,9 @@ exports["default"] = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _math = require("./utils/math.util");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _devWarn = _interopRequireDefault(require("./utils/devWarn"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
13
|
|
|
12
14
|
// 简体
|
|
13
15
|
var chnNumberChar = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
|
|
@@ -43,11 +45,11 @@ var unitSection;
|
|
|
43
45
|
*/
|
|
44
46
|
|
|
45
47
|
function sectionToChinese(section) {
|
|
46
|
-
var str = ''
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
unitPos = 0;
|
|
48
|
+
var str = '';
|
|
49
|
+
var chnstr = '';
|
|
50
|
+
var zero = false; //zero为是否进行补零, 第一次进行取余由于为个位数,默认不补零
|
|
51
|
+
|
|
52
|
+
var unitPos = 0;
|
|
51
53
|
|
|
52
54
|
while (section > 0) {
|
|
53
55
|
// 对数字取余10,得到的数即为个位数
|
|
@@ -83,18 +85,18 @@ function sectionToChinese(section) {
|
|
|
83
85
|
|
|
84
86
|
|
|
85
87
|
function convertInteger(num) {
|
|
86
|
-
|
|
88
|
+
var numInt = Math.floor(num);
|
|
87
89
|
var unitPos = 0;
|
|
88
|
-
var strIns = ''
|
|
89
|
-
|
|
90
|
+
var strIns = '';
|
|
91
|
+
var chnStr = '';
|
|
90
92
|
var needZero = false;
|
|
91
93
|
|
|
92
|
-
if (
|
|
94
|
+
if (numInt === 0) {
|
|
93
95
|
return numberChar[0];
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
while (
|
|
97
|
-
var section =
|
|
98
|
+
while (numInt > 0) {
|
|
99
|
+
var section = numInt % 10000;
|
|
98
100
|
|
|
99
101
|
if (needZero) {
|
|
100
102
|
chnStr = numberChar[0] + chnStr;
|
|
@@ -104,7 +106,7 @@ function convertInteger(num) {
|
|
|
104
106
|
strIns += section !== 0 ? unitSection[unitPos] : unitSection[0];
|
|
105
107
|
chnStr = strIns + chnStr;
|
|
106
108
|
needZero = section < 1000 && section > 0;
|
|
107
|
-
|
|
109
|
+
numInt = Math.floor(numInt / 10000);
|
|
108
110
|
unitPos++;
|
|
109
111
|
}
|
|
110
112
|
|
|
@@ -119,12 +121,12 @@ function convertInteger(num) {
|
|
|
119
121
|
|
|
120
122
|
|
|
121
123
|
function convertDecimal(num) {
|
|
122
|
-
var
|
|
123
|
-
var index =
|
|
124
|
+
var strNum = num + '';
|
|
125
|
+
var index = strNum.indexOf('.');
|
|
124
126
|
var ret = '';
|
|
125
127
|
|
|
126
128
|
if (index > -1) {
|
|
127
|
-
var decimalStr =
|
|
129
|
+
var decimalStr = strNum.slice(index + 1);
|
|
128
130
|
ret = mapNumberChar(parseInt(decimalStr));
|
|
129
131
|
}
|
|
130
132
|
|
|
@@ -140,11 +142,11 @@ function convertDecimal(num) {
|
|
|
140
142
|
|
|
141
143
|
|
|
142
144
|
function mapNumberChar(num) {
|
|
143
|
-
var
|
|
145
|
+
var strNum = num + '';
|
|
144
146
|
var ret = '';
|
|
145
147
|
|
|
146
|
-
for (var i = 0, len =
|
|
147
|
-
ret += numberChar[parseInt(
|
|
148
|
+
for (var i = 0, len = strNum.length; i < len; i++) {
|
|
149
|
+
ret += numberChar[parseInt(strNum[i])];
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
return ret;
|
|
@@ -209,19 +211,11 @@ function numberToChinese(num) {
|
|
|
209
211
|
_ref$negative = _ref.negative,
|
|
210
212
|
negative = _ref$negative === void 0 ? '负' : _ref$negative,
|
|
211
213
|
_ref$unitConfig = _ref.unitConfig,
|
|
212
|
-
unitConfig = _ref$unitConfig === void 0 ? {
|
|
213
|
-
w: '万',
|
|
214
|
-
// '萬'
|
|
215
|
-
y: '亿' // '億'
|
|
216
|
-
|
|
217
|
-
} : _ref$unitConfig;
|
|
214
|
+
unitConfig = _ref$unitConfig === void 0 ? {} : _ref$unitConfig;
|
|
218
215
|
|
|
219
216
|
// 非数字 或 NaN 不处理
|
|
220
217
|
if (typeof num !== 'number' || isNaN(num)) {
|
|
221
|
-
|
|
222
|
-
console.warn("\u53C2\u6570\u9519\u8BEF ".concat(num, "\uFF0C\u8BF7\u4F20\u5165\u6570\u5B57"));
|
|
223
|
-
}
|
|
224
|
-
|
|
218
|
+
(0, _devWarn["default"])("\u53C2\u6570\u9519\u8BEF ".concat(num, "\uFF0C\u8BF7\u4F20\u5165\u6570\u5B57"));
|
|
225
219
|
return '';
|
|
226
220
|
} // 超过安全数字提示
|
|
227
221
|
|
|
@@ -237,9 +231,10 @@ function numberToChinese(num) {
|
|
|
237
231
|
} // 设置节点计数单位,万、亿、万亿
|
|
238
232
|
|
|
239
233
|
|
|
240
|
-
var
|
|
241
|
-
var
|
|
242
|
-
|
|
234
|
+
var unitWan = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.w) || '万';
|
|
235
|
+
var unitYi = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.y) || '亿';
|
|
236
|
+
var unitWanYi = unitWan + unitYi;
|
|
237
|
+
unitSection = ['', unitWan, unitYi, unitWanYi]; // 设置0
|
|
243
238
|
|
|
244
239
|
if (zero) {
|
|
245
240
|
numberChar[0] = zero;
|
|
@@ -248,16 +243,17 @@ function numberToChinese(num) {
|
|
|
248
243
|
|
|
249
244
|
var preStr = num < 0 ? negative : ''; // 整数和小数
|
|
250
245
|
|
|
251
|
-
var chnInteger, chnDecimal;
|
|
246
|
+
var chnInteger, chnDecimal;
|
|
247
|
+
var numAbs = Math.abs(num); // 处理整数
|
|
252
248
|
|
|
253
249
|
if (unit) {
|
|
254
|
-
chnInteger = convertInteger(
|
|
250
|
+
chnInteger = convertInteger(numAbs);
|
|
255
251
|
} else {
|
|
256
|
-
chnInteger = mapNumberChar(Math.floor(
|
|
252
|
+
chnInteger = mapNumberChar(Math.floor(numAbs));
|
|
257
253
|
} // 处理小数
|
|
258
254
|
|
|
259
255
|
|
|
260
|
-
chnDecimal = convertDecimal(
|
|
256
|
+
chnDecimal = convertDecimal(numAbs);
|
|
261
257
|
return chnDecimal ? "".concat(preStr).concat(chnInteger).concat(decimal).concat(chnDecimal) : "".concat(preStr).concat(chnInteger);
|
|
262
258
|
}
|
|
263
259
|
|
package/lib/parseIdCard.js
CHANGED
|
@@ -119,33 +119,18 @@ function parseIdCard(id) {
|
|
|
119
119
|
* @type {{ province: string, city: string, area: string, year: string, month: string, day: string, gender: string }}
|
|
120
120
|
*
|
|
121
121
|
*/
|
|
122
|
+
// @ts-ignore
|
|
122
123
|
|
|
123
124
|
|
|
124
|
-
var origin = {
|
|
125
|
-
province:
|
|
126
|
-
city:
|
|
127
|
-
area:
|
|
128
|
-
year:
|
|
129
|
-
month:
|
|
130
|
-
day:
|
|
131
|
-
gender:
|
|
125
|
+
var origin = (info === null || info === void 0 ? void 0 : info.groups) || {
|
|
126
|
+
province: info[1],
|
|
127
|
+
city: info[2],
|
|
128
|
+
area: info[3],
|
|
129
|
+
year: info[4],
|
|
130
|
+
month: info[5],
|
|
131
|
+
day: info[6],
|
|
132
|
+
gender: info[7]
|
|
132
133
|
};
|
|
133
|
-
|
|
134
|
-
if (info.groups) {
|
|
135
|
-
// @ts-ignore
|
|
136
|
-
origin = info.groups;
|
|
137
|
-
} else {
|
|
138
|
-
origin = {
|
|
139
|
-
province: info[1],
|
|
140
|
-
city: info[2],
|
|
141
|
-
area: info[3],
|
|
142
|
-
year: info[4],
|
|
143
|
-
month: info[5],
|
|
144
|
-
day: info[6],
|
|
145
|
-
gender: info[7]
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
134
|
var province = Provinces.find(function (item) {
|
|
150
135
|
return item[0] === origin.province;
|
|
151
136
|
});
|
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 _type = require("./utils/type");
|
|
13
|
+
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -33,6 +35,13 @@ 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, _type.isNumber)(num) || (0, _type.isNaN)(num)) && !(0, _type.isString)(num)) {
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
return num;
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
var base = Math.pow(10, precision);
|
|
37
46
|
return (0, _divide["default"])(Math.round((0, _times["default"])(num, base)), base);
|
|
38
47
|
}
|
|
@@ -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
|
@@ -13,7 +13,9 @@ exports.scientificToNumber = scientificToNumber;
|
|
|
13
13
|
|
|
14
14
|
var _constants = require("./constants");
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _devWarn = _interopRequireDefault(require("./devWarn"));
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* 参考: https://github.com/nefe/number-precision/blob/master/src/index.ts
|
|
@@ -70,8 +72,10 @@ function digitLength(num) {
|
|
|
70
72
|
|
|
71
73
|
|
|
72
74
|
function float2Fixed(num) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
var strNum = String(num);
|
|
76
|
+
|
|
77
|
+
if (!isScientificNumber(strNum)) {
|
|
78
|
+
return Number(strNum.replace('.', ''));
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
var dLen = digitLength(num);
|
|
@@ -86,9 +90,7 @@ function float2Fixed(num) {
|
|
|
86
90
|
|
|
87
91
|
function checkBoundary(num) {
|
|
88
92
|
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
|
-
}
|
|
93
|
+
(0, _devWarn["default"])("".concat(num, " is beyond boundary when transfer to integer, the results may not be accurate"));
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
/**
|
|
@@ -119,40 +121,63 @@ function trimLeftZero(num) {
|
|
|
119
121
|
* 2.小数点前边是0,小数点后十分位(包含十分位)之后连续零的个数大于等于6个
|
|
120
122
|
*
|
|
121
123
|
* @param {string | number} num 科学计数法数字
|
|
122
|
-
* @returns {string} 转换后的数字字符串
|
|
124
|
+
* @returns {string | number} 转换后的数字字符串
|
|
123
125
|
*/
|
|
124
126
|
|
|
125
127
|
|
|
126
128
|
function scientificToNumber(num) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
var strNum = String(num);
|
|
130
|
+
|
|
131
|
+
if (!isScientificNumber(strNum)) {
|
|
132
|
+
return num;
|
|
133
|
+
}
|
|
134
|
+
/** @type string */
|
|
132
135
|
|
|
133
|
-
var l = Math.abs(e); // 取绝对值,l-1就是0的个数
|
|
134
|
-
// @ts-ignore
|
|
135
136
|
|
|
136
|
-
|
|
137
|
+
var ret;
|
|
138
|
+
var zero = '0';
|
|
139
|
+
var parts = strNum.toLowerCase().split('e');
|
|
140
|
+
var e = parts.pop(); // 存储指数
|
|
141
|
+
// @ts-ignore
|
|
137
142
|
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
var l = Math.abs(e); // 取绝对值,l-1就是0的个数
|
|
144
|
+
// @ts-ignore
|
|
140
145
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
var sign = e / l; //判断正负
|
|
147
|
+
|
|
148
|
+
var coeff_array = parts[0].split('.'); // 将系数按照小数点拆分
|
|
149
|
+
// 如果是小数
|
|
150
|
+
|
|
151
|
+
if (sign === -1) {
|
|
152
|
+
// 整数部分
|
|
153
|
+
var intVal = trimLeftZero(coeff_array[0]); // 整数部分大于科学计数后面部分
|
|
154
|
+
// 如: 10e-1, 10.2e-1
|
|
146
155
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
156
|
+
if (intVal.length > l) {
|
|
157
|
+
var thanLen = intVal.length - l;
|
|
158
|
+
var dec = coeff_array[1] || '';
|
|
159
|
+
ret = intVal.slice(0, thanLen); // 处理 10e-1, 100e-1
|
|
160
|
+
|
|
161
|
+
if (intVal.slice(thanLen) !== '0' || dec) {
|
|
162
|
+
ret += '.' + intVal.slice(thanLen) + dec;
|
|
152
163
|
}
|
|
164
|
+
} else {
|
|
165
|
+
// 整数部分小于等于科学计数后面部分
|
|
166
|
+
// 如: 1e-1, 0.2e-1, 1.2e-2, 1.2e-1
|
|
167
|
+
ret = zero + '.' + new Array(l - intVal.length + 1).join(zero) + coeff_array.join('');
|
|
153
168
|
}
|
|
154
|
-
}
|
|
169
|
+
} else {
|
|
170
|
+
// 小数部分
|
|
171
|
+
var _dec = coeff_array[1] || ''; // 如果是整数,将整数除第一位之外的非零数字计入位数,相应的减少0的个数
|
|
155
172
|
|
|
156
173
|
|
|
157
|
-
|
|
174
|
+
if (l - _dec.length < 0) {
|
|
175
|
+
ret = trimLeftZero(coeff_array[0] + _dec.substring(0, l)) + '.' + _dec.substring(l);
|
|
176
|
+
} else {
|
|
177
|
+
// 拼接字符串,如果是整数,不需要拼接小数点
|
|
178
|
+
ret = coeff_array.join('') + new Array(l - _dec.length + 1).join(zero);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return trimLeftZero(ret);
|
|
158
183
|
}
|
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
|
}
|