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.
@@ -5,7 +5,37 @@
5
5
  * 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
6
6
  */
7
7
  import { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } from './constants';
8
- import { config } from './config';
8
+ import devWarn from './devWarn';
9
+ import { isNumber, isString } from './type';
10
+ /**
11
+ * 值是否为有效的数值
12
+ *
13
+ * @param {*} value 待检测的值
14
+ * @returns {boolean} 是否为有效的数值
15
+ */
16
+
17
+ export function isEffectiveNumeric(value) {
18
+ if (isNumber(value) && !isNaN(value)) {
19
+ return true;
20
+ } // 避免空字符串 或 带空格的字符串
21
+
22
+
23
+ if (isString(value)) {
24
+ var fmtStrValue = value.trim(); // 带空格的字符串也不转换数字
25
+ // Number(' ') => 0
26
+
27
+ if (fmtStrValue === value) {
28
+ var numValue = fmtStrValue ? Number(fmtStrValue) : NaN;
29
+
30
+ if (isNumber(numValue) && !isNaN(numValue)) {
31
+ return true;
32
+ }
33
+ }
34
+ }
35
+
36
+ devWarn("".concat(value, " is not a valid number."));
37
+ return false;
38
+ }
9
39
  /**
10
40
  * 是否为科学计数法数字
11
41
  *
@@ -52,8 +82,10 @@ export function digitLength(num) {
52
82
  */
53
83
 
