util-helpers 4.11.0 → 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 +880 -542
- 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/package.json +2 -1
package/dist/util-helpers.js
CHANGED
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
* @param {*} value 检查值
|
|
57
57
|
* @returns {boolean} 是否为 undefined 或 null
|
|
58
58
|
*/
|
|
59
|
+
|
|
59
60
|
function isNil(value) {
|
|
60
61
|
return isUndefined(value) || isNull(value);
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
var toString = Object.prototype.toString;
|
|
65
65
|
/**
|
|
66
66
|
* 检测值的 `toString` 类型
|
|
67
67
|
*
|
|
@@ -71,8 +71,9 @@
|
|
|
71
71
|
* @param {string} typename 类型名称
|
|
72
72
|
* @returns {boolean} 返回值的 `toString` 类型是否匹配
|
|
73
73
|
*/
|
|
74
|
+
|
|
74
75
|
function isType(value, typename) {
|
|
75
|
-
return toString.call(value) ===
|
|
76
|
+
return toString.call(value) === "[object ".concat(typename, "]");
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
/**
|
|
@@ -91,6 +92,7 @@
|
|
|
91
92
|
* isString(1)
|
|
92
93
|
* // => false
|
|
93
94
|
*/
|
|
95
|
+
|
|
94
96
|
function isString(value) {
|
|
95
97
|
return isType(value, 'String');
|
|
96
98
|
}
|
|
@@ -101,6 +103,7 @@
|
|
|
101
103
|
* @param {*} value 值
|
|
102
104
|
* @returns {string} 字符串
|
|
103
105
|
*/
|
|
106
|
+
|
|
104
107
|
function convertToString(value) {
|
|
105
108
|
return isString(value) ? value : String(value);
|
|
106
109
|
}
|
|
@@ -125,16 +128,16 @@
|
|
|
125
128
|
* normalizeString(1); // '1'
|
|
126
129
|
* normalizeString('a'); // 'a'
|
|
127
130
|
*/
|
|
131
|
+
|
|
128
132
|
function normalizeString(value) {
|
|
129
133
|
if (isNil(value)) {
|
|
130
134
|
return '';
|
|
131
135
|
}
|
|
136
|
+
|
|
132
137
|
return convertToString(value);
|
|
133
138
|
}
|
|
134
139
|
|
|
135
|
-
|
|
136
|
-
const reg$d = /^1[3456789]\d{9}$/;
|
|
137
|
-
|
|
140
|
+
var reg$d = /^1[3456789]\d{9}$/;
|
|
138
141
|
/**
|
|
139
142
|
* 检测值是否为手机号码
|
|
140
143
|
*
|
|
@@ -152,14 +155,13 @@
|
|
|
152
155
|
* // => false
|
|
153
156
|
*
|
|
154
157
|
*/
|
|
158
|
+
|
|
155
159
|
function isMobile(value) {
|
|
156
|
-
|
|
160
|
+
var valueStr = normalizeString(value);
|
|
157
161
|
return reg$d.test(valueStr);
|
|
158
162
|
}
|
|
159
163
|
|
|
160
|
-
|
|
161
|
-
const reg$c = /^(0\d{2,3}\-)?([2-9]\d{6,7})(\-\d{1,6})?$/;
|
|
162
|
-
|
|
164
|
+
var reg$c = /^(0\d{2,3}\-)?([2-9]\d{6,7})(\-\d{1,6})?$/;
|
|
163
165
|
/**
|
|
164
166
|
* 检测值是否为固定电话
|
|
165
167
|
*
|
|
@@ -183,14 +185,13 @@
|
|
|
183
185
|
* // => false
|
|
184
186
|
*
|
|
185
187
|
*/
|
|
188
|
+
|
|
186
189
|
function isTelephone(value) {
|
|
187
|
-
|
|
190
|
+
var valueStr = normalizeString(value);
|
|
188
191
|
return reg$c.test(valueStr);
|
|
189
192
|
}
|
|
190
193
|
|
|
191
|
-
|
|
192
|
-
const reg$b = /^\d{6}$/;
|
|
193
|
-
|
|
194
|
+
var reg$b = /^\d{6}$/;
|
|
194
195
|
/**
|
|
195
196
|
* 检测值是否为邮政编码,6位数字
|
|
196
197
|
*
|
|
@@ -208,14 +209,13 @@
|
|
|
208
209
|
* // => false
|
|
209
210
|
*
|
|
210
211
|
*/
|
|
212
|
+
|
|
211
213
|
function isPostcode(value) {
|
|
212
|
-
|
|
214
|
+
var valueStr = normalizeString(value);
|
|
213
215
|
return reg$b.test(valueStr);
|
|
214
216
|
}
|
|
215
217
|
|
|
216
|
-
|
|
217
|
-
const regIdCard$1 = /^[1-9]\d{5}(19|20)?\d{2}((0[1-9])|(1[012]))(([0-2][1-9])|10|20|30|31)\d{3}(\d|X)?$/i;
|
|
218
|
-
|
|
218
|
+
var regIdCard$1 = /^[1-9]\d{5}(19|20)?\d{2}((0[1-9])|(1[012]))(([0-2][1-9])|10|20|30|31)\d{3}(\d|X)?$/i;
|
|
219
219
|
/**
|
|
220
220
|
* 校验码计算
|
|
221
221
|
*
|
|
@@ -225,19 +225,22 @@
|
|
|
225
225
|
* @param {string} id 身份证号码
|
|
226
226
|
* @returns {boolean} 校验码是否正确
|
|
227
227
|
*/
|
|
228
|
+
|
|
228
229
|
function check(id) {
|
|
229
|
-
|
|
230
|
+
var index, sum, num;
|
|
231
|
+
|
|
230
232
|
for (sum = index = 0; index < 17; index++) {
|
|
231
|
-
sum +=
|
|
233
|
+
sum += Math.pow(2, 17 - index) % 11 * Number(id[index]);
|
|
232
234
|
}
|
|
233
|
-
|
|
235
|
+
|
|
236
|
+
num = (12 - sum % 11) % 11;
|
|
237
|
+
|
|
234
238
|
if (num < 10) {
|
|
235
239
|
return num === Number(id[17]);
|
|
236
240
|
} else {
|
|
237
241
|
return id[17].toUpperCase() === 'X';
|
|
238
242
|
}
|
|
239
243
|
}
|
|
240
|
-
|
|
241
244
|
/**
|
|
242
245
|
* 检测值是否为18位身份证号码。<br/>宽松模式下,支持15位身份证号码
|
|
243
246
|
*
|
|
@@ -267,8 +270,17 @@
|
|
|
267
270
|
* // => true
|
|
268
271
|
*
|
|
269
272
|
*/
|
|
270
|
-
|
|
271
|
-
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
function isIdCard(value) {
|
|
276
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
277
|
+
_ref$loose = _ref.loose,
|
|
278
|
+
loose = _ref$loose === void 0 ? false : _ref$loose,
|
|
279
|
+
_ref$checkCode = _ref.checkCode,
|
|
280
|
+
checkCode = _ref$checkCode === void 0 ? true : _ref$checkCode;
|
|
281
|
+
|
|
282
|
+
var valueStr = normalizeString(value);
|
|
283
|
+
|
|
272
284
|
if (valueStr.length === 15 && loose) {
|
|
273
285
|
return regIdCard$1.test(valueStr);
|
|
274
286
|
}
|
|
@@ -277,15 +289,14 @@
|
|
|
277
289
|
if (checkCode) {
|
|
278
290
|
return check(valueStr);
|
|
279
291
|
}
|
|
292
|
+
|
|
280
293
|
return true;
|
|
281
294
|
}
|
|
282
295
|
|
|
283
296
|
return false;
|
|
284
297
|
}
|
|
285
298
|
|
|
286
|
-
|
|
287
|
-
const reg$a = /^[\da-z]+([\-\.\_]?[\da-z]+)*@[\da-z]+([\-\.]?[\da-z]+)*(\.[a-z]{2,})+$/i;
|
|
288
|
-
|
|
299
|
+
var reg$a = /^[\da-z]+([\-\.\_]?[\da-z]+)*@[\da-z]+([\-\.]?[\da-z]+)*(\.[a-z]{2,})+$/i;
|
|
289
300
|
/**
|
|
290
301
|
* 检测值是否为Email
|
|
291
302
|
*
|
|
@@ -303,14 +314,13 @@
|
|
|
303
314
|
* // => false
|
|
304
315
|
*
|
|
305
316
|
*/
|
|
317
|
+
|
|
306
318
|
function isEmail(value) {
|
|
307
|
-
|
|
319
|
+
var valueStr = normalizeString(value);
|
|
308
320
|
return reg$a.test(valueStr);
|
|
309
321
|
}
|
|
310
322
|
|
|
311
|
-
|
|
312
|
-
const reg$9 = /^[1-9]\d{4,10}$/;
|
|
313
|
-
|
|
323
|
+
var reg$9 = /^[1-9]\d{4,10}$/;
|
|
314
324
|
/**
|
|
315
325
|
* 检测值是否为QQ号,非0开头,5至11位数字
|
|
316
326
|
*
|
|
@@ -328,14 +338,13 @@
|
|
|
328
338
|
* // => false
|
|
329
339
|
*
|
|
330
340
|
*/
|
|
341
|
+
|
|
331
342
|
function isQQ(value) {
|
|
332
|
-
|
|
343
|
+
var valueStr = normalizeString(value);
|
|
333
344
|
return reg$9.test(valueStr);
|
|
334
345
|
}
|
|
335
346
|
|
|
336
|
-
|
|
337
|
-
const reg$8 = /^[a-z]([-_a-z0-9]{5,19})+$/i;
|
|
338
|
-
|
|
347
|
+
var reg$8 = /^[a-z]([-_a-z0-9]{5,19})+$/i;
|
|
339
348
|
/**
|
|
340
349
|
* 检测值是否为微信号
|
|
341
350
|
*
|
|
@@ -353,14 +362,13 @@
|
|
|
353
362
|
* // => false
|
|
354
363
|
*
|
|
355
364
|
*/
|
|
365
|
+
|
|
356
366
|
function isWX(value) {
|
|
357
|
-
|
|
367
|
+
var valueStr = normalizeString(value);
|
|
358
368
|
return reg$8.test(valueStr);
|
|
359
369
|
}
|
|
360
370
|
|
|
361
|
-
|
|
362
|
-
const reg$7 = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})|([A-Z0-9]{5}[DF])|([DF][A-Z0-9]{5}))$/;
|
|
363
|
-
|
|
371
|
+
var reg$7 = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})|([A-Z0-9]{5}[DF])|([DF][A-Z0-9]{5}))$/;
|
|
364
372
|
/**
|
|
365
373
|
* 检测值是否为车牌号,支持新能源和非新能源车牌
|
|
366
374
|
*
|
|
@@ -388,35 +396,34 @@
|
|
|
388
396
|
* // => true
|
|
389
397
|
*
|
|
390
398
|
*/
|
|
399
|
+
|
|
391
400
|
function isVehicle(value) {
|
|
392
|
-
|
|
401
|
+
var valueStr = normalizeString(value);
|
|
393
402
|
return reg$7.test(valueStr);
|
|
394
403
|
}
|
|
395
404
|
|
|
396
|
-
//
|
|
397
|
-
const reg$6 = /^[1-9]\d{9,20}$/;
|
|
398
|
-
|
|
399
|
-
// 8~30位数字
|
|
400
|
-
const regLoose = /^\d{8,30}$/;
|
|
405
|
+
var reg$6 = /^[1-9]\d{9,20}$/; // 8~30位数字
|
|
401
406
|
|
|
407
|
+
var regLoose = /^\d{8,30}$/;
|
|
402
408
|
/**
|
|
403
409
|
* luhn 计算校验位
|
|
404
410
|
* @private
|
|
405
411
|
* @param {string} numStr 银行卡前面数字
|
|
406
412
|
* @returns {number}
|
|
407
413
|
*/
|
|
414
|
+
|
|
408
415
|
function sumCheckCode$2(numStr) {
|
|
409
|
-
|
|
416
|
+
var numArr = (numStr + '').replace(/\D/g, '').split('').reverse();
|
|
417
|
+
var sum = 0;
|
|
410
418
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
const currNum = parseInt(numArr[i]);
|
|
419
|
+
for (var i = 0; i < numArr.length; i++) {
|
|
420
|
+
var currNum = parseInt(numArr[i]);
|
|
414
421
|
sum += i % 2 === 0 ? currNum * 2 - (currNum > 4 ? 9 : 0) : currNum;
|
|
415
422
|
}
|
|
416
|
-
|
|
423
|
+
|
|
424
|
+
var mod = sum % 10;
|
|
417
425
|
return mod !== 0 ? 10 - mod : 0;
|
|
418
426
|
}
|
|
419
|
-
|
|
420
427
|
/**
|
|
421
428
|
* 检测值是否为银行卡号。正常模式(非0开头,10~21位数字)宽松模式(8~30位数字)
|
|
422
429
|
*
|
|
@@ -444,24 +451,30 @@
|
|
|
444
451
|
* // => true
|
|
445
452
|
*
|
|
446
453
|
*/
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
function isBankCard(value) {
|
|
457
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
458
|
+
_ref$loose = _ref.loose,
|
|
459
|
+
loose = _ref$loose === void 0 ? false : _ref$loose,
|
|
460
|
+
_ref$luhn = _ref.luhn,
|
|
461
|
+
luhn = _ref$luhn === void 0 ? false : _ref$luhn;
|
|
462
|
+
|
|
463
|
+
var valueStr = normalizeString(value);
|
|
464
|
+
var validateResult = loose ? regLoose.test(valueStr) : reg$6.test(valueStr);
|
|
450
465
|
|
|
451
466
|
if (validateResult && luhn) {
|
|
452
|
-
|
|
453
|
-
|
|
467
|
+
var precode = valueStr.substring(0, valueStr.length - 1);
|
|
468
|
+
var checkCode = valueStr[valueStr.length - 1];
|
|
454
469
|
return checkCode === String(sumCheckCode$2(precode));
|
|
455
470
|
}
|
|
471
|
+
|
|
456
472
|
return validateResult;
|
|
457
473
|
}
|
|
458
474
|
|
|
459
|
-
//
|
|
460
|
-
const baseReg$1 = /^[\dA-HJ-NPQRTUWXY]{2}\d{6}[\dA-HJ-NPQRTUWXY]{10}$/;
|
|
461
|
-
|
|
462
|
-
// 基础字符组成
|
|
463
|
-
const baseCodeArr = '0123456789ABCDEFGHJKLMNPQRTUWXY'.split('');
|
|
475
|
+
var baseReg$1 = /^[\dA-HJ-NPQRTUWXY]{2}\d{6}[\dA-HJ-NPQRTUWXY]{10}$/; // 基础字符组成
|
|
464
476
|
|
|
477
|
+
var baseCodeArr = '0123456789ABCDEFGHJKLMNPQRTUWXY'.split('');
|
|
465
478
|
/**
|
|
466
479
|
* 计算校验码
|
|
467
480
|
*
|
|
@@ -470,27 +483,31 @@
|
|
|
470
483
|
* @param {string} preCode 统一代码前17位
|
|
471
484
|
* @returns {string} 校验码
|
|
472
485
|
*/
|
|
486
|
+
|
|
473
487
|
function sumCheckCode$1(preCode) {
|
|
474
|
-
|
|
488
|
+
var total = 0; // 计算字符位置对应序号和加权因子的乘积,总和
|
|
475
489
|
|
|
476
|
-
|
|
477
|
-
for (let i = 0; i < 17; i++) {
|
|
490
|
+
var _loop = function _loop(i) {
|
|
478
491
|
// 字符位置对应的基础编码序号
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
492
|
+
var index = baseCodeArr.findIndex(function (item) {
|
|
493
|
+
return item === preCode[i];
|
|
494
|
+
}); // 加权因子
|
|
495
|
+
|
|
496
|
+
var wf = Math.pow(3, i) % 31; // 计算序号和加权因子的乘积,并计算级数之和
|
|
497
|
+
|
|
483
498
|
total += index * wf;
|
|
484
|
-
}
|
|
499
|
+
};
|
|
485
500
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
//
|
|
489
|
-
const checkCodeIndex = remainder !== 0 ? 31 - remainder : 0;
|
|
501
|
+
for (var i = 0; i < 17; i++) {
|
|
502
|
+
_loop(i);
|
|
503
|
+
} // 计算整数求余函数MOD
|
|
490
504
|
|
|
505
|
+
|
|
506
|
+
var remainder = total % 31; // 校验码字符值序号
|
|
507
|
+
|
|
508
|
+
var checkCodeIndex = remainder !== 0 ? 31 - remainder : 0;
|
|
491
509
|
return baseCodeArr[checkCodeIndex];
|
|
492
510
|
}
|
|
493
|
-
|
|
494
511
|
/**
|
|
495
512
|
* 检测值是否为统一社会信用代码,也叫三证合一组织代码。由18位数字和大写字母组成,不使用I、O、Z、S、V。
|
|
496
513
|
*
|
|
@@ -518,35 +535,37 @@
|
|
|
518
535
|
* // => false
|
|
519
536
|
*
|
|
520
537
|
*/
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
function isSocialCreditCode(value) {
|
|
541
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
542
|
+
var valueStr = normalizeString(value); // @ts-ignore
|
|
524
543
|
// TODO 下个版本废弃 loose
|
|
525
|
-
const { loose = false, checkCode: cc = true } = options;
|
|
526
|
-
const needCheckCode = !loose && cc;
|
|
527
544
|
|
|
528
|
-
|
|
545
|
+
var _options$loose = options.loose,
|
|
546
|
+
loose = _options$loose === void 0 ? false : _options$loose,
|
|
547
|
+
_options$checkCode = options.checkCode,
|
|
548
|
+
cc = _options$checkCode === void 0 ? true : _options$checkCode;
|
|
549
|
+
var needCheckCode = !loose && cc;
|
|
550
|
+
var passBaseRule = baseReg$1.test(valueStr); // 宽松模式 或 基础规则不通过直接返回
|
|
529
551
|
|
|
530
|
-
// 宽松模式 或 基础规则不通过直接返回
|
|
531
552
|
if (!needCheckCode || !passBaseRule) {
|
|
532
553
|
return passBaseRule;
|
|
533
|
-
}
|
|
554
|
+
} // 前17位
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
var preCode = valueStr.substring(0, 17); // 校验码
|
|
534
558
|
|
|
535
|
-
//
|
|
536
|
-
const preCode = valueStr.substring(0, 17);
|
|
537
|
-
// 校验码
|
|
538
|
-
const lastCode = valueStr.substring(valueStr.length - 1);
|
|
539
|
-
// 计算校验码
|
|
540
|
-
const checkCode = sumCheckCode$1(preCode);
|
|
559
|
+
var lastCode = valueStr.substring(valueStr.length - 1); // 计算校验码
|
|
541
560
|
|
|
561
|
+
var checkCode = sumCheckCode$1(preCode);
|
|
542
562
|
return lastCode === checkCode;
|
|
543
563
|
}
|
|
544
564
|
|
|
545
|
-
|
|
565
|
+
var config = {
|
|
546
566
|
// 禁用warning提示
|
|
547
567
|
disableWarning: true
|
|
548
568
|
};
|
|
549
|
-
|
|
550
569
|
/**
|
|
551
570
|
* 设置禁止warning提示
|
|
552
571
|
* @static
|
|
@@ -554,6 +573,7 @@
|
|
|
554
573
|
* @since 3.6.1
|
|
555
574
|
* @param {boolean} bool 是否禁止warning提示
|
|
556
575
|
*/
|
|
576
|
+
|
|
557
577
|
function setDisableWarning(bool) {
|
|
558
578
|
config.disableWarning = !!bool;
|
|
559
579
|
}
|
|
@@ -563,17 +583,19 @@
|
|
|
563
583
|
*
|
|
564
584
|
* @param {any[]} args 打印的信息
|
|
565
585
|
*/
|
|
566
|
-
|
|
586
|
+
|
|
587
|
+
function devWarn() {
|
|
567
588
|
if (!config.disableWarning) {
|
|
568
|
-
|
|
589
|
+
var _console;
|
|
590
|
+
|
|
591
|
+
(_console = console).warn.apply(_console, arguments);
|
|
569
592
|
}
|
|
570
593
|
}
|
|
571
594
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
595
|
+
var regNumber = /[\d]/;
|
|
596
|
+
var regLowerCaseLetter = /[a-z]/;
|
|
597
|
+
var regUpperCaseLetter = /[A-Z]/;
|
|
598
|
+
var regAllNumberAndLetter = /[\d|a-z]/gi;
|
|
577
599
|
/**
|
|
578
600
|
* 是否包含数字
|
|
579
601
|
*
|
|
@@ -581,10 +603,10 @@
|
|
|
581
603
|
* @param {string} val 检查的值
|
|
582
604
|
* @returns {boolean} 是否包含数字
|
|
583
605
|
*/
|
|
606
|
+
|
|
584
607
|
function hasNumber(val) {
|
|
585
608
|
return regNumber.test(val);
|
|
586
609
|
}
|
|
587
|
-
|
|
588
610
|
/**
|
|
589
611
|
* 是否包含小写字母
|
|
590
612
|
*
|
|
@@ -592,10 +614,11 @@
|
|
|
592
614
|
* @param {string} val 检测的值
|
|
593
615
|
* @returns {boolean} 是否包含小写字母
|
|
594
616
|
*/
|
|
617
|
+
|
|
618
|
+
|
|
595
619
|
function hasLowerCaseLetter(val) {
|
|
596
620
|
return regLowerCaseLetter.test(val);
|
|
597
621
|
}
|
|
598
|
-
|
|
599
622
|
/**
|
|
600
623
|
* 是否包含大写字母
|
|
601
624
|
*
|
|
@@ -603,10 +626,11 @@
|
|
|
603
626
|
* @param {string} val 检测的值
|
|
604
627
|
* @returns {boolean} 是否包含大写字母
|
|
605
628
|
*/
|
|
629
|
+
|
|
630
|
+
|
|
606
631
|
function hasUpperCaseLetter(val) {
|
|
607
632
|
return regUpperCaseLetter.test(val);
|
|
608
633
|
}
|
|
609
|
-
|
|
610
634
|
/**
|
|
611
635
|
* 是否为十六进制
|
|
612
636
|
*
|
|
@@ -614,10 +638,11 @@
|
|
|
614
638
|
* @param {string} val 检测的值
|
|
615
639
|
* @returns {boolean} 是否为十六进制
|
|
616
640
|
*/
|
|
641
|
+
|
|
642
|
+
|
|
617
643
|
function hasHex(val) {
|
|
618
|
-
return val.indexOf('\\x') > -1 || val.indexOf(
|
|
644
|
+
return val.indexOf('\\x') > -1 || val.indexOf("\\u") > -1;
|
|
619
645
|
}
|
|
620
|
-
|
|
621
646
|
/**
|
|
622
647
|
* 是否包含特殊字符
|
|
623
648
|
*
|
|
@@ -626,33 +651,35 @@
|
|
|
626
651
|
* @param {string} chars 特殊字符
|
|
627
652
|
* @returns {boolean} 是否包含特殊字符
|
|
628
653
|
*/
|
|
654
|
+
|
|
655
|
+
|
|
629
656
|
function hasSpecialCharacter(val, chars) {
|
|
630
657
|
if (!chars || !val) {
|
|
631
658
|
return false;
|
|
632
659
|
}
|
|
633
660
|
|
|
634
|
-
|
|
661
|
+
var specialChars = val.replace(regAllNumberAndLetter, '');
|
|
635
662
|
|
|
636
663
|
if (!specialChars) {
|
|
637
664
|
return false;
|
|
638
665
|
}
|
|
639
666
|
|
|
640
|
-
|
|
667
|
+
var regChars = hasHex(chars) ? new RegExp("[".concat(chars, "]")) : null;
|
|
641
668
|
|
|
642
669
|
if (regChars) {
|
|
643
670
|
return regChars.test(specialChars);
|
|
644
671
|
}
|
|
645
672
|
|
|
646
|
-
|
|
647
|
-
specialChars.split('').some((charItem)
|
|
673
|
+
var ret = false;
|
|
674
|
+
specialChars.split('').some(function (charItem) {
|
|
648
675
|
if (chars.indexOf(charItem) > -1) {
|
|
649
676
|
ret = true;
|
|
650
677
|
}
|
|
678
|
+
|
|
651
679
|
return ret;
|
|
652
680
|
});
|
|
653
681
|
return ret;
|
|
654
682
|
}
|
|
655
|
-
|
|
656
683
|
/**
|
|
657
684
|
* 是否包含非法字符
|
|
658
685
|
*
|
|
@@ -661,12 +688,14 @@
|
|
|
661
688
|
* @param {string} chars 特殊字符
|
|
662
689
|
* @returns {boolean} 是否包含非法字符
|
|
663
690
|
*/
|
|
691
|
+
|
|
692
|
+
|
|
664
693
|
function hasUnallowableCharacter(val, chars) {
|
|
665
694
|
if (!val) {
|
|
666
695
|
return false;
|
|
667
696
|
}
|
|
668
697
|
|
|
669
|
-
|
|
698
|
+
var specialChars = val.replace(regAllNumberAndLetter, '');
|
|
670
699
|
|
|
671
700
|
if (!specialChars) {
|
|
672
701
|
return false;
|
|
@@ -674,20 +703,22 @@
|
|
|
674
703
|
return true;
|
|
675
704
|
}
|
|
676
705
|
|
|
677
|
-
|
|
706
|
+
var regChars = hasHex(chars) ? new RegExp("[^".concat(chars, "]")) : null;
|
|
707
|
+
|
|
678
708
|
if (regChars) {
|
|
679
709
|
return regChars.test(specialChars);
|
|
680
710
|
}
|
|
681
|
-
|
|
682
|
-
|
|
711
|
+
|
|
712
|
+
var ret = false;
|
|
713
|
+
specialChars.split('').some(function (charItem) {
|
|
683
714
|
if (chars.indexOf(charItem) === -1) {
|
|
684
715
|
ret = true;
|
|
685
716
|
}
|
|
717
|
+
|
|
686
718
|
return ret;
|
|
687
719
|
});
|
|
688
720
|
return ret;
|
|
689
721
|
}
|
|
690
|
-
|
|
691
722
|
/**
|
|
692
723
|
* @typedef {Object} PasswordContaines - 验证密码的包含内容
|
|
693
724
|
* @property {boolean} number - 包含数字
|
|
@@ -776,32 +807,41 @@
|
|
|
776
807
|
* }
|
|
777
808
|
* }
|
|
778
809
|
*/
|
|
779
|
-
|
|
780
|
-
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
function validatePassword(value) {
|
|
813
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
814
|
+
_ref$level = _ref.level,
|
|
815
|
+
level = _ref$level === void 0 ? 2 : _ref$level,
|
|
816
|
+
_ref$ignoreCase = _ref.ignoreCase,
|
|
817
|
+
ignoreCase = _ref$ignoreCase === void 0 ? false : _ref$ignoreCase,
|
|
818
|
+
_ref$special = _ref.special,
|
|
819
|
+
special = _ref$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _ref$special;
|
|
820
|
+
|
|
821
|
+
var valStr = value;
|
|
781
822
|
|
|
782
823
|
if (typeof value !== 'string') {
|
|
783
|
-
devWarn(
|
|
824
|
+
devWarn("[validatePassword] value must be a string.");
|
|
784
825
|
valStr = '';
|
|
785
826
|
}
|
|
786
827
|
|
|
787
|
-
|
|
828
|
+
var currentLevel = 0; // 包含数字
|
|
829
|
+
|
|
830
|
+
var containesNumber = hasNumber(valStr); // 包含小写字母
|
|
831
|
+
|
|
832
|
+
var containesLowerCaseLetter = hasLowerCaseLetter(valStr); // 包含大写字母
|
|
833
|
+
|
|
834
|
+
var containesUpperCaseLetter = hasUpperCaseLetter(valStr); // 包含特殊字符
|
|
788
835
|
|
|
789
|
-
//
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
const containesLowerCaseLetter = hasLowerCaseLetter(valStr);
|
|
793
|
-
// 包含大写字母
|
|
794
|
-
const containesUpperCaseLetter = hasUpperCaseLetter(valStr);
|
|
795
|
-
// 包含特殊字符
|
|
796
|
-
const containesSpecialCharacter = hasSpecialCharacter(valStr, special);
|
|
797
|
-
// 包含非法字符,即含有非数字字母特殊字符以外的其他字符
|
|
798
|
-
const containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
|
|
836
|
+
var containesSpecialCharacter = hasSpecialCharacter(valStr, special); // 包含非法字符,即含有非数字字母特殊字符以外的其他字符
|
|
837
|
+
|
|
838
|
+
var containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
|
|
799
839
|
|
|
800
840
|
if (containesNumber) {
|
|
801
841
|
currentLevel += 1;
|
|
802
|
-
}
|
|
842
|
+
} // 不区分大小写
|
|
843
|
+
|
|
803
844
|
|
|
804
|
-
// 不区分大小写
|
|
805
845
|
if (ignoreCase) {
|
|
806
846
|
if (containesLowerCaseLetter || containesUpperCaseLetter) {
|
|
807
847
|
currentLevel += 1;
|
|
@@ -811,6 +851,7 @@
|
|
|
811
851
|
if (containesLowerCaseLetter) {
|
|
812
852
|
currentLevel += 1;
|
|
813
853
|
}
|
|
854
|
+
|
|
814
855
|
if (containesUpperCaseLetter) {
|
|
815
856
|
currentLevel += 1;
|
|
816
857
|
}
|
|
@@ -818,13 +859,12 @@
|
|
|
818
859
|
|
|
819
860
|
if (containesSpecialCharacter) {
|
|
820
861
|
currentLevel += 1;
|
|
821
|
-
}
|
|
862
|
+
} // 验证结果
|
|
822
863
|
|
|
823
|
-
// 验证结果
|
|
824
|
-
const validated = currentLevel >= level && !containesUnallowableCharacter;
|
|
825
864
|
|
|
865
|
+
var validated = currentLevel >= level && !containesUnallowableCharacter;
|
|
826
866
|
return {
|
|
827
|
-
validated,
|
|
867
|
+
validated: validated,
|
|
828
868
|
level: currentLevel,
|
|
829
869
|
containes: {
|
|
830
870
|
number: containesNumber,
|
|
@@ -876,13 +916,24 @@
|
|
|
876
916
|
* isPassword(' _Aa12345678', {level: 3, ignoreCase: true});
|
|
877
917
|
* // => false
|
|
878
918
|
*/
|
|
879
|
-
function isPassword(value, { level = 2, ignoreCase = false, special = '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' } = {}) {
|
|
880
|
-
return validatePassword(value, { level, ignoreCase, special }).validated;
|
|
881
|
-
}
|
|
882
919
|
|
|
883
|
-
|
|
884
|
-
|
|
920
|
+
function isPassword(value) {
|
|
921
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
922
|
+
_ref$level = _ref.level,
|
|
923
|
+
level = _ref$level === void 0 ? 2 : _ref$level,
|
|
924
|
+
_ref$ignoreCase = _ref.ignoreCase,
|
|
925
|
+
ignoreCase = _ref$ignoreCase === void 0 ? false : _ref$ignoreCase,
|
|
926
|
+
_ref$special = _ref.special,
|
|
927
|
+
special = _ref$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _ref$special;
|
|
928
|
+
|
|
929
|
+
return validatePassword(value, {
|
|
930
|
+
level: level,
|
|
931
|
+
ignoreCase: ignoreCase,
|
|
932
|
+
special: special
|
|
933
|
+
}).validated;
|
|
934
|
+
}
|
|
885
935
|
|
|
936
|
+
var reg$5 = /^((e[\da-z])|(de)|(se)|(pe)|([khm][\da-z]))[\da-z]{7}$/i;
|
|
886
937
|
/**
|
|
887
938
|
* 检测值是否为护照号
|
|
888
939
|
* 支持普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ/H*)、澳门特区护照(MA/MB/M*),注意不区分大小写
|
|
@@ -902,47 +953,37 @@
|
|
|
902
953
|
* // => false
|
|
903
954
|
*
|
|
904
955
|
*/
|
|
956
|
+
|
|
905
957
|
function isPassport(value) {
|
|
906
|
-
|
|
958
|
+
var valueStr = normalizeString(value);
|
|
907
959
|
return reg$5.test(valueStr);
|
|
908
960
|
}
|
|
909
961
|
|
|
910
|
-
|
|
962
|
+
var chineseDictionary = {
|
|
911
963
|
// 基本汉字
|
|
912
|
-
chineseBasic:
|
|
913
|
-
|
|
964
|
+
chineseBasic: "[\u4E00-\u9FA5]",
|
|
914
965
|
// 基本汉字补充
|
|
915
|
-
chineseExtend:
|
|
916
|
-
|
|
966
|
+
chineseExtend: "[\u9EA6-\u9FEF]",
|
|
917
967
|
// 汉字扩展A
|
|
918
|
-
chineseExtendA:
|
|
919
|
-
|
|
968
|
+
chineseExtendA: "[\u3400-\u4DB5]",
|
|
920
969
|
// 汉字扩展B
|
|
921
|
-
chineseExtendB:
|
|
922
|
-
|
|
970
|
+
chineseExtendB: "[\uD840\uDC00-\uD869\uDED6]",
|
|
923
971
|
// 汉字扩展C
|
|
924
|
-
chineseExtendC:
|
|
925
|
-
|
|
972
|
+
chineseExtendC: "[\uD869\uDF00-\uD86D\uDF34]",
|
|
926
973
|
// 汉字扩展D
|
|
927
|
-
chineseExtendD:
|
|
928
|
-
|
|
974
|
+
chineseExtendD: "[\uD86D\uDF40-\uD86E\uDC1D]",
|
|
929
975
|
// 汉字扩展E
|
|
930
|
-
chineseExtendE:
|
|
931
|
-
|
|
976
|
+
chineseExtendE: "[\uD86E\uDC20-\uD873\uDEA1]",
|
|
932
977
|
// 汉字扩展F
|
|
933
|
-
chineseExtendF:
|
|
978
|
+
chineseExtendF: "[\uD873\uDEB0-\uD87A\uDFE0]"
|
|
934
979
|
};
|
|
980
|
+
var looseChineseRegExp = chineseDictionary.chineseBasic + '+';
|
|
981
|
+
var chineseRegExp = '^' + chineseDictionary.chineseBasic + '+$';
|
|
982
|
+
var chineseWithExtend = '(?:' + chineseDictionary.chineseBasic + '|' + chineseDictionary.chineseExtend + '|' + chineseDictionary.chineseExtendA + '|' + chineseDictionary.chineseExtendB + '|' + chineseDictionary.chineseExtendC + '|' + chineseDictionary.chineseExtendD + '|' + chineseDictionary.chineseExtendE + '|' + chineseDictionary.chineseExtendF + ')';
|
|
983
|
+
var looseChineseExtendRegExp = chineseWithExtend + '+';
|
|
984
|
+
var chineseExtendRegExp = '^' + chineseWithExtend + '+$'; // eslint-disable-next-line no-prototype-builtins
|
|
935
985
|
|
|
936
|
-
|
|
937
|
-
const chineseRegExp = '^' + chineseDictionary.chineseBasic + '+$';
|
|
938
|
-
|
|
939
|
-
const chineseWithExtend = '(?:' + chineseDictionary.chineseBasic + '|' + chineseDictionary.chineseExtend + '|' + chineseDictionary.chineseExtendA + '|' + chineseDictionary.chineseExtendB + '|' + chineseDictionary.chineseExtendC + '|' + chineseDictionary.chineseExtendD + '|' + chineseDictionary.chineseExtendE + '|' + chineseDictionary.chineseExtendF + ')';
|
|
940
|
-
const looseChineseExtendRegExp = chineseWithExtend + '+';
|
|
941
|
-
const chineseExtendRegExp = '^' + chineseWithExtend + '+$';
|
|
942
|
-
|
|
943
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
944
|
-
const supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');
|
|
945
|
-
|
|
986
|
+
var supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');
|
|
946
987
|
/**
|
|
947
988
|
* 检测值是否为中文
|
|
948
989
|
*
|
|
@@ -979,21 +1020,25 @@
|
|
|
979
1020
|
* isChinese('𠮷aa', { useExtend: true, loose: true });
|
|
980
1021
|
* // => true
|
|
981
1022
|
*/
|
|
982
|
-
function isChinese(value, { loose = false, useExtend = false } = {}) {
|
|
983
|
-
const valueStr = normalizeString(value);
|
|
984
|
-
const basicRegExp = loose ? looseChineseRegExp : chineseRegExp;
|
|
985
|
-
const extendRegExp = loose ? looseChineseExtendRegExp : chineseExtendRegExp;
|
|
986
1023
|
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1024
|
+
function isChinese(value) {
|
|
1025
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1026
|
+
_ref$loose = _ref.loose,
|
|
1027
|
+
loose = _ref$loose === void 0 ? false : _ref$loose,
|
|
1028
|
+
_ref$useExtend = _ref.useExtend,
|
|
1029
|
+
useExtend = _ref$useExtend === void 0 ? false : _ref$useExtend;
|
|
1030
|
+
|
|
1031
|
+
var valueStr = normalizeString(value);
|
|
1032
|
+
var basicRegExp = loose ? looseChineseRegExp : chineseRegExp;
|
|
1033
|
+
var extendRegExp = loose ? looseChineseExtendRegExp : chineseExtendRegExp;
|
|
1034
|
+
var hasExtend = useExtend && supportRegExpUnicode;
|
|
1035
|
+
var resultRegExp = hasExtend ? extendRegExp : basicRegExp;
|
|
1036
|
+
var flag = hasExtend ? 'u' : undefined;
|
|
1037
|
+
var reg = new RegExp(resultRegExp, flag);
|
|
991
1038
|
return reg.test(valueStr);
|
|
992
1039
|
}
|
|
993
1040
|
|
|
994
|
-
|
|
995
|
-
const reg$4 = /^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
|
|
996
|
-
|
|
1041
|
+
var reg$4 = /^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
|
|
997
1042
|
/**
|
|
998
1043
|
* 检测值是否为ipv4
|
|
999
1044
|
*
|
|
@@ -1017,14 +1062,13 @@
|
|
|
1017
1062
|
* // => false
|
|
1018
1063
|
*
|
|
1019
1064
|
*/
|
|
1065
|
+
|
|
1020
1066
|
function isIPv4(value) {
|
|
1021
|
-
|
|
1067
|
+
var valueStr = normalizeString(value);
|
|
1022
1068
|
return reg$4.test(valueStr);
|
|
1023
1069
|
}
|
|
1024
1070
|
|
|
1025
|
-
|
|
1026
|
-
const reg$3 = /^((([0-9A-F]{1,4}:){7}([0-9A-F]{1,4}|:))|(([0-9A-F]{1,4}:){6}(:[0-9A-F]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3})|:))|(([0-9A-F]{1,4}:){5}(((:[0-9A-F]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3})|:))|(([0-9A-F]{1,4}:){4}(((:[0-9A-F]{1,4}){1,3})|((:[0-9A-F]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){3}(((:[0-9A-F]{1,4}){1,4})|((:[0-9A-F]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){2}(((:[0-9A-F]{1,4}){1,5})|((:[0-9A-F]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){1}(((:[0-9A-F]{1,4}){1,6})|((:[0-9A-F]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(:(((:[0-9A-F]{1,4}){1,7})|((:[0-9A-F]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:)))(%.+)?$/i;
|
|
1027
|
-
|
|
1071
|
+
var reg$3 = /^((([0-9A-F]{1,4}:){7}([0-9A-F]{1,4}|:))|(([0-9A-F]{1,4}:){6}(:[0-9A-F]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3})|:))|(([0-9A-F]{1,4}:){5}(((:[0-9A-F]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3})|:))|(([0-9A-F]{1,4}:){4}(((:[0-9A-F]{1,4}){1,3})|((:[0-9A-F]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){3}(((:[0-9A-F]{1,4}){1,4})|((:[0-9A-F]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){2}(((:[0-9A-F]{1,4}){1,5})|((:[0-9A-F]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){1}(((:[0-9A-F]{1,4}){1,6})|((:[0-9A-F]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(:(((:[0-9A-F]{1,4}){1,7})|((:[0-9A-F]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:)))(%.+)?$/i;
|
|
1028
1072
|
/**
|
|
1029
1073
|
* 检测值是否为ipv6
|
|
1030
1074
|
*
|
|
@@ -1073,14 +1117,13 @@
|
|
|
1073
1117
|
* // => false
|
|
1074
1118
|
*
|
|
1075
1119
|
*/
|
|
1120
|
+
|
|
1076
1121
|
function isIPv6(value) {
|
|
1077
|
-
|
|
1122
|
+
var valueStr = normalizeString(value);
|
|
1078
1123
|
return reg$3.test(valueStr);
|
|
1079
1124
|
}
|
|
1080
1125
|
|
|
1081
|
-
|
|
1082
|
-
const reg$2 = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\*\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
|
|
1083
|
-
|
|
1126
|
+
var reg$2 = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\*\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
|
|
1084
1127
|
/**
|
|
1085
1128
|
* 检测值是否为url
|
|
1086
1129
|
*
|
|
@@ -1113,14 +1156,13 @@
|
|
|
1113
1156
|
* isUrl('http://www.example.com/test/123?foo=bar');
|
|
1114
1157
|
* // => true
|
|
1115
1158
|
*/
|
|
1159
|
+
|
|
1116
1160
|
function isUrl(value) {
|
|
1117
|
-
|
|
1161
|
+
var valueStr = normalizeString(value);
|
|
1118
1162
|
return reg$2.test(valueStr);
|
|
1119
1163
|
}
|
|
1120
1164
|
|
|
1121
|
-
|
|
1122
|
-
const baseReg = /^\d{15}$/;
|
|
1123
|
-
|
|
1165
|
+
var baseReg = /^\d{15}$/;
|
|
1124
1166
|
/**
|
|
1125
1167
|
* 计算校验码
|
|
1126
1168
|
*
|
|
@@ -1129,20 +1171,21 @@
|
|
|
1129
1171
|
* @param {string} preCode 营业执照前14位
|
|
1130
1172
|
* @returns {number} 校验码
|
|
1131
1173
|
*/
|
|
1174
|
+
|
|
1132
1175
|
function sumCheckCode(preCode) {
|
|
1133
|
-
|
|
1176
|
+
var retNum; // 校验位数字
|
|
1134
1177
|
|
|
1135
|
-
|
|
1178
|
+
var pj = 10; // Pj+1 11,初始为10
|
|
1136
1179
|
|
|
1137
|
-
for (
|
|
1138
|
-
|
|
1139
|
-
|
|
1180
|
+
for (var j = 0; j < 14; j++) {
|
|
1181
|
+
var sj = pj + Number(preCode[j]);
|
|
1182
|
+
var sj10 = sj % 10;
|
|
1140
1183
|
sj10 = sj10 === 0 ? 10 : sj10;
|
|
1141
|
-
|
|
1184
|
+
var pj1 = sj10 * 2;
|
|
1142
1185
|
pj = pj1 % 11;
|
|
1143
|
-
}
|
|
1186
|
+
} // 反模10计算
|
|
1187
|
+
|
|
1144
1188
|
|
|
1145
|
-
// 反模10计算
|
|
1146
1189
|
if (pj === 1) {
|
|
1147
1190
|
retNum = 0;
|
|
1148
1191
|
} else {
|
|
@@ -1151,7 +1194,6 @@
|
|
|
1151
1194
|
|
|
1152
1195
|
return retNum;
|
|
1153
1196
|
}
|
|
1154
|
-
|
|
1155
1197
|
/**
|
|
1156
1198
|
* 检测值是否为营业执照号,也叫工商注册号。由14位数字本体码和1位数字校验码组成,其中本体码从左至右依次为:6位首次登记机关码、8位顺序码。
|
|
1157
1199
|
*
|
|
@@ -1177,30 +1219,241 @@
|
|
|
1177
1219
|
* isBusinessLicense('31011560098', { checkCode: false });
|
|
1178
1220
|
* // => false
|
|
1179
1221
|
*/
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
function isBusinessLicense(value) {
|
|
1225
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1226
|
+
var valueStr = normalizeString(value); // @ts-ignore
|
|
1183
1227
|
// TODO 下个版本废弃 loose
|
|
1184
|
-
const { loose = false, checkCode: cc = true } = options;
|
|
1185
|
-
const needCheckCode = !loose && cc;
|
|
1186
1228
|
|
|
1187
|
-
|
|
1229
|
+
var _options$loose = options.loose,
|
|
1230
|
+
loose = _options$loose === void 0 ? false : _options$loose,
|
|
1231
|
+
_options$checkCode = options.checkCode,
|
|
1232
|
+
cc = _options$checkCode === void 0 ? true : _options$checkCode;
|
|
1233
|
+
var needCheckCode = !loose && cc;
|
|
1234
|
+
var passBaseRule = baseReg.test(valueStr); // 宽松模式 或 基础规则不通过直接返回
|
|
1188
1235
|
|
|
1189
|
-
// 宽松模式 或 基础规则不通过直接返回
|
|
1190
1236
|
if (!needCheckCode || !passBaseRule) {
|
|
1191
1237
|
return passBaseRule;
|
|
1192
|
-
}
|
|
1238
|
+
} // 前14位
|
|
1193
1239
|
|
|
1194
|
-
// 前14位
|
|
1195
|
-
const preCode = valueStr.substring(0, 14);
|
|
1196
|
-
// 校验码
|
|
1197
|
-
const lastCode = valueStr.substring(valueStr.length - 1);
|
|
1198
|
-
// 计算校验码
|
|
1199
|
-
const checkCode = sumCheckCode(preCode);
|
|
1200
1240
|
|
|
1241
|
+
var preCode = valueStr.substring(0, 14); // 校验码
|
|
1242
|
+
|
|
1243
|
+
var lastCode = valueStr.substring(valueStr.length - 1); // 计算校验码
|
|
1244
|
+
|
|
1245
|
+
var checkCode = sumCheckCode(preCode);
|
|
1201
1246
|
return lastCode === String(checkCode);
|
|
1202
1247
|
}
|
|
1203
1248
|
|
|
1249
|
+
function _typeof(obj) {
|
|
1250
|
+
"@babel/helpers - typeof";
|
|
1251
|
+
|
|
1252
|
+
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
1253
|
+
_typeof = function (obj) {
|
|
1254
|
+
return typeof obj;
|
|
1255
|
+
};
|
|
1256
|
+
} else {
|
|
1257
|
+
_typeof = function (obj) {
|
|
1258
|
+
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
return _typeof(obj);
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
function _wrapRegExp() {
|
|
1266
|
+
_wrapRegExp = function (re, groups) {
|
|
1267
|
+
return new BabelRegExp(re, undefined, groups);
|
|
1268
|
+
};
|
|
1269
|
+
|
|
1270
|
+
var _super = RegExp.prototype;
|
|
1271
|
+
|
|
1272
|
+
var _groups = new WeakMap();
|
|
1273
|
+
|
|
1274
|
+
function BabelRegExp(re, flags, groups) {
|
|
1275
|
+
var _this = new RegExp(re, flags);
|
|
1276
|
+
|
|
1277
|
+
_groups.set(_this, groups || _groups.get(re));
|
|
1278
|
+
|
|
1279
|
+
return _setPrototypeOf(_this, BabelRegExp.prototype);
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
_inherits(BabelRegExp, RegExp);
|
|
1283
|
+
|
|
1284
|
+
BabelRegExp.prototype.exec = function (str) {
|
|
1285
|
+
var result = _super.exec.call(this, str);
|
|
1286
|
+
|
|
1287
|
+
if (result) result.groups = buildGroups(result, this);
|
|
1288
|
+
return result;
|
|
1289
|
+
};
|
|
1290
|
+
|
|
1291
|
+
BabelRegExp.prototype[Symbol.replace] = function (str, substitution) {
|
|
1292
|
+
if (typeof substitution === "string") {
|
|
1293
|
+
var groups = _groups.get(this);
|
|
1294
|
+
|
|
1295
|
+
return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) {
|
|
1296
|
+
return "$" + groups[name];
|
|
1297
|
+
}));
|
|
1298
|
+
} else if (typeof substitution === "function") {
|
|
1299
|
+
var _this = this;
|
|
1300
|
+
|
|
1301
|
+
return _super[Symbol.replace].call(this, str, function () {
|
|
1302
|
+
var args = arguments;
|
|
1303
|
+
|
|
1304
|
+
if (typeof args[args.length - 1] !== "object") {
|
|
1305
|
+
args = [].slice.call(args);
|
|
1306
|
+
args.push(buildGroups(args, _this));
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
return substitution.apply(this, args);
|
|
1310
|
+
});
|
|
1311
|
+
} else {
|
|
1312
|
+
return _super[Symbol.replace].call(this, str, substitution);
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
|
|
1316
|
+
function buildGroups(result, re) {
|
|
1317
|
+
var g = _groups.get(re);
|
|
1318
|
+
|
|
1319
|
+
return Object.keys(g).reduce(function (groups, name) {
|
|
1320
|
+
groups[name] = result[g[name]];
|
|
1321
|
+
return groups;
|
|
1322
|
+
}, Object.create(null));
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
return _wrapRegExp.apply(this, arguments);
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
function _inherits(subClass, superClass) {
|
|
1329
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
1330
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
1334
|
+
constructor: {
|
|
1335
|
+
value: subClass,
|
|
1336
|
+
writable: true,
|
|
1337
|
+
configurable: true
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1340
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
function _setPrototypeOf(o, p) {
|
|
1344
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
1345
|
+
o.__proto__ = p;
|
|
1346
|
+
return o;
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1349
|
+
return _setPrototypeOf(o, p);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
function _isNativeReflectConstruct() {
|
|
1353
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
1354
|
+
if (Reflect.construct.sham) return false;
|
|
1355
|
+
if (typeof Proxy === "function") return true;
|
|
1356
|
+
|
|
1357
|
+
try {
|
|
1358
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
1359
|
+
return true;
|
|
1360
|
+
} catch (e) {
|
|
1361
|
+
return false;
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
function _construct(Parent, args, Class) {
|
|
1366
|
+
if (_isNativeReflectConstruct()) {
|
|
1367
|
+
_construct = Reflect.construct;
|
|
1368
|
+
} else {
|
|
1369
|
+
_construct = function _construct(Parent, args, Class) {
|
|
1370
|
+
var a = [null];
|
|
1371
|
+
a.push.apply(a, args);
|
|
1372
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
1373
|
+
var instance = new Constructor();
|
|
1374
|
+
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
1375
|
+
return instance;
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
return _construct.apply(null, arguments);
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
function _slicedToArray(arr, i) {
|
|
1383
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
function _toConsumableArray(arr) {
|
|
1387
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
function _arrayWithoutHoles(arr) {
|
|
1391
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
function _arrayWithHoles(arr) {
|
|
1395
|
+
if (Array.isArray(arr)) return arr;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
function _iterableToArray(iter) {
|
|
1399
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
function _iterableToArrayLimit(arr, i) {
|
|
1403
|
+
var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]);
|
|
1404
|
+
|
|
1405
|
+
if (_i == null) return;
|
|
1406
|
+
var _arr = [];
|
|
1407
|
+
var _n = true;
|
|
1408
|
+
var _d = false;
|
|
1409
|
+
|
|
1410
|
+
var _s, _e;
|
|
1411
|
+
|
|
1412
|
+
try {
|
|
1413
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
1414
|
+
_arr.push(_s.value);
|
|
1415
|
+
|
|
1416
|
+
if (i && _arr.length === i) break;
|
|
1417
|
+
}
|
|
1418
|
+
} catch (err) {
|
|
1419
|
+
_d = true;
|
|
1420
|
+
_e = err;
|
|
1421
|
+
} finally {
|
|
1422
|
+
try {
|
|
1423
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
1424
|
+
} finally {
|
|
1425
|
+
if (_d) throw _e;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
return _arr;
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
1433
|
+
if (!o) return;
|
|
1434
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
1435
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1436
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1437
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
1438
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
function _arrayLikeToArray(arr, len) {
|
|
1442
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
1443
|
+
|
|
1444
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
1445
|
+
|
|
1446
|
+
return arr2;
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
function _nonIterableSpread() {
|
|
1450
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
function _nonIterableRest() {
|
|
1454
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1204
1457
|
/**
|
|
1205
1458
|
* 检测值是否类似Promise对象
|
|
1206
1459
|
*
|
|
@@ -1221,12 +1474,10 @@
|
|
|
1221
1474
|
* => true
|
|
1222
1475
|
*/
|
|
1223
1476
|
function isPromiseLike(obj) {
|
|
1224
|
-
return obj !== null && (
|
|
1477
|
+
return obj !== null && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
|
1225
1478
|
}
|
|
1226
1479
|
|
|
1227
|
-
|
|
1228
|
-
const regHMCard = /^[hm]{1}([0-9]{10}|[0-9]{8})$/i;
|
|
1229
|
-
|
|
1480
|
+
var regHMCard = /^[hm]{1}([0-9]{10}|[0-9]{8})$/i;
|
|
1230
1481
|
/**
|
|
1231
1482
|
* 检测值是否为港澳居民来往内地通行证,俗称回乡证或回乡卡。
|
|
1232
1483
|
*
|
|
@@ -1249,17 +1500,15 @@
|
|
|
1249
1500
|
* isHMCard('m32031177') // true
|
|
1250
1501
|
* isHMCard('M32031177') // true
|
|
1251
1502
|
*/
|
|
1503
|
+
|
|
1252
1504
|
function isHMCard(value) {
|
|
1253
|
-
|
|
1505
|
+
var valueStr = normalizeString(value);
|
|
1254
1506
|
return regHMCard.test(valueStr);
|
|
1255
1507
|
}
|
|
1256
1508
|
|
|
1257
|
-
//
|
|
1258
|
-
const regTWCard = /^\d{8}$/i;
|
|
1259
|
-
|
|
1260
|
-
// 一次性短期台胞证
|
|
1261
|
-
const singleRegTWCard = /^[\da-z]{10,12}$/i;
|
|
1509
|
+
var regTWCard = /^\d{8}$/i; // 一次性短期台胞证
|
|
1262
1510
|
|
|
1511
|
+
var singleRegTWCard = /^[\da-z]{10,12}$/i;
|
|
1263
1512
|
/**
|
|
1264
1513
|
* 检测值是否为台湾居民来往大陆通行证,俗称台胞证。
|
|
1265
1514
|
*
|
|
@@ -1279,16 +1528,22 @@
|
|
|
1279
1528
|
* isTWCard('F290299977') // false
|
|
1280
1529
|
* isTWCard('F290299977', { loose: true }) // true
|
|
1281
1530
|
*/
|
|
1282
|
-
|
|
1283
|
-
|
|
1531
|
+
|
|
1532
|
+
function isTWCard(value) {
|
|
1533
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1534
|
+
_ref$loose = _ref.loose,
|
|
1535
|
+
loose = _ref$loose === void 0 ? false : _ref$loose;
|
|
1536
|
+
|
|
1537
|
+
var valueStr = normalizeString(value);
|
|
1538
|
+
|
|
1284
1539
|
if (regTWCard.test(valueStr)) {
|
|
1285
1540
|
return true;
|
|
1286
1541
|
}
|
|
1542
|
+
|
|
1287
1543
|
return loose ? singleRegTWCard.test(valueStr) : false;
|
|
1288
1544
|
}
|
|
1289
1545
|
|
|
1290
|
-
|
|
1291
|
-
|
|
1546
|
+
var reg$1 = /^[A-Z]{6}[A-Z\d]{2}(?:[A-Z\d]{3})?$/;
|
|
1292
1547
|
/**
|
|
1293
1548
|
* 检测值是否为 Swift Code。8位或11位,前6位为大写字母,7-8位为大写字母或数字,9-11位为可选的大写字母或数字。
|
|
1294
1549
|
*
|
|
@@ -1309,15 +1564,16 @@
|
|
|
1309
1564
|
* isSwiftCode('ICBKCNBJBJM') // true
|
|
1310
1565
|
*
|
|
1311
1566
|
*/
|
|
1567
|
+
|
|
1312
1568
|
function isSwiftCode(value) {
|
|
1313
|
-
|
|
1569
|
+
var valueStr = normalizeString(value);
|
|
1314
1570
|
return reg$1.test(valueStr);
|
|
1315
1571
|
}
|
|
1316
1572
|
|
|
1317
1573
|
// 最大安全数字
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1574
|
+
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // 最小安全数字
|
|
1575
|
+
|
|
1576
|
+
var MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
|
|
1321
1577
|
|
|
1322
1578
|
/**
|
|
1323
1579
|
* 参考: https://github.com/nefe/number-precision/blob/master/src/index.ts
|
|
@@ -1325,17 +1581,16 @@
|
|
|
1325
1581
|
* 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
|
|
1326
1582
|
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
|
|
1327
1583
|
*/
|
|
1328
|
-
|
|
1329
1584
|
/**
|
|
1330
1585
|
* 是否为科学计数法数字
|
|
1331
1586
|
*
|
|
1332
1587
|
* @param {string} num 检查值
|
|
1333
1588
|
* @returns {boolean}
|
|
1334
1589
|
*/
|
|
1590
|
+
|
|
1335
1591
|
function isScientificNumber(num) {
|
|
1336
1592
|
return /\d+\.?\d*e[\+\-]*\d+/i.test(num);
|
|
1337
1593
|
}
|
|
1338
|
-
|
|
1339
1594
|
/**
|
|
1340
1595
|
* 把错误的数据转正
|
|
1341
1596
|
*
|
|
@@ -1346,60 +1601,63 @@
|
|
|
1346
1601
|
*
|
|
1347
1602
|
* strip(0.09999999999999998)=0.1
|
|
1348
1603
|
*/
|
|
1349
|
-
|
|
1604
|
+
|
|
1605
|
+
function strip(num) {
|
|
1606
|
+
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 12;
|
|
1350
1607
|
return +parseFloat(num.toPrecision(precision));
|
|
1351
1608
|
}
|
|
1352
|
-
|
|
1353
1609
|
/**
|
|
1354
1610
|
* 计算数字的小数点长度,支持科学记数法
|
|
1355
1611
|
*
|
|
1356
1612
|
* @param {number|string} num 输入数
|
|
1357
1613
|
* @returns {number} 小数点长度
|
|
1358
1614
|
*/
|
|
1615
|
+
|
|
1359
1616
|
function digitLength(num) {
|
|
1360
1617
|
// Get digit length of e
|
|
1361
|
-
|
|
1362
|
-
|
|
1618
|
+
var eSplit = num.toString().split(/e/i);
|
|
1619
|
+
var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
|
|
1363
1620
|
return len > 0 ? len : 0;
|
|
1364
1621
|
}
|
|
1365
|
-
|
|
1366
1622
|
/**
|
|
1367
1623
|
* 把小数转成整数,支持科学计数法。如果是小数则放大成整数
|
|
1368
1624
|
*
|
|
1369
1625
|
* @param {number|string} num 输入数
|
|
1370
1626
|
* @returns {number}
|
|
1371
1627
|
*/
|
|
1628
|
+
|
|
1372
1629
|
function float2Fixed(num) {
|
|
1373
|
-
|
|
1630
|
+
var strNum = String(num);
|
|
1631
|
+
|
|
1374
1632
|
if (!isScientificNumber(strNum)) {
|
|
1375
1633
|
return Number(strNum.replace('.', ''));
|
|
1376
1634
|
}
|
|
1377
|
-
|
|
1635
|
+
|
|
1636
|
+
var dLen = digitLength(num);
|
|
1378
1637
|
return dLen > 0 ? strip(+num * Math.pow(10, dLen)) : +num;
|
|
1379
1638
|
}
|
|
1380
|
-
|
|
1381
1639
|
/**
|
|
1382
1640
|
* 检测数字是否越界,如果越界给出提示
|
|
1383
1641
|
* @param {number} num 输入数
|
|
1384
1642
|
* @returns
|
|
1385
1643
|
*/
|
|
1644
|
+
|
|
1386
1645
|
function checkBoundary(num) {
|
|
1387
1646
|
if (+num > MAX_SAFE_INTEGER || +num < MIN_SAFE_INTEGER) {
|
|
1388
|
-
devWarn(
|
|
1647
|
+
devWarn("".concat(num, " is beyond boundary when transfer to integer, the results may not be accurate"));
|
|
1389
1648
|
}
|
|
1390
1649
|
}
|
|
1391
|
-
|
|
1392
1650
|
/**
|
|
1393
1651
|
* 去掉左边数字0
|
|
1394
1652
|
*
|
|
1395
1653
|
* @param {string} num 数字字符串
|
|
1396
1654
|
* @returns {string}
|
|
1397
1655
|
*/
|
|
1398
|
-
function trimLeftZero(num) {
|
|
1399
|
-
const reg = /^([+-])?(0+)([0-9\.]+)$/;
|
|
1400
|
-
const result = reg.exec(num);
|
|
1401
1656
|
|
|
1402
|
-
|
|
1657
|
+
function trimLeftZero(num) {
|
|
1658
|
+
var reg = /^([+-])?(0+)([0-9\.]+)$/;
|
|
1659
|
+
var result = reg.exec(num);
|
|
1660
|
+
var sign;
|
|
1403
1661
|
|
|
1404
1662
|
if (result) {
|
|
1405
1663
|
sign = result[1] || '';
|
|
@@ -1408,7 +1666,6 @@
|
|
|
1408
1666
|
|
|
1409
1667
|
return num;
|
|
1410
1668
|
}
|
|
1411
|
-
|
|
1412
1669
|
/**
|
|
1413
1670
|
* 科学计数法转换成普通数字
|
|
1414
1671
|
*
|
|
@@ -1419,39 +1676,40 @@
|
|
|
1419
1676
|
* @param {string | number} num 科学计数法数字
|
|
1420
1677
|
* @returns {string | number} 转换后的数字字符串
|
|
1421
1678
|
*/
|
|
1679
|
+
|
|
1422
1680
|
function scientificToNumber(num) {
|
|
1423
|
-
|
|
1681
|
+
var strNum = String(num);
|
|
1424
1682
|
|
|
1425
1683
|
if (!isScientificNumber(strNum)) {
|
|
1426
1684
|
return num;
|
|
1427
1685
|
}
|
|
1428
|
-
|
|
1429
1686
|
/** @type string */
|
|
1430
|
-
let ret;
|
|
1431
1687
|
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1688
|
+
|
|
1689
|
+
var ret;
|
|
1690
|
+
var zero = '0';
|
|
1691
|
+
var parts = strNum.toLowerCase().split('e');
|
|
1692
|
+
var e = parts.pop(); // 存储指数
|
|
1435
1693
|
// @ts-ignore
|
|
1436
|
-
|
|
1694
|
+
|
|
1695
|
+
var l = Math.abs(e); // 取绝对值,l-1就是0的个数
|
|
1437
1696
|
// @ts-ignore
|
|
1438
|
-
const sign = e / l; //判断正负
|
|
1439
|
-
const coeff_array = parts[0].split('.'); // 将系数按照小数点拆分
|
|
1440
1697
|
|
|
1698
|
+
var sign = e / l; //判断正负
|
|
1699
|
+
|
|
1700
|
+
var coeff_array = parts[0].split('.'); // 将系数按照小数点拆分
|
|
1441
1701
|
// 如果是小数
|
|
1702
|
+
|
|
1442
1703
|
if (sign === -1) {
|
|
1443
1704
|
// 整数部分
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
// 整数部分大于科学计数后面部分
|
|
1705
|
+
var intVal = trimLeftZero(coeff_array[0]); // 整数部分大于科学计数后面部分
|
|
1447
1706
|
// 如: 10e-1, 10.2e-1
|
|
1448
|
-
if (intVal.length > l) {
|
|
1449
|
-
const thanLen = intVal.length - l;
|
|
1450
|
-
const dec = coeff_array[1] || '';
|
|
1451
1707
|
|
|
1452
|
-
|
|
1708
|
+
if (intVal.length > l) {
|
|
1709
|
+
var thanLen = intVal.length - l;
|
|
1710
|
+
var dec = coeff_array[1] || '';
|
|
1711
|
+
ret = intVal.slice(0, thanLen); // 处理 10e-1, 100e-1
|
|
1453
1712
|
|
|
1454
|
-
// 处理 10e-1, 100e-1
|
|
1455
1713
|
if (intVal.slice(thanLen) !== '0' || dec) {
|
|
1456
1714
|
ret += '.' + intVal.slice(thanLen) + dec;
|
|
1457
1715
|
}
|
|
@@ -1462,14 +1720,14 @@
|
|
|
1462
1720
|
}
|
|
1463
1721
|
} else {
|
|
1464
1722
|
// 小数部分
|
|
1465
|
-
|
|
1723
|
+
var _dec = coeff_array[1] || ''; // 如果是整数,将整数除第一位之外的非零数字计入位数,相应的减少0的个数
|
|
1724
|
+
|
|
1466
1725
|
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
ret = trimLeftZero(coeff_array[0] + dec.substring(0, l)) + '.' + dec.substring(l);
|
|
1726
|
+
if (l - _dec.length < 0) {
|
|
1727
|
+
ret = trimLeftZero(coeff_array[0] + _dec.substring(0, l)) + '.' + _dec.substring(l);
|
|
1470
1728
|
} else {
|
|
1471
1729
|
// 拼接字符串,如果是整数,不需要拼接小数点
|
|
1472
|
-
ret = coeff_array.join('') + new Array(l -
|
|
1730
|
+
ret = coeff_array.join('') + new Array(l - _dec.length + 1).join(zero);
|
|
1473
1731
|
}
|
|
1474
1732
|
}
|
|
1475
1733
|
|
|
@@ -1492,12 +1750,12 @@
|
|
|
1492
1750
|
* isNaN(1)
|
|
1493
1751
|
* // => false
|
|
1494
1752
|
*/
|
|
1753
|
+
|
|
1495
1754
|
function _isNaN(value) {
|
|
1496
1755
|
return isType(value, 'Number') && isNaN(value);
|
|
1497
1756
|
}
|
|
1498
1757
|
|
|
1499
|
-
|
|
1500
|
-
|
|
1758
|
+
var reg = /^[+-]?\d*\.?\d*$/;
|
|
1501
1759
|
/**
|
|
1502
1760
|
* 检查数字或数字字符串
|
|
1503
1761
|
*
|
|
@@ -1505,22 +1763,21 @@
|
|
|
1505
1763
|
* @param {string} num
|
|
1506
1764
|
* @returns 是否为数字
|
|
1507
1765
|
*/
|
|
1508
|
-
function checkNumber(num) {
|
|
1509
|
-
if (!(reg.test(num) || isScientificNumber(num)) || _isNaN(num) || (typeof num !== 'number' && typeof num !== 'string') || num === '') {
|
|
1510
|
-
devWarn(`${num} invalid parameter.`);
|
|
1511
1766
|
|
|
1767
|
+
function checkNumber(num) {
|
|
1768
|
+
if (!(reg.test(num) || isScientificNumber(num)) || _isNaN(num) || typeof num !== 'number' && typeof num !== 'string' || num === '') {
|
|
1769
|
+
devWarn("".concat(num, " invalid parameter."));
|
|
1512
1770
|
return false;
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
// 数字超限如果不是是字符串,可能有异常
|
|
1771
|
+
} // 数字超限如果不是是字符串,可能有异常
|
|
1516
1772
|
// 如 1111111111111111111111 // => 1.1111111111111111e+21
|
|
1773
|
+
|
|
1774
|
+
|
|
1517
1775
|
if (typeof num === 'number') {
|
|
1518
1776
|
checkBoundary(num);
|
|
1519
1777
|
}
|
|
1520
1778
|
|
|
1521
1779
|
return true;
|
|
1522
1780
|
}
|
|
1523
|
-
|
|
1524
1781
|
/**
|
|
1525
1782
|
* 格式化整数部分
|
|
1526
1783
|
*
|
|
@@ -1529,20 +1786,22 @@
|
|
|
1529
1786
|
* @param {string} thousand 千分位符号
|
|
1530
1787
|
* @returns 格式化后的值
|
|
1531
1788
|
*/
|
|
1789
|
+
|
|
1790
|
+
|
|
1532
1791
|
function formatInt(intStr, thousand) {
|
|
1533
|
-
|
|
1792
|
+
var txt = '';
|
|
1534
1793
|
intStr = trimLeftZero(intStr);
|
|
1535
1794
|
intStr = intStr[0] === '+' ? intStr.substring(1) : intStr; // 去掉+符号
|
|
1536
|
-
const negativeSymbol = Number(intStr) < 0 ? '-' : '';
|
|
1537
|
-
const reArr = negativeSymbol ? intStr.substring(1).split('').reverse() : intStr.split('').reverse();
|
|
1538
1795
|
|
|
1539
|
-
|
|
1796
|
+
var negativeSymbol = Number(intStr) < 0 ? '-' : '';
|
|
1797
|
+
var reArr = negativeSymbol ? intStr.substring(1).split('').reverse() : intStr.split('').reverse();
|
|
1798
|
+
|
|
1799
|
+
for (var i = 0; i < reArr.length; i++) {
|
|
1540
1800
|
txt += reArr[i] + ((i + 1) % 3 === 0 && i + 1 !== reArr.length ? thousand : '');
|
|
1541
1801
|
}
|
|
1542
1802
|
|
|
1543
1803
|
return negativeSymbol + txt.split('').reverse().join('');
|
|
1544
1804
|
}
|
|
1545
|
-
|
|
1546
1805
|
/**
|
|
1547
1806
|
* 格式化小数部分,如果使用 toFixed,超大额数字会自动被截断
|
|
1548
1807
|
*
|
|
@@ -1552,16 +1811,18 @@
|
|
|
1552
1811
|
* @param {string} decimal 小数点符号
|
|
1553
1812
|
* @returns 格式化后的值
|
|
1554
1813
|
*/
|
|
1814
|
+
|
|
1815
|
+
|
|
1555
1816
|
function formatDec(decStr, precision, decimal) {
|
|
1556
1817
|
if (precision === 0) {
|
|
1557
1818
|
return '';
|
|
1558
1819
|
}
|
|
1559
1820
|
|
|
1560
|
-
|
|
1561
|
-
|
|
1821
|
+
var zero = 0;
|
|
1822
|
+
var ret = '';
|
|
1562
1823
|
|
|
1563
1824
|
if (decStr && Number(decStr) > 0) {
|
|
1564
|
-
|
|
1825
|
+
var tmpNum = parseFloat('0.' + decStr);
|
|
1565
1826
|
ret = tmpNum.toFixed(precision).substring(2);
|
|
1566
1827
|
} else {
|
|
1567
1828
|
ret = zero.toFixed(precision).substring(2);
|
|
@@ -1569,7 +1830,6 @@
|
|
|
1569
1830
|
|
|
1570
1831
|
return decimal + ret;
|
|
1571
1832
|
}
|
|
1572
|
-
|
|
1573
1833
|
/**
|
|
1574
1834
|
* 格式化金额
|
|
1575
1835
|
*
|
|
@@ -1613,27 +1873,41 @@
|
|
|
1613
1873
|
* formatMoney(1000.00, { decimal: '&' });
|
|
1614
1874
|
* // => 1,000&00
|
|
1615
1875
|
*/
|
|
1616
|
-
|
|
1876
|
+
|
|
1877
|
+
|
|
1878
|
+
var formatMoney = function formatMoney(num) {
|
|
1879
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1880
|
+
_ref$precision = _ref.precision,
|
|
1881
|
+
precision = _ref$precision === void 0 ? 2 : _ref$precision,
|
|
1882
|
+
symbol = _ref.symbol,
|
|
1883
|
+
_ref$thousand = _ref.thousand,
|
|
1884
|
+
thousand = _ref$thousand === void 0 ? ',' : _ref$thousand,
|
|
1885
|
+
_ref$decimal = _ref.decimal,
|
|
1886
|
+
decimal = _ref$decimal === void 0 ? '.' : _ref$decimal;
|
|
1887
|
+
|
|
1617
1888
|
// 数字参数不正确,返回空字符串
|
|
1618
1889
|
// @ts-ignore
|
|
1619
1890
|
if (!checkNumber(num)) {
|
|
1620
1891
|
return '';
|
|
1621
|
-
}
|
|
1892
|
+
} // 参数规整化
|
|
1893
|
+
|
|
1622
1894
|
|
|
1623
|
-
// 参数规整化
|
|
1624
1895
|
if (typeof precision !== 'number' || _isNaN(precision) || precision < 0) {
|
|
1625
1896
|
precision = 2;
|
|
1626
1897
|
} else if (precision > 10) {
|
|
1627
1898
|
precision = 10;
|
|
1628
1899
|
}
|
|
1900
|
+
|
|
1629
1901
|
symbol = typeof symbol === 'string' ? symbol : '';
|
|
1630
1902
|
thousand = typeof thousand === 'string' ? thousand : ',';
|
|
1631
|
-
decimal = typeof decimal === 'string' ? decimal : '.';
|
|
1903
|
+
decimal = typeof decimal === 'string' ? decimal : '.'; // 转换数字字符串,支持科学记数法
|
|
1904
|
+
|
|
1905
|
+
var strNum = scientificToNumber(num) + ''; // 整数和小数部分
|
|
1632
1906
|
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1907
|
+
var _strNum$split = strNum.split('.'),
|
|
1908
|
+
_strNum$split2 = _slicedToArray(_strNum$split, 2),
|
|
1909
|
+
intStr = _strNum$split2[0],
|
|
1910
|
+
decStr = _strNum$split2[1];
|
|
1637
1911
|
|
|
1638
1912
|
return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
|
|
1639
1913
|
};
|
|
@@ -1668,13 +1942,20 @@
|
|
|
1668
1942
|
* // => 6228-4804-0256-4890
|
|
1669
1943
|
*
|
|
1670
1944
|
*/
|
|
1671
|
-
function formatBankCard(bankCardNo = '', { char = ' ', length = 4 } = {}) {
|
|
1672
|
-
const reg = new RegExp(`(.{${length}})`, 'g');
|
|
1673
|
-
const regChar = new RegExp(`${char}`, 'g');
|
|
1674
1945
|
|
|
1675
|
-
|
|
1676
|
-
|
|
1946
|
+
function formatBankCard() {
|
|
1947
|
+
var bankCardNo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
1948
|
+
|
|
1949
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1950
|
+
_ref$char = _ref["char"],
|
|
1951
|
+
_char = _ref$char === void 0 ? ' ' : _ref$char,
|
|
1952
|
+
_ref$length = _ref.length,
|
|
1953
|
+
length = _ref$length === void 0 ? 4 : _ref$length;
|
|
1677
1954
|
|
|
1955
|
+
var reg = new RegExp("(.{".concat(length, "})"), 'g');
|
|
1956
|
+
var regChar = new RegExp("".concat(_char), 'g');
|
|
1957
|
+
var realValue = normalizeString(bankCardNo).replace(regChar, '');
|
|
1958
|
+
var str = realValue.replace(reg, "$1".concat(_char));
|
|
1678
1959
|
return realValue.length % length === 0 ? str.substring(0, str.length - 1) : str;
|
|
1679
1960
|
}
|
|
1680
1961
|
|
|
@@ -1724,64 +2005,69 @@
|
|
|
1724
2005
|
* // => 林**
|
|
1725
2006
|
*
|
|
1726
2007
|
*/
|
|
1727
|
-
function replaceChar(str, { start = 3, end = -4, char = '*', repeat, exclude } = {}) {
|
|
1728
|
-
const realStr = normalizeString(str);
|
|
1729
|
-
const strLen = realStr.length;
|
|
1730
2008
|
|
|
1731
|
-
|
|
2009
|
+
function replaceChar(str) {
|
|
2010
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
2011
|
+
_ref$start = _ref.start,
|
|
2012
|
+
start = _ref$start === void 0 ? 3 : _ref$start,
|
|
2013
|
+
_ref$end = _ref.end,
|
|
2014
|
+
end = _ref$end === void 0 ? -4 : _ref$end,
|
|
2015
|
+
_ref$char = _ref["char"],
|
|
2016
|
+
_char = _ref$char === void 0 ? '*' : _ref$char,
|
|
2017
|
+
repeat = _ref.repeat,
|
|
2018
|
+
exclude = _ref.exclude;
|
|
2019
|
+
|
|
2020
|
+
var realStr = normalizeString(str);
|
|
2021
|
+
var strLen = realStr.length; // 开始位置超过str长度
|
|
2022
|
+
|
|
1732
2023
|
if (Math.abs(start) >= strLen) {
|
|
1733
2024
|
return realStr;
|
|
1734
2025
|
}
|
|
1735
2026
|
|
|
1736
2027
|
start = start >= 0 ? start : strLen + start;
|
|
1737
|
-
end = end >= 0 ? end : strLen + end;
|
|
2028
|
+
end = end >= 0 ? end : strLen + end; // 开始位置大于结束位置
|
|
1738
2029
|
|
|
1739
|
-
// 开始位置大于结束位置
|
|
1740
2030
|
if (start >= end) {
|
|
1741
2031
|
return realStr;
|
|
1742
2032
|
}
|
|
1743
2033
|
|
|
1744
|
-
|
|
2034
|
+
var middleStr = realStr.substring(start, end);
|
|
1745
2035
|
|
|
1746
2036
|
if (exclude) {
|
|
1747
|
-
|
|
1748
|
-
middleStr = middleStr.replace(reg,
|
|
2037
|
+
var reg = new RegExp("[^".concat(exclude, "]"), 'g');
|
|
2038
|
+
middleStr = middleStr.replace(reg, _char);
|
|
1749
2039
|
} else {
|
|
1750
2040
|
repeat = typeof repeat === 'number' && repeat >= 0 ? repeat : middleStr.length;
|
|
1751
|
-
middleStr =
|
|
2041
|
+
middleStr = _char.repeat(repeat);
|
|
1752
2042
|
}
|
|
1753
2043
|
|
|
1754
2044
|
return realStr.substring(0, start) + middleStr + realStr.substring(end);
|
|
1755
2045
|
}
|
|
1756
2046
|
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
const chnUnitChar = ['', '十', '百', '千'];
|
|
1760
|
-
|
|
1761
|
-
// 繁体
|
|
1762
|
-
const big5NumberChar = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
1763
|
-
const big5UnitChar = ['', '拾', '佰', '仟'];
|
|
2047
|
+
var chnNumberChar = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
|
|
2048
|
+
var chnUnitChar = ['', '十', '百', '千']; // 繁体
|
|
1764
2049
|
|
|
1765
|
-
|
|
2050
|
+
var big5NumberChar = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
2051
|
+
var big5UnitChar = ['', '拾', '佰', '仟']; // 数字字符、计数单位
|
|
1766
2052
|
|
|
1767
2053
|
/**
|
|
1768
2054
|
* @type {string[]}
|
|
1769
2055
|
* @private
|
|
1770
2056
|
*/
|
|
1771
|
-
let numberChar;
|
|
1772
2057
|
|
|
2058
|
+
var numberChar;
|
|
1773
2059
|
/**
|
|
1774
2060
|
* @type {string[]}
|
|
1775
2061
|
* @private
|
|
1776
2062
|
*/
|
|
1777
|
-
let unitChar;
|
|
1778
2063
|
|
|
2064
|
+
var unitChar;
|
|
1779
2065
|
/**
|
|
1780
2066
|
* @type {string[]}
|
|
1781
2067
|
* @private
|
|
1782
2068
|
*/
|
|
1783
|
-
let unitSection;
|
|
1784
2069
|
|
|
2070
|
+
var unitSection;
|
|
1785
2071
|
/**
|
|
1786
2072
|
* 每个小节的内部进行转化
|
|
1787
2073
|
*
|
|
@@ -1789,17 +2075,18 @@
|
|
|
1789
2075
|
* @param {number} section 数字
|
|
1790
2076
|
* @returns {string} 转化的数字
|
|
1791
2077
|
*/
|
|
2078
|
+
|
|
1792
2079
|
function sectionToChinese(section) {
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
2080
|
+
var str = '';
|
|
2081
|
+
var chnstr = '';
|
|
2082
|
+
var zero = false; //zero为是否进行补零, 第一次进行取余由于为个位数,默认不补零
|
|
2083
|
+
|
|
2084
|
+
var unitPos = 0;
|
|
1797
2085
|
|
|
1798
2086
|
while (section > 0) {
|
|
1799
2087
|
// 对数字取余10,得到的数即为个位数
|
|
1800
|
-
|
|
2088
|
+
var v = section % 10; //如果数字为零,则对字符串进行补零
|
|
1801
2089
|
|
|
1802
|
-
//如果数字为零,则对字符串进行补零
|
|
1803
2090
|
if (v == 0) {
|
|
1804
2091
|
if (zero) {
|
|
1805
2092
|
//如果遇到连续多次取余都是0,那么只需补一个零即可
|
|
@@ -1813,12 +2100,13 @@
|
|
|
1813
2100
|
str += unitChar[unitPos];
|
|
1814
2101
|
chnstr = str + chnstr;
|
|
1815
2102
|
}
|
|
2103
|
+
|
|
1816
2104
|
unitPos++;
|
|
1817
2105
|
section = Math.floor(section / 10);
|
|
1818
2106
|
}
|
|
2107
|
+
|
|
1819
2108
|
return chnstr;
|
|
1820
2109
|
}
|
|
1821
|
-
|
|
1822
2110
|
/**
|
|
1823
2111
|
* 转换整数
|
|
1824
2112
|
*
|
|
@@ -1826,22 +2114,26 @@
|
|
|
1826
2114
|
* @param {number} num 要转换的数字
|
|
1827
2115
|
* @returns {string} 中文数字
|
|
1828
2116
|
*/
|
|
1829
|
-
function convertInteger(num) {
|
|
1830
|
-
let numInt = Math.floor(num);
|
|
1831
2117
|
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
2118
|
+
|
|
2119
|
+
function convertInteger(num) {
|
|
2120
|
+
var numInt = Math.floor(num);
|
|
2121
|
+
var unitPos = 0;
|
|
2122
|
+
var strIns = '';
|
|
2123
|
+
var chnStr = '';
|
|
2124
|
+
var needZero = false;
|
|
1836
2125
|
|
|
1837
2126
|
if (numInt === 0) {
|
|
1838
2127
|
return numberChar[0];
|
|
1839
2128
|
}
|
|
2129
|
+
|
|
1840
2130
|
while (numInt > 0) {
|
|
1841
2131
|
var section = numInt % 10000;
|
|
2132
|
+
|
|
1842
2133
|
if (needZero) {
|
|
1843
2134
|
chnStr = numberChar[0] + chnStr;
|
|
1844
2135
|
}
|
|
2136
|
+
|
|
1845
2137
|
strIns = sectionToChinese(section);
|
|
1846
2138
|
strIns += section !== 0 ? unitSection[unitPos] : unitSection[0];
|
|
1847
2139
|
chnStr = strIns + chnStr;
|
|
@@ -1849,29 +2141,29 @@
|
|
|
1849
2141
|
numInt = Math.floor(numInt / 10000);
|
|
1850
2142
|
unitPos++;
|
|
1851
2143
|
}
|
|
2144
|
+
|
|
1852
2145
|
return chnStr;
|
|
1853
2146
|
}
|
|
1854
|
-
|
|
1855
2147
|
/**
|
|
1856
2148
|
* 转换小数
|
|
1857
2149
|
*
|
|
1858
2150
|
* @private
|
|
1859
2151
|
* @param {number} num 要转换的数字
|
|
1860
2152
|
*/
|
|
1861
|
-
function convertDecimal(num) {
|
|
1862
|
-
const strNum = num + '';
|
|
1863
|
-
const index = strNum.indexOf('.');
|
|
1864
2153
|
|
|
1865
|
-
|
|
2154
|
+
|
|
2155
|
+
function convertDecimal(num) {
|
|
2156
|
+
var strNum = num + '';
|
|
2157
|
+
var index = strNum.indexOf('.');
|
|
2158
|
+
var ret = '';
|
|
1866
2159
|
|
|
1867
2160
|
if (index > -1) {
|
|
1868
|
-
|
|
2161
|
+
var decimalStr = strNum.slice(index + 1);
|
|
1869
2162
|
ret = mapNumberChar(parseInt(decimalStr));
|
|
1870
2163
|
}
|
|
1871
2164
|
|
|
1872
2165
|
return ret;
|
|
1873
2166
|
}
|
|
1874
|
-
|
|
1875
2167
|
/**
|
|
1876
2168
|
* 映射为中文数字
|
|
1877
2169
|
*
|
|
@@ -1879,17 +2171,18 @@
|
|
|
1879
2171
|
* @param {number} num 要处理的数字
|
|
1880
2172
|
* @returns {string} 返回中文数字的映射
|
|
1881
2173
|
*/
|
|
2174
|
+
|
|
2175
|
+
|
|
1882
2176
|
function mapNumberChar(num) {
|
|
1883
|
-
|
|
1884
|
-
|
|
2177
|
+
var strNum = num + '';
|
|
2178
|
+
var ret = '';
|
|
1885
2179
|
|
|
1886
|
-
for (
|
|
2180
|
+
for (var i = 0, len = strNum.length; i < len; i++) {
|
|
1887
2181
|
ret += numberChar[parseInt(strNum[i])];
|
|
1888
2182
|
}
|
|
1889
2183
|
|
|
1890
2184
|
return ret;
|
|
1891
2185
|
}
|
|
1892
|
-
|
|
1893
2186
|
/**
|
|
1894
2187
|
* 数字转中文数字
|
|
1895
2188
|
* 不在安全数字 -9007199254740991~9007199254740991 内,处理会有异常
|
|
@@ -1935,55 +2228,65 @@
|
|
|
1935
2228
|
* // => 一九九〇
|
|
1936
2229
|
*
|
|
1937
2230
|
*/
|
|
1938
|
-
|
|
2231
|
+
|
|
2232
|
+
|
|
2233
|
+
function numberToChinese(num) {
|
|
2234
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
2235
|
+
_ref$big = _ref.big5,
|
|
2236
|
+
big5 = _ref$big === void 0 ? false : _ref$big,
|
|
2237
|
+
_ref$unit = _ref.unit,
|
|
2238
|
+
unit = _ref$unit === void 0 ? true : _ref$unit,
|
|
2239
|
+
_ref$decimal = _ref.decimal,
|
|
2240
|
+
decimal = _ref$decimal === void 0 ? '点' : _ref$decimal,
|
|
2241
|
+
_ref$zero = _ref.zero,
|
|
2242
|
+
zero = _ref$zero === void 0 ? '' : _ref$zero,
|
|
2243
|
+
_ref$negative = _ref.negative,
|
|
2244
|
+
negative = _ref$negative === void 0 ? '负' : _ref$negative,
|
|
2245
|
+
_ref$unitConfig = _ref.unitConfig,
|
|
2246
|
+
unitConfig = _ref$unitConfig === void 0 ? {} : _ref$unitConfig;
|
|
2247
|
+
|
|
1939
2248
|
// 非数字 或 NaN 不处理
|
|
1940
2249
|
if (typeof num !== 'number' || isNaN(num)) {
|
|
1941
|
-
devWarn(
|
|
1942
|
-
|
|
2250
|
+
devWarn("\u53C2\u6570\u9519\u8BEF ".concat(num, "\uFF0C\u8BF7\u4F20\u5165\u6570\u5B57"));
|
|
1943
2251
|
return '';
|
|
1944
|
-
}
|
|
2252
|
+
} // 超过安全数字提示
|
|
2253
|
+
|
|
1945
2254
|
|
|
1946
|
-
//
|
|
1947
|
-
checkBoundary(num);
|
|
2255
|
+
checkBoundary(num); // 设置数字字符和计数单位
|
|
1948
2256
|
|
|
1949
|
-
// 设置数字字符和计数单位
|
|
1950
2257
|
if (big5) {
|
|
1951
2258
|
numberChar = big5NumberChar.slice();
|
|
1952
2259
|
unitChar = big5UnitChar.slice();
|
|
1953
2260
|
} else {
|
|
1954
2261
|
numberChar = chnNumberChar.slice();
|
|
1955
2262
|
unitChar = chnUnitChar.slice();
|
|
1956
|
-
}
|
|
2263
|
+
} // 设置节点计数单位,万、亿、万亿
|
|
2264
|
+
|
|
1957
2265
|
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
unitSection = ['', unitWan, unitYi, unitWanYi];
|
|
2266
|
+
var unitWan = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.w) || '万';
|
|
2267
|
+
var unitYi = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.y) || '亿';
|
|
2268
|
+
var unitWanYi = unitWan + unitYi;
|
|
2269
|
+
unitSection = ['', unitWan, unitYi, unitWanYi]; // 设置0
|
|
1963
2270
|
|
|
1964
|
-
// 设置0
|
|
1965
2271
|
if (zero) {
|
|
1966
2272
|
numberChar[0] = zero;
|
|
1967
|
-
}
|
|
2273
|
+
} // 前置字符,负数处理
|
|
1968
2274
|
|
|
1969
|
-
// 前置字符,负数处理
|
|
1970
|
-
const preStr = num < 0 ? negative : '';
|
|
1971
2275
|
|
|
1972
|
-
// 整数和小数
|
|
1973
|
-
|
|
1974
|
-
|
|
2276
|
+
var preStr = num < 0 ? negative : ''; // 整数和小数
|
|
2277
|
+
|
|
2278
|
+
var chnInteger, chnDecimal;
|
|
2279
|
+
var numAbs = Math.abs(num); // 处理整数
|
|
1975
2280
|
|
|
1976
|
-
// 处理整数
|
|
1977
2281
|
if (unit) {
|
|
1978
2282
|
chnInteger = convertInteger(numAbs);
|
|
1979
2283
|
} else {
|
|
1980
2284
|
chnInteger = mapNumberChar(Math.floor(numAbs));
|
|
1981
|
-
}
|
|
2285
|
+
} // 处理小数
|
|
1982
2286
|
|
|
1983
|
-
// 处理小数
|
|
1984
|
-
chnDecimal = convertDecimal(numAbs);
|
|
1985
2287
|
|
|
1986
|
-
|
|
2288
|
+
chnDecimal = convertDecimal(numAbs);
|
|
2289
|
+
return chnDecimal ? "".concat(preStr).concat(chnInteger).concat(decimal).concat(chnDecimal) : "".concat(preStr).concat(chnInteger);
|
|
1987
2290
|
}
|
|
1988
2291
|
|
|
1989
2292
|
/**
|
|
@@ -2009,76 +2312,36 @@
|
|
|
2009
2312
|
* // => 1 GB
|
|
2010
2313
|
*/
|
|
2011
2314
|
function bytesToSize(bytes) {
|
|
2012
|
-
|
|
2315
|
+
var numBytes = typeof bytes !== 'number' ? Number(bytes) : bytes;
|
|
2013
2316
|
if (numBytes === 0 || isNaN(numBytes)) return '0 B';
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
['34', '安徽省'],
|
|
2043
|
-
['35', '福建省'],
|
|
2044
|
-
['36', '江西省'],
|
|
2045
|
-
['37', '山东省'],
|
|
2046
|
-
|
|
2047
|
-
// 华中地区: 河南省|410000,湖北省|420000,湖南省|430000
|
|
2048
|
-
['41', '河南省'],
|
|
2049
|
-
['42', '湖北省'],
|
|
2050
|
-
['43', '湖南省'],
|
|
2051
|
-
|
|
2052
|
-
// 华南地区:广东省|440000,广西壮族自治区|450000,海南省|460000
|
|
2053
|
-
['44', '广东省'],
|
|
2054
|
-
['45', '广西壮族自治区'],
|
|
2055
|
-
['46', '海南省'],
|
|
2056
|
-
|
|
2057
|
-
// 西南地区:重庆市|500000,四川省|510000,贵州省|520000,云南省|530000,西藏自治区|540000
|
|
2058
|
-
['50', '重庆市'],
|
|
2059
|
-
['51', '四川省'],
|
|
2060
|
-
['52', '贵州省'],
|
|
2061
|
-
['53', '云南省'],
|
|
2062
|
-
['54', '西藏自治区'],
|
|
2063
|
-
|
|
2064
|
-
// 西北地区: 陕西省|610000,甘肃省|620000,青海省|630000,宁夏回族自治区|640000,新疆维吾尔自治区|650000
|
|
2065
|
-
['61', '陕西省'],
|
|
2066
|
-
['62', '甘肃省'],
|
|
2067
|
-
['63', '青海省'],
|
|
2068
|
-
['64', '宁夏回族自治区'],
|
|
2069
|
-
['65', '新疆维吾尔自治区'],
|
|
2070
|
-
|
|
2071
|
-
// 台湾地区:台湾省|710000
|
|
2072
|
-
// 台湾居民公民身份号码地址码为830000,参考 http://www.wanweibaike.com/wiki-中华人民共和国行政区划代码_(7区)、https://zh.wikipedia.org/wiki/港澳台居民居住证
|
|
2073
|
-
['71', '台湾省'],
|
|
2074
|
-
['83', '台湾省'],
|
|
2075
|
-
|
|
2076
|
-
// 港澳地区:香港特别行政区|810000,澳门特别行政区|820000
|
|
2077
|
-
['81', '香港特别行政区'],
|
|
2078
|
-
['82', '澳门特别行政区']
|
|
2079
|
-
];
|
|
2080
|
-
|
|
2081
|
-
// 第一位数字是以前的大区制代码。第二位是大区所在省市编码。全国共分为8个大区:华北(1)、东北(2)、华东(3)、中南(4)、西南(5)、西北(6)、台湾(7)和港澳(8)。
|
|
2317
|
+
var k = 1024; // 存储单位
|
|
2318
|
+
|
|
2319
|
+
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
2320
|
+
var i = Math.floor(Math.log(numBytes) / Math.log(k));
|
|
2321
|
+
return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(2)), " ").concat(sizes[i]) : numBytes + '';
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
var regIdCard = /*#__PURE__*/_wrapRegExp(/^([0-9]{2})([0-9]{2})([0-9]{2})((?:[0-9]{2})?[0-9]{2})([0-9]{2})([0-9]{2})[0-9]{2}([0-9])(?:[0-9]|X)?$/i, {
|
|
2325
|
+
province: 1,
|
|
2326
|
+
city: 2,
|
|
2327
|
+
area: 3,
|
|
2328
|
+
year: 4,
|
|
2329
|
+
month: 5,
|
|
2330
|
+
day: 6,
|
|
2331
|
+
gender: 7
|
|
2332
|
+
});
|
|
2333
|
+
|
|
2334
|
+
var Provinces = [// 华北地区:北京市|110000,天津市|120000,河北省|130000,山西省|140000,内蒙古自治区|150000
|
|
2335
|
+
['11', '北京市'], ['12', '天津市'], ['13', '河北省'], ['14', '山西省'], ['15', '内蒙古自治区'], // 东北地区: 辽宁省|210000,吉林省|220000,黑龙江省|230000
|
|
2336
|
+
['21', '辽宁省'], ['22', '吉林省'], ['23', '黑龙江省'], // 华东地区: 上海市|310000,江苏省|320000,浙江省|330000,安徽省|340000,福建省|350000,江西省|360000,山东省|370000
|
|
2337
|
+
['31', '上海市'], ['32', '江苏省'], ['33', '浙江省'], ['34', '安徽省'], ['35', '福建省'], ['36', '江西省'], ['37', '山东省'], // 华中地区: 河南省|410000,湖北省|420000,湖南省|430000
|
|
2338
|
+
['41', '河南省'], ['42', '湖北省'], ['43', '湖南省'], // 华南地区:广东省|440000,广西壮族自治区|450000,海南省|460000
|
|
2339
|
+
['44', '广东省'], ['45', '广西壮族自治区'], ['46', '海南省'], // 西南地区:重庆市|500000,四川省|510000,贵州省|520000,云南省|530000,西藏自治区|540000
|
|
2340
|
+
['50', '重庆市'], ['51', '四川省'], ['52', '贵州省'], ['53', '云南省'], ['54', '西藏自治区'], // 西北地区: 陕西省|610000,甘肃省|620000,青海省|630000,宁夏回族自治区|640000,新疆维吾尔自治区|650000
|
|
2341
|
+
['61', '陕西省'], ['62', '甘肃省'], ['63', '青海省'], ['64', '宁夏回族自治区'], ['65', '新疆维吾尔自治区'], // 台湾地区:台湾省|710000
|
|
2342
|
+
// 台湾居民公民身份号码地址码为830000,参考 http://www.wanweibaike.com/wiki-中华人民共和国行政区划代码_(7区)、https://zh.wikipedia.org/wiki/港澳台居民居住证
|
|
2343
|
+
['71', '台湾省'], ['83', '台湾省'], // 港澳地区:香港特别行政区|810000,澳门特别行政区|820000
|
|
2344
|
+
['81', '香港特别行政区'], ['82', '澳门特别行政区']]; // 第一位数字是以前的大区制代码。第二位是大区所在省市编码。全国共分为8个大区:华北(1)、东北(2)、华东(3)、中南(4)、西南(5)、西北(6)、台湾(7)和港澳(8)。
|
|
2082
2345
|
// const Regions = [
|
|
2083
2346
|
// ['1', '华北地区'],
|
|
2084
2347
|
// ['2', '东北地区'],
|
|
@@ -2143,23 +2406,27 @@
|
|
|
2143
2406
|
* }
|
|
2144
2407
|
*
|
|
2145
2408
|
*/
|
|
2409
|
+
|
|
2146
2410
|
function parseIdCard(id) {
|
|
2147
|
-
if (!isIdCard(id, {
|
|
2411
|
+
if (!isIdCard(id, {
|
|
2412
|
+
loose: true
|
|
2413
|
+
})) {
|
|
2148
2414
|
return null;
|
|
2149
2415
|
}
|
|
2150
2416
|
|
|
2151
|
-
|
|
2417
|
+
var info = regIdCard.exec(id);
|
|
2152
2418
|
|
|
2153
2419
|
if (!info) {
|
|
2154
2420
|
return null;
|
|
2155
2421
|
}
|
|
2156
|
-
|
|
2157
2422
|
/**
|
|
2158
2423
|
* @type {{ province: string, city: string, area: string, year: string, month: string, day: string, gender: string }}
|
|
2159
2424
|
*
|
|
2160
2425
|
*/
|
|
2161
2426
|
// @ts-ignore
|
|
2162
|
-
|
|
2427
|
+
|
|
2428
|
+
|
|
2429
|
+
var origin = (info === null || info === void 0 ? void 0 : info.groups) || {
|
|
2163
2430
|
province: info[1],
|
|
2164
2431
|
city: info[2],
|
|
2165
2432
|
area: info[3],
|
|
@@ -2168,23 +2435,23 @@
|
|
|
2168
2435
|
day: info[6],
|
|
2169
2436
|
gender: info[7]
|
|
2170
2437
|
};
|
|
2171
|
-
|
|
2172
|
-
|
|
2438
|
+
var province = Provinces.find(function (item) {
|
|
2439
|
+
return item[0] === origin.province;
|
|
2440
|
+
});
|
|
2173
2441
|
|
|
2174
2442
|
if (!province) {
|
|
2175
2443
|
return null;
|
|
2176
2444
|
}
|
|
2177
2445
|
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
// const region = Regions.find(item => item[0] === origin.province?.substring(0, 1));
|
|
2446
|
+
var birthday = "".concat(origin.year, "-").concat(origin.month, "-").concat(origin.day);
|
|
2447
|
+
var gender = Number(origin.gender) % 2 === 0 ? '女' : '男'; // const region = Regions.find(item => item[0] === origin.province?.substring(0, 1));
|
|
2181
2448
|
|
|
2182
2449
|
return {
|
|
2183
2450
|
// region,
|
|
2184
2451
|
province: province[1],
|
|
2185
|
-
birthday,
|
|
2186
|
-
gender,
|
|
2187
|
-
origin
|
|
2452
|
+
birthday: birthday,
|
|
2453
|
+
gender: gender,
|
|
2454
|
+
origin: origin
|
|
2188
2455
|
};
|
|
2189
2456
|
}
|
|
2190
2457
|
|
|
@@ -2216,12 +2483,17 @@
|
|
|
2216
2483
|
* });
|
|
2217
2484
|
*/
|
|
2218
2485
|
function blobToDataURL(blob) {
|
|
2219
|
-
return new Promise((resolve, reject)
|
|
2220
|
-
|
|
2221
|
-
reader.readAsDataURL(blob);
|
|
2222
|
-
|
|
2223
|
-
reader.onload = ()
|
|
2224
|
-
|
|
2486
|
+
return new Promise(function (resolve, reject) {
|
|
2487
|
+
var reader = new FileReader();
|
|
2488
|
+
reader.readAsDataURL(blob); // @ts-ignore
|
|
2489
|
+
|
|
2490
|
+
reader.onload = function () {
|
|
2491
|
+
return resolve(reader.result);
|
|
2492
|
+
};
|
|
2493
|
+
|
|
2494
|
+
reader.onerror = function (error) {
|
|
2495
|
+
return reject(error);
|
|
2496
|
+
};
|
|
2225
2497
|
});
|
|
2226
2498
|
}
|
|
2227
2499
|
|
|
@@ -2239,17 +2511,20 @@
|
|
|
2239
2511
|
* dataURLToBlob(dataurl);
|
|
2240
2512
|
*/
|
|
2241
2513
|
function dataURLToBlob(dataurl) {
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2514
|
+
var arr = dataurl.split(','); // @ts-ignore
|
|
2515
|
+
|
|
2516
|
+
var mime = arr[0].match(/:(.*?);/)[1];
|
|
2517
|
+
var bstr = atob(arr[1]);
|
|
2518
|
+
var n = bstr.length;
|
|
2519
|
+
var u8arr = new Uint8Array(n);
|
|
2248
2520
|
|
|
2249
2521
|
while (n--) {
|
|
2250
2522
|
u8arr[n] = bstr.charCodeAt(n);
|
|
2251
2523
|
}
|
|
2252
|
-
|
|
2524
|
+
|
|
2525
|
+
return new Blob([u8arr], {
|
|
2526
|
+
type: mime
|
|
2527
|
+
});
|
|
2253
2528
|
}
|
|
2254
2529
|
|
|
2255
2530
|
/**
|
|
@@ -2274,12 +2549,12 @@
|
|
|
2274
2549
|
* setDataURLPrefix(data, ''); // data:;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
|
|
2275
2550
|
* setDataURLPrefix(data, '', false); // data:,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
|
|
2276
2551
|
*/
|
|
2277
|
-
function setDataURLPrefix(data
|
|
2278
|
-
|
|
2552
|
+
function setDataURLPrefix(data) {
|
|
2553
|
+
var mimetype = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'image/png';
|
|
2554
|
+
var base64 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
2555
|
+
return "data:".concat(mimetype).concat(base64 ? ';base64' : '', ",").concat(data);
|
|
2279
2556
|
}
|
|
2280
2557
|
|
|
2281
|
-
// TODO: 函数重载,类型参照 Date
|
|
2282
|
-
|
|
2283
2558
|
/**
|
|
2284
2559
|
* 创建一个 Date 实例日期对象,同 new Date() 。<br/>
|
|
2285
2560
|
* 规避了苹果设备浏览器不支持部分格式(YYYY-MM-DD HH-mm 或 YYYY.MM.DD)。
|
|
@@ -2300,15 +2575,20 @@
|
|
|
2300
2575
|
* safeDate(1646711233171); // Tue Mar 08 2022 11:47:13 GMT+0800 (中国标准时间)
|
|
2301
2576
|
*
|
|
2302
2577
|
*/
|
|
2303
|
-
|
|
2304
|
-
|
|
2578
|
+
|
|
2579
|
+
function safeDate(value) {
|
|
2580
|
+
var safeValue = typeof value === 'string' ? value.replace(/[\\.-]/g, '/') : value;
|
|
2581
|
+
|
|
2582
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
2583
|
+
args[_key - 1] = arguments[_key];
|
|
2584
|
+
}
|
|
2305
2585
|
|
|
2306
2586
|
if (args && args.length > 0) {
|
|
2307
2587
|
// @ts-ignore
|
|
2308
|
-
return
|
|
2309
|
-
}
|
|
2588
|
+
return _construct(Date, [safeValue].concat(args));
|
|
2589
|
+
} // @ts-ignore
|
|
2590
|
+
|
|
2310
2591
|
|
|
2311
|
-
// @ts-ignore
|
|
2312
2592
|
return isNil(safeValue) ? new Date() : new Date(safeValue);
|
|
2313
2593
|
}
|
|
2314
2594
|
|
|
@@ -2335,16 +2615,23 @@
|
|
|
2335
2615
|
* formatMobile('133456') // '133 456'
|
|
2336
2616
|
* formatMobile('13345678') // '133 4567 8'
|
|
2337
2617
|
*/
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2618
|
+
|
|
2619
|
+
function formatMobile(mobileNo) {
|
|
2620
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
2621
|
+
_ref$char = _ref["char"],
|
|
2622
|
+
_char = _ref$char === void 0 ? ' ' : _ref$char;
|
|
2623
|
+
|
|
2624
|
+
var regChar = new RegExp(_char, 'g');
|
|
2625
|
+
var realValue = normalizeString(mobileNo).replace(regChar, '').substring(0, 11);
|
|
2341
2626
|
|
|
2342
2627
|
if (realValue.length > 7) {
|
|
2343
|
-
return realValue.replace(/^(...)(....)/g,
|
|
2628
|
+
return realValue.replace(/^(...)(....)/g, "$1".concat(_char, "$2").concat(_char));
|
|
2344
2629
|
}
|
|
2630
|
+
|
|
2345
2631
|
if (realValue.length > 3) {
|
|
2346
|
-
return realValue.replace(/^(...)/g,
|
|
2632
|
+
return realValue.replace(/^(...)/g, "$1".concat(_char));
|
|
2347
2633
|
}
|
|
2634
|
+
|
|
2348
2635
|
return realValue;
|
|
2349
2636
|
}
|
|
2350
2637
|
|
|
@@ -2370,9 +2657,11 @@
|
|
|
2370
2657
|
* padZero(688, 5); // '00688'
|
|
2371
2658
|
* padZero('688', 5); // '00688'
|
|
2372
2659
|
*/
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2660
|
+
|
|
2661
|
+
function padZero(value) {
|
|
2662
|
+
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
2663
|
+
var str = normalizeString(value);
|
|
2664
|
+
var len = str.length;
|
|
2376
2665
|
|
|
2377
2666
|
if (typeof size !== 'number' || size < 0) {
|
|
2378
2667
|
size = 0;
|
|
@@ -2381,6 +2670,7 @@
|
|
|
2381
2670
|
if (len < size) {
|
|
2382
2671
|
return '0'.repeat(size - len) + str;
|
|
2383
2672
|
}
|
|
2673
|
+
|
|
2384
2674
|
return str;
|
|
2385
2675
|
}
|
|
2386
2676
|
|
|
@@ -2409,6 +2699,7 @@
|
|
|
2409
2699
|
* isNumber('1')
|
|
2410
2700
|
* // => false
|
|
2411
2701
|
*/
|
|
2702
|
+
|
|
2412
2703
|
function isNumber(value) {
|
|
2413
2704
|
return isType(value, 'Number');
|
|
2414
2705
|
}
|
|
@@ -2432,25 +2723,31 @@
|
|
|
2432
2723
|
* times(3, 0.6, 2, 10);
|
|
2433
2724
|
* // => 36
|
|
2434
2725
|
*/
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2726
|
+
|
|
2727
|
+
function times() {
|
|
2728
|
+
for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2729
|
+
nums[_key] = arguments[_key];
|
|
2439
2730
|
}
|
|
2440
2731
|
|
|
2441
|
-
|
|
2732
|
+
var num1 = nums[0],
|
|
2733
|
+
num2 = nums[1],
|
|
2734
|
+
rest = nums.slice(2);
|
|
2735
|
+
|
|
2736
|
+
if (rest.length > 0) {
|
|
2737
|
+
return times.apply(void 0, [times(num1, num2)].concat(_toConsumableArray(rest)));
|
|
2738
|
+
} // 兼容处理,如果第2个参数为非数字或字符串时,返回第一个参数
|
|
2739
|
+
|
|
2740
|
+
|
|
2442
2741
|
if ((!isNumber(num2) || _isNaN(num2)) && !isString(num2)) {
|
|
2443
2742
|
// @ts-ignore
|
|
2444
2743
|
return num1;
|
|
2445
2744
|
}
|
|
2446
2745
|
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2746
|
+
var num1Changed = float2Fixed(num1);
|
|
2747
|
+
var num2Changed = float2Fixed(num2);
|
|
2748
|
+
var baseNum = digitLength(num1) + digitLength(num2);
|
|
2749
|
+
var leftValue = num1Changed * num2Changed;
|
|
2452
2750
|
checkBoundary(leftValue);
|
|
2453
|
-
|
|
2454
2751
|
return leftValue / Math.pow(10, baseNum);
|
|
2455
2752
|
}
|
|
2456
2753
|
|
|
@@ -2473,20 +2770,27 @@
|
|
|
2473
2770
|
* plus(0.1, 0.2, 0.3, 0.4);
|
|
2474
2771
|
* // => 1
|
|
2475
2772
|
*/
|
|
2476
|
-
function plus(...nums) {
|
|
2477
|
-
const [num1, num2, ...rest] = nums;
|
|
2478
2773
|
|
|
2479
|
-
|
|
2480
|
-
|
|
2774
|
+
function plus() {
|
|
2775
|
+
for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2776
|
+
nums[_key] = arguments[_key];
|
|
2481
2777
|
}
|
|
2482
2778
|
|
|
2483
|
-
|
|
2779
|
+
var num1 = nums[0],
|
|
2780
|
+
num2 = nums[1],
|
|
2781
|
+
rest = nums.slice(2);
|
|
2782
|
+
|
|
2783
|
+
if (rest.length > 0) {
|
|
2784
|
+
return plus.apply(void 0, [plus(num1, num2)].concat(_toConsumableArray(rest)));
|
|
2785
|
+
} // 兼容处理,如果第2个参数为非数字或字符串时,返回第一个参数
|
|
2786
|
+
|
|
2787
|
+
|
|
2484
2788
|
if ((!isNumber(num2) || _isNaN(num2)) && !isString(num2)) {
|
|
2485
2789
|
// @ts-ignore
|
|
2486
2790
|
return num1;
|
|
2487
2791
|
}
|
|
2488
2792
|
|
|
2489
|
-
|
|
2793
|
+
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
2490
2794
|
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
|
|
2491
2795
|
}
|
|
2492
2796
|
|
|
@@ -2509,20 +2813,27 @@
|
|
|
2509
2813
|
* minus(1, 0.9, 0.02, 0.08);
|
|
2510
2814
|
* // => 0
|
|
2511
2815
|
*/
|
|
2512
|
-
function minus(...nums) {
|
|
2513
|
-
const [num1, num2, ...rest] = nums;
|
|
2514
2816
|
|
|
2515
|
-
|
|
2516
|
-
|
|
2817
|
+
function minus() {
|
|
2818
|
+
for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2819
|
+
nums[_key] = arguments[_key];
|
|
2517
2820
|
}
|
|
2518
2821
|
|
|
2519
|
-
|
|
2822
|
+
var num1 = nums[0],
|
|
2823
|
+
num2 = nums[1],
|
|
2824
|
+
rest = nums.slice(2);
|
|
2825
|
+
|
|
2826
|
+
if (rest.length > 0) {
|
|
2827
|
+
return minus.apply(void 0, [minus(num1, num2)].concat(_toConsumableArray(rest)));
|
|
2828
|
+
} // 兼容处理,如果第2个参数为非数字或字符串时,返回第一个参数
|
|
2829
|
+
|
|
2830
|
+
|
|
2520
2831
|
if ((!isNumber(num2) || _isNaN(num2)) && !isString(num2)) {
|
|
2521
2832
|
// @ts-ignore
|
|
2522
2833
|
return num1;
|
|
2523
2834
|
}
|
|
2524
2835
|
|
|
2525
|
-
|
|
2836
|
+
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
2526
2837
|
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
|
|
2527
2838
|
}
|
|
2528
2839
|
|
|
@@ -2545,24 +2856,31 @@
|
|
|
2545
2856
|
* divide(1000, 10, 10, 10);
|
|
2546
2857
|
* // => 1
|
|
2547
2858
|
*/
|
|
2548
|
-
function divide(...nums) {
|
|
2549
|
-
const [num1, num2, ...rest] = nums;
|
|
2550
2859
|
|
|
2551
|
-
|
|
2552
|
-
|
|
2860
|
+
function divide() {
|
|
2861
|
+
for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2862
|
+
nums[_key] = arguments[_key];
|
|
2553
2863
|
}
|
|
2554
2864
|
|
|
2555
|
-
|
|
2865
|
+
var num1 = nums[0],
|
|
2866
|
+
num2 = nums[1],
|
|
2867
|
+
rest = nums.slice(2);
|
|
2868
|
+
|
|
2869
|
+
if (rest.length > 0) {
|
|
2870
|
+
return divide.apply(void 0, [divide(num1, num2)].concat(_toConsumableArray(rest)));
|
|
2871
|
+
} // 兼容处理,如果第2个参数为非数字或字符串时,返回第一个参数
|
|
2872
|
+
|
|
2873
|
+
|
|
2556
2874
|
if ((!isNumber(num2) || _isNaN(num2)) && !isString(num2)) {
|
|
2557
2875
|
// @ts-ignore
|
|
2558
2876
|
return num1;
|
|
2559
2877
|
}
|
|
2560
2878
|
|
|
2561
|
-
|
|
2562
|
-
|
|
2879
|
+
var num1Changed = float2Fixed(num1);
|
|
2880
|
+
var num2Changed = float2Fixed(num2);
|
|
2563
2881
|
checkBoundary(num1Changed);
|
|
2564
|
-
checkBoundary(num2Changed);
|
|
2565
|
-
|
|
2882
|
+
checkBoundary(num2Changed); // fix: 类似 10 ** -4 为 0.00009999999999999999,strip 修正
|
|
2883
|
+
|
|
2566
2884
|
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
|
|
2567
2885
|
}
|
|
2568
2886
|
|
|
@@ -2586,14 +2904,17 @@
|
|
|
2586
2904
|
* round(4060, -2);
|
|
2587
2905
|
* // => 4100
|
|
2588
2906
|
*/
|
|
2589
|
-
|
|
2907
|
+
|
|
2908
|
+
function round(num) {
|
|
2909
|
+
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
2910
|
+
|
|
2590
2911
|
// 兼容处理,如果参数为非数字或字符串时,直接返回
|
|
2591
2912
|
if ((!isNumber(num) || _isNaN(num)) && !isString(num)) {
|
|
2592
2913
|
// @ts-ignore
|
|
2593
2914
|
return num;
|
|
2594
2915
|
}
|
|
2595
2916
|
|
|
2596
|
-
|
|
2917
|
+
var base = Math.pow(10, precision);
|
|
2597
2918
|
return divide(Math.round(times(num, base)), base);
|
|
2598
2919
|
}
|
|
2599
2920
|
|
|
@@ -2615,14 +2936,13 @@
|
|
|
2615
2936
|
* // do something
|
|
2616
2937
|
* })
|
|
2617
2938
|
*/
|
|
2618
|
-
function waitTime(
|
|
2619
|
-
|
|
2939
|
+
function waitTime() {
|
|
2940
|
+
var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
|
|
2941
|
+
return new Promise(function (resolve) {
|
|
2620
2942
|
setTimeout(resolve, time);
|
|
2621
2943
|
});
|
|
2622
2944
|
}
|
|
2623
2945
|
|
|
2624
|
-
// ref: https://github.com/ant-design/ant-design-mobile/blob/v2/components/input-item/index.tsx#L240
|
|
2625
|
-
|
|
2626
2946
|
/**
|
|
2627
2947
|
* 计算输入框的值格式化后光标位置
|
|
2628
2948
|
*
|
|
@@ -2643,22 +2963,28 @@
|
|
|
2643
2963
|
* @param {'mobile'|'bankCard'} [options.type] 格式化类型,内置手机号码和银行卡号特殊处理
|
|
2644
2964
|
* @returns {number} 格式化后的光标位置
|
|
2645
2965
|
*/
|
|
2646
|
-
function calculateCursorPosition(prevPos, prevCtrlValue, rawValue, ctrlValue, { placeholderChar = ' ', maskReg = /\D/g, type } = {}) {
|
|
2647
|
-
const realCtrlValue = normalizeString(prevCtrlValue);
|
|
2648
|
-
const realRawValue = normalizeString(rawValue);
|
|
2649
|
-
const placeholderChars = Array.isArray(placeholderChar) ? placeholderChar : [placeholderChar];
|
|
2650
2966
|
|
|
2651
|
-
|
|
2652
|
-
|
|
2967
|
+
function calculateCursorPosition(prevPos, prevCtrlValue, rawValue, ctrlValue) {
|
|
2968
|
+
var _ref = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
|
|
2969
|
+
_ref$placeholderChar = _ref.placeholderChar,
|
|
2970
|
+
placeholderChar = _ref$placeholderChar === void 0 ? ' ' : _ref$placeholderChar,
|
|
2971
|
+
_ref$maskReg = _ref.maskReg,
|
|
2972
|
+
maskReg = _ref$maskReg === void 0 ? /\D/g : _ref$maskReg,
|
|
2973
|
+
type = _ref.type;
|
|
2653
2974
|
|
|
2654
|
-
|
|
2975
|
+
var realCtrlValue = normalizeString(prevCtrlValue);
|
|
2976
|
+
var realRawValue = normalizeString(rawValue);
|
|
2977
|
+
var placeholderChars = Array.isArray(placeholderChar) ? placeholderChar : [placeholderChar];
|
|
2978
|
+
var editLength = realRawValue.length - realCtrlValue.length;
|
|
2979
|
+
var isAddition = editLength > 0;
|
|
2980
|
+
var pos = prevPos;
|
|
2655
2981
|
|
|
2656
2982
|
if (isAddition) {
|
|
2657
|
-
|
|
2658
|
-
|
|
2983
|
+
var additionStr = realRawValue.substring(pos - editLength, pos);
|
|
2984
|
+
var ctrlCharCount = additionStr.replace(maskReg, '').length;
|
|
2659
2985
|
pos -= editLength - ctrlCharCount;
|
|
2986
|
+
var placeholderCharCount = 0;
|
|
2660
2987
|
|
|
2661
|
-
let placeholderCharCount = 0;
|
|
2662
2988
|
while (ctrlCharCount > 0) {
|
|
2663
2989
|
if (placeholderChars.indexOf(ctrlValue.charAt(pos - ctrlCharCount + placeholderCharCount)) !== -1) {
|
|
2664
2990
|
placeholderCharCount++;
|
|
@@ -2666,20 +2992,20 @@
|
|
|
2666
2992
|
ctrlCharCount--;
|
|
2667
2993
|
}
|
|
2668
2994
|
}
|
|
2995
|
+
|
|
2669
2996
|
pos += placeholderCharCount;
|
|
2670
2997
|
}
|
|
2671
2998
|
|
|
2672
|
-
if (
|
|
2999
|
+
if (type === 'mobile' && (pos === 4 || pos === 9) || type === 'bankCard' && pos > 0 && pos % 5 === 0) {
|
|
2673
3000
|
pos -= 1;
|
|
2674
3001
|
}
|
|
2675
3002
|
|
|
2676
3003
|
return pos;
|
|
2677
3004
|
}
|
|
2678
3005
|
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
3006
|
+
var numberChars = '0123456789';
|
|
3007
|
+
var letterChars = 'abcdefghijklmnopqrstuvwxyz';
|
|
3008
|
+
var defaultChars = numberChars + letterChars + letterChars.toUpperCase();
|
|
2683
3009
|
/**
|
|
2684
3010
|
* @private
|
|
2685
3011
|
* @param {number} [len=0] 长度
|
|
@@ -2687,14 +3013,19 @@
|
|
|
2687
3013
|
* @param {string} [prefix=''] 前缀部分,不计入长度
|
|
2688
3014
|
* @returns {string}
|
|
2689
3015
|
*/
|
|
2690
|
-
|
|
3016
|
+
|
|
3017
|
+
function internalRandomString() {
|
|
3018
|
+
var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
3019
|
+
var optionalChars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultChars;
|
|
3020
|
+
var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
3021
|
+
|
|
2691
3022
|
while (len-- > 0) {
|
|
2692
|
-
|
|
3023
|
+
var r = optionalChars[Math.floor(Math.random() * optionalChars.length)];
|
|
2693
3024
|
return internalRandomString(len, optionalChars, prefix + r);
|
|
2694
3025
|
}
|
|
3026
|
+
|
|
2695
3027
|
return prefix;
|
|
2696
3028
|
}
|
|
2697
|
-
|
|
2698
3029
|
/**
|
|
2699
3030
|
* 生成随机字符串
|
|
2700
3031
|
*
|
|
@@ -2712,10 +3043,13 @@
|
|
|
2712
3043
|
* randomString(5, 'abc'); // ccbcb
|
|
2713
3044
|
* randomString(8, 'abcefg'); // bcgcfabg
|
|
2714
3045
|
*/
|
|
2715
|
-
function randomString(len = 0, optionalChars) {
|
|
2716
3046
|
|
|
2717
|
-
const realChars = typeof optionalChars === 'string' && optionalChars ? optionalChars : defaultChars;
|
|
2718
3047
|
|
|
3048
|
+
function randomString() {
|
|
3049
|
+
var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
3050
|
+
var optionalChars = arguments.length > 1 ? arguments[1] : undefined;
|
|
3051
|
+
|
|
3052
|
+
var realChars = typeof optionalChars === 'string' && optionalChars ? optionalChars : defaultChars;
|
|
2719
3053
|
return internalRandomString(len, realChars);
|
|
2720
3054
|
}
|
|
2721
3055
|
|
|
@@ -2737,17 +3071,21 @@
|
|
|
2737
3071
|
* strlen('🍎'); // 4
|
|
2738
3072
|
*
|
|
2739
3073
|
*/
|
|
3074
|
+
|
|
2740
3075
|
function strlen(str) {
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
3076
|
+
var realStr = normalizeString(str);
|
|
3077
|
+
var len = 0;
|
|
3078
|
+
|
|
3079
|
+
for (var i = 0; i < realStr.length; i++) {
|
|
3080
|
+
var c = realStr.charCodeAt(i);
|
|
3081
|
+
|
|
3082
|
+
if (c >= 0x0001 && c <= 0x007e || 0xff60 <= c && c <= 0xff9f) {
|
|
2746
3083
|
len++;
|
|
2747
3084
|
} else {
|
|
2748
3085
|
len += 2;
|
|
2749
3086
|
}
|
|
2750
3087
|
}
|
|
3088
|
+
|
|
2751
3089
|
return len;
|
|
2752
3090
|
}
|
|
2753
3091
|
|