util-helpers 4.10.2 → 4.11.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.
- package/dist/util-helpers.js +991 -607
- 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 +17 -16
- package/esm/isChinese.js +24 -11
- package/esm/isSocialCreditCode.js +16 -9
- 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 +17 -16
- package/lib/isChinese.js +24 -11
- package/lib/isSocialCreditCode.js +16 -9
- 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 +4 -2
- package/types/isBusinessLicense.d.ts +7 -10
- package/types/isChinese.d.ts +13 -3
- package/types/isSocialCreditCode.d.ts +8 -5
- 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/esm/validatePassword.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import devWarn from './utils/devWarn';
|
|
2
2
|
var regNumber = /[\d]/;
|
|
3
3
|
var regLowerCaseLetter = /[a-z]/;
|
|
4
4
|
var regUpperCaseLetter = /[A-Z]/;
|
|
@@ -55,19 +55,22 @@ function hasHex(val) {
|
|
|
55
55
|
*
|
|
56
56
|
* @private
|
|
57
57
|
* @param {string} val 检测的值
|
|
58
|
-
* @param {string}
|
|
58
|
+
* @param {string} chars 特殊字符
|
|
59
59
|
* @returns {boolean} 是否包含特殊字符
|
|
60
60
|
*/
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
function hasSpecialCharacter(val) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (!chars) {
|
|
63
|
+
function hasSpecialCharacter(val, chars) {
|
|
64
|
+
if (!chars || !val) {
|
|
67
65
|
return false;
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
var specialChars = val.replace(regAllNumberAndLetter, '');
|
|
69
|
+
|
|
70
|
+
if (!specialChars) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
71
74
|
var regChars = hasHex(chars) ? new RegExp("[".concat(chars, "]")) : null;
|
|
72
75
|
|
|
73
76
|
if (regChars) {
|
|
@@ -89,16 +92,21 @@ function hasSpecialCharacter(val) {
|
|
|
89
92
|
*
|
|
90
93
|
* @private
|
|
91
94
|
* @param {string} val 检测的值
|
|
92
|
-
* @param {string} chars
|
|
95
|
+
* @param {string} chars 特殊字符
|
|
93
96
|
* @returns {boolean} 是否包含非法字符
|
|
94
97
|
*/
|
|
95
98
|
|
|
96
99
|
|
|
97
|
-
function hasUnallowableCharacter(val) {
|
|
98
|
-
|
|
100
|
+
function hasUnallowableCharacter(val, chars) {
|
|
101
|
+
if (!val) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
99
105
|
var specialChars = val.replace(regAllNumberAndLetter, '');
|
|
100
106
|
|
|
101
|
-
if (!
|
|
107
|
+
if (!specialChars) {
|
|
108
|
+
return false;
|
|
109
|
+
} else if (!chars) {
|
|
102
110
|
return true;
|
|
103
111
|
}
|
|
104
112
|
|
|
@@ -163,7 +171,7 @@ function hasUnallowableCharacter(val) {
|
|
|
163
171
|
* }
|
|
164
172
|
* }
|
|
165
173
|
*
|
|
166
|
-
* validatePassword('a12345678', {level: 3});
|
|
174
|
+
* validatePassword('a12345678', { level: 3 });
|
|
167
175
|
* // =>
|
|
168
176
|
* {
|
|
169
177
|
* validated: false,
|
|
@@ -177,7 +185,7 @@ function hasUnallowableCharacter(val) {
|
|
|
177
185
|
* }
|
|
178
186
|
* }
|
|
179
187
|
*
|
|
180
|
-
* validatePassword('_Aa一二三45678', {level: 3, ignoreCase: true});
|
|
188
|
+
* validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true });
|
|
181
189
|
* // =>
|
|
182
190
|
* {
|
|
183
191
|
* validated: false,
|
|
@@ -192,7 +200,7 @@ function hasUnallowableCharacter(val) {
|
|
|
192
200
|
* }
|
|
193
201
|
*
|
|
194
202
|
* // 自定义特殊字符
|
|
195
|
-
* validatePassword('_Aa一二三45678', {level: 3, ignoreCase: true, special: '_一二三'});
|
|
203
|
+
* validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true, special: '_一二三' });
|
|
196
204
|
* // =>
|
|
197
205
|
* {
|
|
198
206
|
* validated: true,
|
|
@@ -220,10 +228,7 @@ function validatePassword(value) {
|
|
|
220
228
|
var valStr = value;
|
|
221
229
|
|
|
222
230
|
if (typeof value !== 'string') {
|
|
223
|
-
|
|
224
|
-
console.warn("[validatePassword] value must be a string.");
|
|
225
|
-
}
|
|
226
|
-
|
|
231
|
+
devWarn("[validatePassword] value must be a string.");
|
|
227
232
|
valStr = '';
|
|
228
233
|
}
|
|
229
234
|
|
|
@@ -235,16 +240,16 @@ function validatePassword(value) {
|
|
|
235
240
|
|
|
236
241
|
var containesUpperCaseLetter = hasUpperCaseLetter(valStr); // 包含特殊字符
|
|
237
242
|
|
|
238
|
-
var containesSpecialCharacter = hasSpecialCharacter(valStr, special); //
|
|
243
|
+
var containesSpecialCharacter = hasSpecialCharacter(valStr, special); // 包含非法字符,即含有非数字字母特殊字符以外的其他字符
|
|
239
244
|
|
|
240
245
|
var containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
|
|
241
246
|
|
|
242
247
|
if (containesNumber) {
|
|
243
248
|
currentLevel += 1;
|
|
244
|
-
}
|
|
249
|
+
} // 不区分大小写
|
|
250
|
+
|
|
245
251
|
|
|
246
252
|
if (ignoreCase) {
|
|
247
|
-
// 不区分大小写
|
|
248
253
|
if (containesLowerCaseLetter || containesUpperCaseLetter) {
|
|
249
254
|
currentLevel += 1;
|
|
250
255
|
}
|
package/lib/bytesToSize.js
CHANGED
|
@@ -28,12 +28,13 @@ exports["default"] = void 0;
|
|
|
28
28
|
* // => 1 GB
|
|
29
29
|
*/
|
|
30
30
|
function bytesToSize(bytes) {
|
|
31
|
-
|
|
31
|
+
var numBytes = typeof bytes !== 'number' ? Number(bytes) : bytes;
|
|
32
|
+
if (numBytes === 0 || isNaN(numBytes)) return '0 B';
|
|
32
33
|
var k = 1024; // 存储单位
|
|
33
34
|
|
|
34
35
|
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
35
|
-
var i = Math.floor(Math.log(
|
|
36
|
-
return sizes[i] ? "".concat(Number((
|
|
36
|
+
var i = Math.floor(Math.log(numBytes) / Math.log(k));
|
|
37
|
+
return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(2)), " ").concat(sizes[i]) : numBytes + '';
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
var _default = bytesToSize;
|
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
|
@@ -34,8 +34,8 @@ function sumCheckCode(preCode) {
|
|
|
34
34
|
} // 反模10计算
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
if (pj ===
|
|
38
|
-
retNum =
|
|
37
|
+
if (pj === 1) {
|
|
38
|
+
retNum = 0;
|
|
39
39
|
} else {
|
|
40
40
|
retNum = 11 - pj;
|
|
41
41
|
}
|
|
@@ -51,36 +51,37 @@ function sumCheckCode(preCode) {
|
|
|
51
51
|
* @since 3.5.0
|
|
52
52
|
* @param {*} value 要检测的值
|
|
53
53
|
* @param {Object} [options] 配置项
|
|
54
|
-
* @param {boolean} [options.
|
|
54
|
+
* @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
|
|
55
55
|
* @returns {boolean} 值是否为营业执照号
|
|
56
56
|
* @example
|
|
57
57
|
*
|
|
58
58
|
* isBusinessLicense('310115600985533');
|
|
59
59
|
* // => true
|
|
60
60
|
*
|
|
61
|
-
* isBusinessLicense('3101156009');
|
|
62
|
-
* // => false
|
|
63
|
-
*
|
|
64
|
-
* isBusinessLicense('3101156009', { loose: true });
|
|
65
|
-
* // => false
|
|
66
|
-
*
|
|
67
61
|
* isBusinessLicense('310115600985535');
|
|
68
62
|
* // => false
|
|
69
63
|
*
|
|
70
|
-
* isBusinessLicense('310115600985535', {
|
|
64
|
+
* isBusinessLicense('310115600985535', { checkCode: false });
|
|
71
65
|
* // => true
|
|
66
|
+
*
|
|
67
|
+
* isBusinessLicense('31011560098', { checkCode: false });
|
|
68
|
+
* // => false
|
|
72
69
|
*/
|
|
73
70
|
|
|
74
71
|
|
|
75
72
|
function isBusinessLicense(value) {
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
var
|
|
73
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
74
|
+
var valueStr = (0, _normalizeString["default"])(value); // @ts-ignore
|
|
75
|
+
// TODO 下个版本废弃 loose
|
|
76
|
+
|
|
77
|
+
var _options$loose = options.loose,
|
|
78
|
+
loose = _options$loose === void 0 ? false : _options$loose,
|
|
79
|
+
_options$checkCode = options.checkCode,
|
|
80
|
+
cc = _options$checkCode === void 0 ? true : _options$checkCode;
|
|
81
|
+
var needCheckCode = !loose && cc;
|
|
81
82
|
var passBaseRule = baseReg.test(valueStr); // 宽松模式 或 基础规则不通过直接返回
|
|
82
83
|
|
|
83
|
-
if (
|
|
84
|
+
if (!needCheckCode || !passBaseRule) {
|
|
84
85
|
return passBaseRule;
|
|
85
86
|
} // 前14位
|
|
86
87
|
|
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
|
|
|
@@ -55,7 +55,7 @@ function sumCheckCode(preCode) {
|
|
|
55
55
|
* @since 1.1.0
|
|
56
56
|
* @param {*} value 要检测的值
|
|
57
57
|
* @param {Object} [options] 配置项
|
|
58
|
-
* @param {boolean} [options.
|
|
58
|
+
* @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
|
|
59
59
|
* @returns {boolean} 值是否为统一社会信用代码
|
|
60
60
|
* @example
|
|
61
61
|
*
|
|
@@ -65,22 +65,29 @@ function sumCheckCode(preCode) {
|
|
|
65
65
|
* isSocialCreditCode('91350100M000100Y4A');
|
|
66
66
|
* // => false
|
|
67
67
|
*
|
|
68
|
-
* //
|
|
69
|
-
* isSocialCreditCode('91350100M000100Y4A', {
|
|
68
|
+
* // 不校验校验位
|
|
69
|
+
* isSocialCreditCode('91350100M000100Y4A', { checkCode: false });
|
|
70
70
|
* // => true
|
|
71
71
|
*
|
|
72
|
+
* isSocialCreditCode('91350100M000100Y', { checkCode: false });
|
|
73
|
+
* // => false
|
|
74
|
+
*
|
|
72
75
|
*/
|
|
73
76
|
|
|
74
77
|
|
|
75
78
|
function isSocialCreditCode(value) {
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
var
|
|
79
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
80
|
+
var valueStr = (0, _normalizeString["default"])(value); // @ts-ignore
|
|
81
|
+
// TODO 下个版本废弃 loose
|
|
82
|
+
|
|
83
|
+
var _options$loose = options.loose,
|
|
84
|
+
loose = _options$loose === void 0 ? false : _options$loose,
|
|
85
|
+
_options$checkCode = options.checkCode,
|
|
86
|
+
cc = _options$checkCode === void 0 ? true : _options$checkCode;
|
|
87
|
+
var needCheckCode = !loose && cc;
|
|
81
88
|
var passBaseRule = baseReg.test(valueStr); // 宽松模式 或 基础规则不通过直接返回
|
|
82
89
|
|
|
83
|
-
if (
|
|
90
|
+
if (!needCheckCode || !passBaseRule) {
|
|
84
91
|
return passBaseRule;
|
|
85
92
|
} // 前17位
|
|
86
93
|
|
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;
|