54
84
  export function float2Fixed(num) {
55
- if (!isScientificNumber(num.toString())) {
56
- return Number(num.toString().replace('.', ''));
85
+ var strNum = String(num);
86
+
87
+ if (!isScientificNumber(strNum)) {
88
+ return Number(strNum.replace('.', ''));
57
89
  }
58
90
 
59
91
  var dLen = digitLength(num);
@@ -67,9 +99,7 @@ export function float2Fixed(num) {
67
99
 
68
100
  export function checkBoundary(num) {
69
101
  if (+num > MAX_SAFE_INTEGER || +num < MIN_SAFE_INTEGER) {
70
- if (!config.disableWarning) {
71
- console.warn("".concat(num, " is beyond boundary when transfer to integer, the results may not be accurate"));
72
- }
102
+ devWarn("".concat(num, " is beyond boundary when transfer to integer, the results may not be accurate"));
73
103
  }
74
104
  }
75
105
  /**
@@ -99,39 +129,62 @@ export function trimLeftZero(num) {
99
129
  * 2.小数点前边是0,小数点后十分位(包含十分位)之后连续零的个数大于等于6个
100
130
  *
101
131
  * @param {string | number} num 科学计数法数字
102
- * @returns {string} 转换后的数字字符串
132
+ * @returns {string | number} 转换后的数字字符串
103
133
  */
104
134
 
105
135
  export function scientificToNumber(num) {
106
- if (isScientificNumber(num.toString())) {
107
- var zero = '0';
108
- var parts = String(num).toLowerCase().split('e');
109
- var e = parts.pop(); // 存储指数
110
- // @ts-ignore
136
+ var strNum = String(num);
137
+
138
+ if (!isScientificNumber(strNum)) {
139
+ return num;
140
+ }
141
+ /** @type string */
111
142
 
112
- var l = Math.abs(e); // 取绝对值,l-1就是0的个数
113
- // @ts-ignore
114
143
 
115
- var sign = e / l; //判断正负
144
+ var ret;
145
+ var zero = '0';
146
+ var parts = strNum.toLowerCase().split('e');
147
+ var e = parts.pop(); // 存储指数
148
+ // @ts-ignore
116
149
 
117
- var coeff_array = parts[0].split('.'); // 将系数按照小数点拆分
118
- //如果是小数
150
+ var l = Math.abs(e); // 取绝对值,l-1就是0的个数
151
+ // @ts-ignore
119
152
 
120
- if (sign === -1) {
121
- //拼接字符串,如果是小数,拼接0和小数点
122
- num = zero + '.' + new Array(l).join(zero) + coeff_array.join('');
123
- } else {
124
- var dec = coeff_array[1]; //如果是整数,将整数除第一位之外的非零数字计入位数,相应的减少0的个数
153
+ var sign = e / l; //判断正负
154
+
155
+ var coeff_array = parts[0].split('.'); // 将系数按照小数点拆分
156
+ // 如果是小数
157
+
158
+ if (sign === -1) {
159
+ // 整数部分
160
+ var intVal = trimLeftZero(coeff_array[0]); // 整数部分大于科学计数后面部分
161
+ // 如: 10e-1, 10.2e-1
162
+
163
+ if (intVal.length > l) {
164
+ var thanLen = intVal.length - l;
165
+ var dec = coeff_array[1] || '';
166
+ ret = intVal.slice(0, thanLen); // 处理 10e-1, 100e-1
125
167
 
126
- if (l - dec.length < 0) {
127
- num = trimLeftZero(coeff_array[0] + dec.substring(0, l)) + '.' + dec.substring(l);
128
- } else {
129
- //拼接字符串,如果是整数,不需要拼接小数点
130
- num = coeff_array.join('') + new Array(l - dec.length + 1).join(zero);
168
+ if (intVal.slice(thanLen) !== '0' || dec) {
169
+ ret += '.' + intVal.slice(thanLen) + dec;
131
170
  }
171
+ } else {
172
+ // 整数部分小于等于科学计数后面部分
173
+ // 如: 1e-1, 0.2e-1, 1.2e-2, 1.2e-1
174
+ ret = zero + '.' + new Array(l - intVal.length + 1).join(zero) + coeff_array.join('');
132
175
  }
133
- } // @ts-ignore
176
+ } else {
177
+ // 小数部分
178
+ var _dec = coeff_array[1] || ''; // 如果是整数,将整数除第一位之外的非零数字计入位数,相应的减少0的个数
134
179
 
135
180
 
136
- return num;
181
+ if (l - _dec.length < 0) {
182
+ ret = trimLeftZero(coeff_array[0] + _dec.substring(0, l)) + '.' + _dec.substring(l);
183
+ } else {
184
+ // 拼接字符串,如果是整数,不需要拼接小数点
185
+ ret = coeff_array.join('') + new Array(l - _dec.length + 1).join(zero);
186
+ }
187
+ }
188
+
189
+ return trimLeftZero(ret);
137
190
  }
@@ -1,4 +1,4 @@
1
- import { config } from './utils/config';
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} [chars] 特殊字符
58
+ * @param {string} chars 特殊字符
59
59
  * @returns {boolean} 是否包含特殊字符
60
60
  */
61
61
 
62
62
 
63
- function hasSpecialCharacter(val) {
64
- var chars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
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
- var chars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
100
+ function hasUnallowableCharacter(val, chars) {
101
+ if (!val) {
102
+ return false;
103
+ }
104
+
99
105
  var specialChars = val.replace(regAllNumberAndLetter, '');
100
106
 
101
- if (!chars && specialChars) {
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
- if (!config.disableWarning) {
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
  }
@@ -28,12 +28,13 @@ exports["default"] = void 0;
28
28
  * // => 1 GB
29
29
  */
30
30
  function bytesToSize(bytes) {
31
- if (bytes === 0) return '0 B';
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(bytes) / Math.log(k));
36
- return sizes[i] ? "".concat(Number((bytes / Math.pow(k, i)).toFixed(2)), " ").concat(sizes[i]) : bytes + '';
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/divide.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 divide() {
55
53
 
56
54
  if (rest.length > 0) {
57
55
  return divide.apply(void 0, [divide(num1, num2)].concat(_toConsumableArray(rest)));
58
- } // 兼容处理,如果第2个参数为非数字或字符串时,返回第一个参数
56
+ } // 兼容处理,如果参数包含无效数值时,尝试取出有效数值参数
59
57
 
60
58
 
61
- if ((!(0, _type.isNumber)(num2) || (0, _type.isNaN)(num2)) && !(0, _type.isString)(num2)) {
62
- // @ts-ignore
63
- return num1;
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 num1Changed = (0, _math.float2Fixed)(num1);
@@ -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 _config = require("./utils/config");
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
- if (!_config.config.disableWarning) {
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 numStr = (0, _math.scientificToNumber)(num) + ''; // 整数和小数部分
175
+ var strNum = (0, _math.scientificToNumber)(num) + ''; // 整数和小数部分
179
176
 
180
- var _numStr$split = numStr.split('.'),
181
- _numStr$split2 = _slicedToArray(_numStr$split, 2),
182
- intStr = _numStr$split2[0],
183
- decStr = _numStr$split2[1];
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
  };
@@ -34,8 +34,8 @@ function sumCheckCode(preCode) {
34
34
  } // 反模10计算
35
35
 
36
36
 
37
- if (pj === 10 || pj === 1) {
38
- retNum = 1;
37
+ if (pj === 1) {
38
+ retNum = 0;
39
39
  } else {
40
40
  retNum = 11 - pj;
41
41
  }
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 + '+$'; // eslint-disable-next-line no-prototype-builtins
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 reg = new RegExp(loose ? looseChineseRegExp : chineseRegExp, supportRegExpUnicode ? 'u' : undefined);
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/minus.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 minus() {
55
53
 
56
54
  if (rest.length > 0) {
57
55
  return minus.apply(void 0, [minus(num1, num2)].concat(_toConsumableArray(rest)));
58
- } // 兼容处理,如果第2个参数为非数字或字符串时,返回第一个参数
56
+ } // 兼容处理,如果参数包含无效数值时,尝试取出有效数值参数
59
57
 
60
58
 
61
- if ((!(0, _type.isNumber)(num2) || (0, _type.isNaN)(num2)) && !(0, _type.isString)(num2)) {
62
- // @ts-ignore
63
- return num1;
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)));
@@ -7,7 +7,9 @@ exports["default"] = void 0;
7
7
 
8
8
  var _math = require("./utils/math.util");
9
9
 
10
- var _config = require("./utils/config");
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
- chnstr = '',
48
- zero = false,
49
- //zero为是否进行补零, 第一次进行取余由于为个位数,默认不补零
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
- num = Math.floor(num);
88
+ var numInt = Math.floor(num);
87
89
  var unitPos = 0;
88
- var strIns = '',
89
- chnStr = '';
90
+ var strIns = '';
91
+ var chnStr = '';
90
92
  var needZero = false;
91
93
 
92
- if (num === 0) {
94
+ if (numInt === 0) {
93
95
  return numberChar[0];
94
96
  }
95
97
 
96
- while (num > 0) {
97
- var section = num % 10000;
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
- num = Math.floor(num / 10000);
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 numStr = num + '';
123
- var index = numStr.indexOf('.');
124
+ var strNum = num + '';
125
+ var index = strNum.indexOf('.');
124
126
  var ret = '';
125
127
 
126
128
  if (index > -1) {
127
- var decimalStr = numStr.slice(index + 1);
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 numStr = num + '';
145
+ var strNum = num + '';
144
146
  var ret = '';
145
147
 
146
- for (var i = 0, len = numStr.length; i < len; i++) {
147
- ret += numberChar[parseInt(numStr[i])];
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
- if (!_config.config.disableWarning) {
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 defaultUnitWan = '万';
241
- var defaultUnitYi = '亿';
242
- unitSection = ['', unitConfig.w || defaultUnitWan, unitConfig.y || defaultUnitYi, unitConfig.w && unitConfig.y ? unitConfig.w + unitConfig.y : defaultUnitWan + defaultUnitYi]; // 设置0
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(num);
250
+ chnInteger = convertInteger(numAbs);
255
251
  } else {
256
- chnInteger = mapNumberChar(Math.floor(num));
252
+ chnInteger = mapNumberChar(Math.floor(numAbs));
257
253
  } // 处理小数
258
254
 
259
255
 
260
- chnDecimal = convertDecimal(num);
256
+ chnDecimal = convertDecimal(numAbs);
261
257
  return chnDecimal ? "".concat(preStr).concat(chnInteger).concat(decimal).concat(chnDecimal) : "".concat(preStr).concat(chnInteger);
262
258
  }
263
259
 
@@ -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
  });