util-helpers 4.10.3 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/util-helpers.js +1076 -668
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/bytesToSize.js +4 -3
- package/esm/divide.js +6 -6
- package/esm/formatMoney.js +7 -10
- package/esm/index.js +32 -0
- package/esm/isBusinessLicense.js +2 -2
- package/esm/isChinese.js +24 -11
- package/esm/minus.js +6 -6
- package/esm/numberToChinese.js +30 -36
- package/esm/parseIdCard.js +9 -24
- package/esm/plus.js +6 -6
- package/esm/replaceChar.js +8 -7
- package/esm/round.js +7 -0
- package/esm/times.js +6 -6
- package/esm/utils/devWarn.js +16 -0
- package/esm/utils/math.util.js +82 -29
- package/esm/validatePassword.js +25 -20
- package/lib/bytesToSize.js +4 -3
- package/lib/divide.js +5 -6
- package/lib/formatMoney.js +7 -10
- package/lib/isBusinessLicense.js +2 -2
- package/lib/isChinese.js +24 -11
- package/lib/minus.js +5 -6
- package/lib/numberToChinese.js +32 -36
- package/lib/parseIdCard.js +9 -24
- package/lib/plus.js +5 -6
- package/lib/replaceChar.js +11 -8
- package/lib/round.js +8 -0
- package/lib/times.js +5 -6
- package/lib/utils/devWarn.js +24 -0
- package/lib/utils/math.util.js +87 -29
- package/lib/validatePassword.js +27 -20
- package/package.json +4 -2
- package/types/isChinese.d.ts +13 -3
- package/types/replaceChar.d.ts +1 -1
- package/types/utils/devWarn.d.ts +7 -0
- package/types/utils/math.util.d.ts +9 -2
- package/types/validatePassword.d.ts +3 -3
package/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
|
+
};
|
|
500
|
+
|
|
501
|
+
for (var i = 0; i < 17; i++) {
|
|
502
|
+
_loop(i);
|
|
503
|
+
} // 计算整数求余函数MOD
|
|
504
|
+
|
|
485
505
|
|
|
486
|
-
//
|
|
487
|
-
const remainder = total % 31;
|
|
488
|
-
// 校验码字符值序号
|
|
489
|
-
const checkCodeIndex = remainder !== 0 ? 31 - remainder : 0;
|
|
506
|
+
var remainder = total % 31; // 校验码字符值序号
|
|
490
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
|
+
|
|
534
556
|
|
|
535
|
-
//
|
|
536
|
-
const preCode = valueStr.substring(0, 17);
|
|
537
|
-
// 校验码
|
|
538
|
-
const lastCode = valueStr.substring(valueStr.length - 1);
|
|
539
|
-
// 计算校验码
|
|
540
|
-
const checkCode = sumCheckCode$1(preCode);
|
|
557
|
+
var preCode = valueStr.substring(0, 17); // 校验码
|
|
541
558
|
|
|
559
|
+
var lastCode = valueStr.substring(valueStr.length - 1); // 计算校验码
|
|
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,15 +573,29 @@
|
|
|
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
|
}
|
|
560
580
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
581
|
+
/**
|
|
582
|
+
* 打印警告信息
|
|
583
|
+
*
|
|
584
|
+
* @param {any[]} args 打印的信息
|
|
585
|
+
*/
|
|
586
|
+
|
|
587
|
+
function devWarn() {
|
|
588
|
+
if (!config.disableWarning) {
|
|
589
|
+
var _console;
|
|
590
|
+
|
|
591
|
+
(_console = console).warn.apply(_console, arguments);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
565
594
|
|
|
595
|
+
var regNumber = /[\d]/;
|
|
596
|
+
var regLowerCaseLetter = /[a-z]/;
|
|
597
|
+
var regUpperCaseLetter = /[A-Z]/;
|
|
598
|
+
var regAllNumberAndLetter = /[\d|a-z]/gi;
|
|
566
599
|
/**
|
|
567
600
|
* 是否包含数字
|
|
568
601
|
*
|
|
@@ -570,10 +603,10 @@
|
|
|
570
603
|
* @param {string} val 检查的值
|
|
571
604
|
* @returns {boolean} 是否包含数字
|
|
572
605
|
*/
|
|
606
|
+
|
|
573
607
|
function hasNumber(val) {
|
|
574
608
|
return regNumber.test(val);
|
|
575
609
|
}
|
|
576
|
-
|
|
577
610
|
/**
|
|
578
611
|
* 是否包含小写字母
|
|
579
612
|
*
|
|
@@ -581,10 +614,11 @@
|
|
|
581
614
|
* @param {string} val 检测的值
|
|
582
615
|
* @returns {boolean} 是否包含小写字母
|
|
583
616
|
*/
|
|
617
|
+
|
|
618
|
+
|
|
584
619
|
function hasLowerCaseLetter(val) {
|
|
585
620
|
return regLowerCaseLetter.test(val);
|
|
586
621
|
}
|
|
587
|
-
|
|
588
622
|
/**
|
|
589
623
|
* 是否包含大写字母
|
|
590
624
|
*
|
|
@@ -592,10 +626,11 @@
|
|
|
592
626
|
* @param {string} val 检测的值
|
|
593
627
|
* @returns {boolean} 是否包含大写字母
|
|
594
628
|
*/
|
|
629
|
+
|
|
630
|
+
|
|
595
631
|
function hasUpperCaseLetter(val) {
|
|
596
632
|
return regUpperCaseLetter.test(val);
|
|
597
633
|
}
|
|
598
|
-
|
|
599
634
|
/**
|
|
600
635
|
* 是否为十六进制
|
|
601
636
|
*
|
|
@@ -603,69 +638,87 @@
|
|
|
603
638
|
* @param {string} val 检测的值
|
|
604
639
|
* @returns {boolean} 是否为十六进制
|
|
605
640
|
*/
|
|
641
|
+
|
|
642
|
+
|
|
606
643
|
function hasHex(val) {
|
|
607
|
-
return val.indexOf('\\x') > -1 || val.indexOf(
|
|
644
|
+
return val.indexOf('\\x') > -1 || val.indexOf("\\u") > -1;
|
|
608
645
|
}
|
|
609
|
-
|
|
610
646
|
/**
|
|
611
647
|
* 是否包含特殊字符
|
|
612
648
|
*
|
|
613
649
|
* @private
|
|
614
650
|
* @param {string} val 检测的值
|
|
615
|
-
* @param {string}
|
|
651
|
+
* @param {string} chars 特殊字符
|
|
616
652
|
* @returns {boolean} 是否包含特殊字符
|
|
617
653
|
*/
|
|
618
|
-
|
|
619
|
-
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
function hasSpecialCharacter(val, chars) {
|
|
657
|
+
if (!chars || !val) {
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
var specialChars = val.replace(regAllNumberAndLetter, '');
|
|
662
|
+
|
|
663
|
+
if (!specialChars) {
|
|
620
664
|
return false;
|
|
621
665
|
}
|
|
622
666
|
|
|
623
|
-
|
|
624
|
-
const regChars = hasHex(chars) ? new RegExp(`[${chars}]`) : null;
|
|
667
|
+
var regChars = hasHex(chars) ? new RegExp("[".concat(chars, "]")) : null;
|
|
625
668
|
|
|
626
669
|
if (regChars) {
|
|
627
670
|
return regChars.test(specialChars);
|
|
628
671
|
}
|
|
629
672
|
|
|
630
|
-
|
|
631
|
-
specialChars.split('').some((charItem)
|
|
673
|
+
var ret = false;
|
|
674
|
+
specialChars.split('').some(function (charItem) {
|
|
632
675
|
if (chars.indexOf(charItem) > -1) {
|
|
633
676
|
ret = true;
|
|
634
677
|
}
|
|
678
|
+
|
|
635
679
|
return ret;
|
|
636
680
|
});
|
|
637
681
|
return ret;
|
|
638
682
|
}
|
|
639
|
-
|
|
640
683
|
/**
|
|
641
684
|
* 是否包含非法字符
|
|
642
685
|
*
|
|
643
686
|
* @private
|
|
644
687
|
* @param {string} val 检测的值
|
|
645
|
-
* @param {string} chars
|
|
688
|
+
* @param {string} chars 特殊字符
|
|
646
689
|
* @returns {boolean} 是否包含非法字符
|
|
647
690
|
*/
|
|
648
|
-
function hasUnallowableCharacter(val, chars = '') {
|
|
649
|
-
const specialChars = val.replace(regAllNumberAndLetter, '');
|
|
650
691
|
|
|
651
|
-
|
|
692
|
+
|
|
693
|
+
function hasUnallowableCharacter(val, chars) {
|
|
694
|
+
if (!val) {
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
var specialChars = val.replace(regAllNumberAndLetter, '');
|
|
699
|
+
|
|
700
|
+
if (!specialChars) {
|
|
701
|
+
return false;
|
|
702
|
+
} else if (!chars) {
|
|
652
703
|
return true;
|
|
653
704
|
}
|
|
654
705
|
|
|
655
|
-
|
|
706
|
+
var regChars = hasHex(chars) ? new RegExp("[^".concat(chars, "]")) : null;
|
|
707
|
+
|
|
656
708
|
if (regChars) {
|
|
657
709
|
return regChars.test(specialChars);
|
|
658
710
|
}
|
|
659
|
-
|
|
660
|
-
|
|
711
|
+
|
|
712
|
+
var ret = false;
|
|
713
|
+
specialChars.split('').some(function (charItem) {
|
|
661
714
|
if (chars.indexOf(charItem) === -1) {
|
|
662
715
|
ret = true;
|
|
663
716
|
}
|
|
717
|
+
|
|
664
718
|
return ret;
|
|
665
719
|
});
|
|
666
720
|
return ret;
|
|
667
721
|
}
|
|
668
|
-
|
|
669
722
|
/**
|
|
670
723
|
* @typedef {Object} PasswordContaines - 验证密码的包含内容
|
|
671
724
|
* @property {boolean} number - 包含数字
|
|
@@ -711,7 +764,7 @@
|
|
|
711
764
|
* }
|
|
712
765
|
* }
|
|
713
766
|
*
|
|
714
|
-
* validatePassword('a12345678', {level: 3});
|
|
767
|
+
* validatePassword('a12345678', { level: 3 });
|
|
715
768
|
* // =>
|
|
716
769
|
* {
|
|
717
770
|
* validated: false,
|
|
@@ -725,7 +778,7 @@
|
|
|
725
778
|
* }
|
|
726
779
|
* }
|
|
727
780
|
*
|
|
728
|
-
* validatePassword('_Aa一二三45678', {level: 3, ignoreCase: true});
|
|
781
|
+
* validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true });
|
|
729
782
|
* // =>
|
|
730
783
|
* {
|
|
731
784
|
* validated: false,
|
|
@@ -740,7 +793,7 @@
|
|
|
740
793
|
* }
|
|
741
794
|
*
|
|
742
795
|
* // 自定义特殊字符
|
|
743
|
-
* validatePassword('_Aa一二三45678', {level: 3, ignoreCase: true, special: '_一二三'});
|
|
796
|
+
* validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true, special: '_一二三' });
|
|
744
797
|
* // =>
|
|
745
798
|
* {
|
|
746
799
|
* validated: true,
|
|
@@ -754,35 +807,42 @@
|
|
|
754
807
|
* }
|
|
755
808
|
* }
|
|
756
809
|
*/
|
|
757
|
-
|
|
758
|
-
|
|
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;
|
|
759
822
|
|
|
760
823
|
if (typeof value !== 'string') {
|
|
761
|
-
|
|
762
|
-
console.warn(`[validatePassword] value must be a string.`);
|
|
763
|
-
}
|
|
824
|
+
devWarn("[validatePassword] value must be a string.");
|
|
764
825
|
valStr = '';
|
|
765
826
|
}
|
|
766
827
|
|
|
767
|
-
|
|
828
|
+
var currentLevel = 0; // 包含数字
|
|
829
|
+
|
|
830
|
+
var containesNumber = hasNumber(valStr); // 包含小写字母
|
|
831
|
+
|
|
832
|
+
var containesLowerCaseLetter = hasLowerCaseLetter(valStr); // 包含大写字母
|
|
768
833
|
|
|
769
|
-
//
|
|
770
|
-
|
|
771
|
-
//
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
const containesUpperCaseLetter = hasUpperCaseLetter(valStr);
|
|
775
|
-
// 包含特殊字符
|
|
776
|
-
const containesSpecialCharacter = hasSpecialCharacter(valStr, special);
|
|
777
|
-
// 包含非法字符
|
|
778
|
-
const containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
|
|
834
|
+
var containesUpperCaseLetter = hasUpperCaseLetter(valStr); // 包含特殊字符
|
|
835
|
+
|
|
836
|
+
var containesSpecialCharacter = hasSpecialCharacter(valStr, special); // 包含非法字符,即含有非数字字母特殊字符以外的其他字符
|
|
837
|
+
|
|
838
|
+
var containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
|
|
779
839
|
|
|
780
840
|
if (containesNumber) {
|
|
781
841
|
currentLevel += 1;
|
|
782
|
-
}
|
|
842
|
+
} // 不区分大小写
|
|
843
|
+
|
|
783
844
|
|
|
784
845
|
if (ignoreCase) {
|
|
785
|
-
// 不区分大小写
|
|
786
846
|
if (containesLowerCaseLetter || containesUpperCaseLetter) {
|
|
787
847
|
currentLevel += 1;
|
|
788
848
|
}
|
|
@@ -791,6 +851,7 @@
|
|
|
791
851
|
if (containesLowerCaseLetter) {
|
|
792
852
|
currentLevel += 1;
|
|
793
853
|
}
|
|
854
|
+
|
|
794
855
|
if (containesUpperCaseLetter) {
|
|
795
856
|
currentLevel += 1;
|
|
796
857
|
}
|
|
@@ -798,13 +859,12 @@
|
|
|
798
859
|
|
|
799
860
|
if (containesSpecialCharacter) {
|
|
800
861
|
currentLevel += 1;
|
|
801
|
-
}
|
|
862
|
+
} // 验证结果
|
|
802
863
|
|
|
803
|
-
// 验证结果
|
|
804
|
-
const validated = currentLevel >= level && !containesUnallowableCharacter;
|
|
805
864
|
|
|
865
|
+
var validated = currentLevel >= level && !containesUnallowableCharacter;
|
|
806
866
|
return {
|
|
807
|
-
validated,
|
|
867
|
+
validated: validated,
|
|
808
868
|
level: currentLevel,
|
|
809
869
|
containes: {
|
|
810
870
|
number: containesNumber,
|
|
@@ -856,13 +916,24 @@
|
|
|
856
916
|
* isPassword(' _Aa12345678', {level: 3, ignoreCase: true});
|
|
857
917
|
* // => false
|
|
858
918
|
*/
|
|
859
|
-
function isPassword(value, { level = 2, ignoreCase = false, special = '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' } = {}) {
|
|
860
|
-
return validatePassword(value, { level, ignoreCase, special }).validated;
|
|
861
|
-
}
|
|
862
919
|
|
|
863
|
-
|
|
864
|
-
|
|
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
|
+
}
|
|
865
935
|
|
|
936
|
+
var reg$5 = /^((e[\da-z])|(de)|(se)|(pe)|([khm][\da-z]))[\da-z]{7}$/i;
|
|
866
937
|
/**
|
|
867
938
|
* 检测值是否为护照号
|
|
868
939
|
* 支持普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ/H*)、澳门特区护照(MA/MB/M*),注意不区分大小写
|
|
@@ -882,49 +953,37 @@
|
|
|
882
953
|
* // => false
|
|
883
954
|
*
|
|
884
955
|
*/
|
|
956
|
+
|
|
885
957
|
function isPassport(value) {
|
|
886
|
-
|
|
958
|
+
var valueStr = normalizeString(value);
|
|
887
959
|
return reg$5.test(valueStr);
|
|
888
960
|
}
|
|
889
961
|
|
|
890
|
-
|
|
962
|
+
var chineseDictionary = {
|
|
891
963
|
// 基本汉字
|
|
892
|
-
chineseBasic:
|
|
893
|
-
|
|
964
|
+
chineseBasic: "[\u4E00-\u9FA5]",
|
|
894
965
|
// 基本汉字补充
|
|
895
|
-
chineseExtend:
|
|
896
|
-
|
|
966
|
+
chineseExtend: "[\u9EA6-\u9FEF]",
|
|
897
967
|
// 汉字扩展A
|
|
898
|
-
chineseExtendA:
|
|
899
|
-
|
|
968
|
+
chineseExtendA: "[\u3400-\u4DB5]",
|
|
900
969
|
// 汉字扩展B
|
|
901
|
-
chineseExtendB:
|
|
902
|
-
|
|
970
|
+
chineseExtendB: "[\uD840\uDC00-\uD869\uDED6]",
|
|
903
971
|
// 汉字扩展C
|
|
904
|
-
chineseExtendC:
|
|
905
|
-
|
|
972
|
+
chineseExtendC: "[\uD869\uDF00-\uD86D\uDF34]",
|
|
906
973
|
// 汉字扩展D
|
|
907
|
-
chineseExtendD:
|
|
908
|
-
|
|
974
|
+
chineseExtendD: "[\uD86D\uDF40-\uD86E\uDC1D]",
|
|
909
975
|
// 汉字扩展E
|
|
910
|
-
chineseExtendE:
|
|
911
|
-
|
|
976
|
+
chineseExtendE: "[\uD86E\uDC20-\uD873\uDEA1]",
|
|
912
977
|
// 汉字扩展F
|
|
913
|
-
chineseExtendF:
|
|
978
|
+
chineseExtendF: "[\uD873\uDEB0-\uD87A\uDFE0]"
|
|
914
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
|
|
915
985
|
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
let chineseRegExp = '^' + chineseDictionary.chineseBasic + '+$';
|
|
919
|
-
|
|
920
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
921
|
-
const supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');
|
|
922
|
-
|
|
923
|
-
if (supportRegExpUnicode) {
|
|
924
|
-
looseChineseRegExp = '(?:' + chineseDictionary.chineseBasic + '|' + chineseDictionary.chineseExtend + '|' + chineseDictionary.chineseExtendA + '|' + chineseDictionary.chineseExtendB + '|' + chineseDictionary.chineseExtendC + '|' + chineseDictionary.chineseExtendD + '|' + chineseDictionary.chineseExtendE + '|' + chineseDictionary.chineseExtendF + ')+';
|
|
925
|
-
chineseRegExp = '^(?:' + chineseDictionary.chineseBasic + '|' + chineseDictionary.chineseExtend + '|' + chineseDictionary.chineseExtendA + '|' + chineseDictionary.chineseExtendB + '|' + chineseDictionary.chineseExtendC + '|' + chineseDictionary.chineseExtendD + '|' + chineseDictionary.chineseExtendE + '|' + chineseDictionary.chineseExtendF + ')+$';
|
|
926
|
-
}
|
|
927
|
-
|
|
986
|
+
var supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');
|
|
928
987
|
/**
|
|
929
988
|
* 检测值是否为中文
|
|
930
989
|
*
|
|
@@ -935,6 +994,7 @@
|
|
|
935
994
|
* @param {*} value 要检测的值
|
|
936
995
|
* @param {Object} [options] 配置项
|
|
937
996
|
* @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
|
|
997
|
+
* @param {boolean} [options.useExtend=false] 使用统一表意文字扩展A-F。注意:如果不支持 `RegExp.prototype.unicode`,扩展字符集将自动不生效,如IE浏览器。
|
|
938
998
|
* @returns {boolean} 值是否为中文
|
|
939
999
|
* @example
|
|
940
1000
|
*
|
|
@@ -945,22 +1005,40 @@
|
|
|
945
1005
|
* // => false
|
|
946
1006
|
*
|
|
947
1007
|
* // 宽松模式,只要包含中文即为true
|
|
948
|
-
* isChinese('林A', {loose: true});
|
|
1008
|
+
* isChinese('林A', { loose: true });
|
|
949
1009
|
* // => true
|
|
950
1010
|
*
|
|
951
|
-
* isChinese('A林A', {loose: true});
|
|
1011
|
+
* isChinese('A林A', { loose: true });
|
|
952
1012
|
* // => true
|
|
953
1013
|
*
|
|
1014
|
+
* isChinese('𠮷');
|
|
1015
|
+
* // => false
|
|
1016
|
+
*
|
|
1017
|
+
* // 使用中文扩展字符集,需要浏览器支持 RegExp.prototype.unicode 才生效。
|
|
1018
|
+
* isChinese('𠮷', { useExtend: true });
|
|
1019
|
+
* // => true
|
|
1020
|
+
* isChinese('𠮷aa', { useExtend: true, loose: true });
|
|
1021
|
+
* // => true
|
|
954
1022
|
*/
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
1023
|
+
|
|
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);
|
|
958
1038
|
return reg.test(valueStr);
|
|
959
1039
|
}
|
|
960
1040
|
|
|
961
|
-
|
|
962
|
-
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])$/;
|
|
963
|
-
|
|
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])$/;
|
|
964
1042
|
/**
|
|
965
1043
|
* 检测值是否为ipv4
|
|
966
1044
|
*
|
|
@@ -984,14 +1062,13 @@
|
|
|
984
1062
|
* // => false
|
|
985
1063
|
*
|
|
986
1064
|
*/
|
|
1065
|
+
|
|
987
1066
|
function isIPv4(value) {
|
|
988
|
-
|
|
1067
|
+
var valueStr = normalizeString(value);
|
|
989
1068
|
return reg$4.test(valueStr);
|
|
990
1069
|
}
|
|
991
1070
|
|
|
992
|
-
|
|
993
|
-
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;
|
|
994
|
-
|
|
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;
|
|
995
1072
|
/**
|
|
996
1073
|
* 检测值是否为ipv6
|
|
997
1074
|
*
|
|
@@ -1040,14 +1117,13 @@
|
|
|
1040
1117
|
* // => false
|
|
1041
1118
|
*
|
|
1042
1119
|
*/
|
|
1120
|
+
|
|
1043
1121
|
function isIPv6(value) {
|
|
1044
|
-
|
|
1122
|
+
var valueStr = normalizeString(value);
|
|
1045
1123
|
return reg$3.test(valueStr);
|
|
1046
1124
|
}
|
|
1047
1125
|
|
|
1048
|
-
|
|
1049
|
-
const reg$2 = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\*\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
|
|
1050
|
-
|
|
1126
|
+
var reg$2 = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\*\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
|
|
1051
1127
|
/**
|
|
1052
1128
|
* 检测值是否为url
|
|
1053
1129
|
*
|
|
@@ -1080,14 +1156,13 @@
|
|
|
1080
1156
|
* isUrl('http://www.example.com/test/123?foo=bar');
|
|
1081
1157
|
* // => true
|
|
1082
1158
|
*/
|
|
1159
|
+
|
|
1083
1160
|
function isUrl(value) {
|
|
1084
|
-
|
|
1161
|
+
var valueStr = normalizeString(value);
|
|
1085
1162
|
return reg$2.test(valueStr);
|
|
1086
1163
|
}
|
|
1087
1164
|
|
|
1088
|
-
|
|
1089
|
-
const baseReg = /^\d{15}$/;
|
|
1090
|
-
|
|
1165
|
+
var baseReg = /^\d{15}$/;
|
|
1091
1166
|
/**
|
|
1092
1167
|
* 计算校验码
|
|
1093
1168
|
*
|
|
@@ -1096,29 +1171,29 @@
|
|
|
1096
1171
|
* @param {string} preCode 营业执照前14位
|
|
1097
1172
|
* @returns {number} 校验码
|
|
1098
1173
|
*/
|
|
1174
|
+
|
|
1099
1175
|
function sumCheckCode(preCode) {
|
|
1100
|
-
|
|
1176
|
+
var retNum; // 校验位数字
|
|
1101
1177
|
|
|
1102
|
-
|
|
1178
|
+
var pj = 10; // Pj+1 11,初始为10
|
|
1103
1179
|
|
|
1104
|
-
for (
|
|
1105
|
-
|
|
1106
|
-
|
|
1180
|
+
for (var j = 0; j < 14; j++) {
|
|
1181
|
+
var sj = pj + Number(preCode[j]);
|
|
1182
|
+
var sj10 = sj % 10;
|
|
1107
1183
|
sj10 = sj10 === 0 ? 10 : sj10;
|
|
1108
|
-
|
|
1184
|
+
var pj1 = sj10 * 2;
|
|
1109
1185
|
pj = pj1 % 11;
|
|
1110
|
-
}
|
|
1186
|
+
} // 反模10计算
|
|
1111
1187
|
|
|
1112
|
-
|
|
1113
|
-
if (pj ===
|
|
1114
|
-
retNum =
|
|
1188
|
+
|
|
1189
|
+
if (pj === 1) {
|
|
1190
|
+
retNum = 0;
|
|
1115
1191
|
} else {
|
|
1116
1192
|
retNum = 11 - pj;
|
|
1117
1193
|
}
|
|
1118
1194
|
|
|
1119
1195
|
return retNum;
|
|
1120
1196
|
}
|
|
1121
|
-
|
|
1122
1197
|
/**
|
|
1123
1198
|
* 检测值是否为营业执照号,也叫工商注册号。由14位数字本体码和1位数字校验码组成,其中本体码从左至右依次为:6位首次登记机关码、8位顺序码。
|
|
1124
1199
|
*
|
|
@@ -1144,30 +1219,241 @@
|
|
|
1144
1219
|
* isBusinessLicense('31011560098', { checkCode: false });
|
|
1145
1220
|
* // => false
|
|
1146
1221
|
*/
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
function isBusinessLicense(value) {
|
|
1225
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1226
|
+
var valueStr = normalizeString(value); // @ts-ignore
|
|
1150
1227
|
// TODO 下个版本废弃 loose
|
|
1151
|
-
const { loose = false, checkCode: cc = true } = options;
|
|
1152
|
-
const needCheckCode = !loose && cc;
|
|
1153
1228
|
|
|
1154
|
-
|
|
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); // 宽松模式 或 基础规则不通过直接返回
|
|
1155
1235
|
|
|
1156
|
-
// 宽松模式 或 基础规则不通过直接返回
|
|
1157
1236
|
if (!needCheckCode || !passBaseRule) {
|
|
1158
1237
|
return passBaseRule;
|
|
1159
|
-
}
|
|
1238
|
+
} // 前14位
|
|
1239
|
+
|
|
1160
1240
|
|
|
1161
|
-
//
|
|
1162
|
-
const preCode = valueStr.substring(0, 14);
|
|
1163
|
-
// 校验码
|
|
1164
|
-
const lastCode = valueStr.substring(valueStr.length - 1);
|
|
1165
|
-
// 计算校验码
|
|
1166
|
-
const checkCode = sumCheckCode(preCode);
|
|
1241
|
+
var preCode = valueStr.substring(0, 14); // 校验码
|
|
1167
1242
|
|
|
1243
|
+
var lastCode = valueStr.substring(valueStr.length - 1); // 计算校验码
|
|
1244
|
+
|
|
1245
|
+
var checkCode = sumCheckCode(preCode);
|
|
1168
1246
|
return lastCode === String(checkCode);
|
|
1169
1247
|
}
|
|
1170
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
|
+
|
|
1171
1457
|
/**
|
|
1172
1458
|
* 检测值是否类似Promise对象
|
|
1173
1459
|
*
|
|
@@ -1188,12 +1474,10 @@
|
|
|
1188
1474
|
* => true
|
|
1189
1475
|
*/
|
|
1190
1476
|
function isPromiseLike(obj) {
|
|
1191
|
-
return obj !== null && (
|
|
1477
|
+
return obj !== null && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
|
1192
1478
|
}
|
|
1193
1479
|
|
|
1194
|
-
|
|
1195
|
-
const regHMCard = /^[hm]{1}([0-9]{10}|[0-9]{8})$/i;
|
|
1196
|
-
|
|
1480
|
+
var regHMCard = /^[hm]{1}([0-9]{10}|[0-9]{8})$/i;
|
|
1197
1481
|
/**
|
|
1198
1482
|
* 检测值是否为港澳居民来往内地通行证,俗称回乡证或回乡卡。
|
|
1199
1483
|
*
|
|
@@ -1216,17 +1500,15 @@
|
|
|
1216
1500
|
* isHMCard('m32031177') // true
|
|
1217
1501
|
* isHMCard('M32031177') // true
|
|
1218
1502
|
*/
|
|
1503
|
+
|
|
1219
1504
|
function isHMCard(value) {
|
|
1220
|
-
|
|
1505
|
+
var valueStr = normalizeString(value);
|
|
1221
1506
|
return regHMCard.test(valueStr);
|
|
1222
1507
|
}
|
|
1223
1508
|
|
|
1224
|
-
//
|
|
1225
|
-
const regTWCard = /^\d{8}$/i;
|
|
1226
|
-
|
|
1227
|
-
// 一次性短期台胞证
|
|
1228
|
-
const singleRegTWCard = /^[\da-z]{10,12}$/i;
|
|
1509
|
+
var regTWCard = /^\d{8}$/i; // 一次性短期台胞证
|
|
1229
1510
|
|
|
1511
|
+
var singleRegTWCard = /^[\da-z]{10,12}$/i;
|
|
1230
1512
|
/**
|
|
1231
1513
|
* 检测值是否为台湾居民来往大陆通行证,俗称台胞证。
|
|
1232
1514
|
*
|
|
@@ -1246,16 +1528,22 @@
|
|
|
1246
1528
|
* isTWCard('F290299977') // false
|
|
1247
1529
|
* isTWCard('F290299977', { loose: true }) // true
|
|
1248
1530
|
*/
|
|
1249
|
-
|
|
1250
|
-
|
|
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
|
+
|
|
1251
1539
|
if (regTWCard.test(valueStr)) {
|
|
1252
1540
|
return true;
|
|
1253
1541
|
}
|
|
1542
|
+
|
|
1254
1543
|
return loose ? singleRegTWCard.test(valueStr) : false;
|
|
1255
1544
|
}
|
|
1256
1545
|
|
|
1257
|
-
|
|
1258
|
-
|
|
1546
|
+
var reg$1 = /^[A-Z]{6}[A-Z\d]{2}(?:[A-Z\d]{3})?$/;
|
|
1259
1547
|
/**
|
|
1260
1548
|
* 检测值是否为 Swift Code。8位或11位,前6位为大写字母,7-8位为大写字母或数字,9-11位为可选的大写字母或数字。
|
|
1261
1549
|
*
|
|
@@ -1267,24 +1555,76 @@
|
|
|
1267
1555
|
* @returns {boolean} 值是否为 Swift Code
|
|
1268
1556
|
* @example
|
|
1269
1557
|
*
|
|
1270
|
-
* isSwiftCode('DEUTDEFF') // true
|
|
1271
|
-
* isSwiftCode('deutdeff') // false
|
|
1558
|
+
* isSwiftCode('DEUTDEFF') // true
|
|
1559
|
+
* isSwiftCode('deutdeff') // false
|
|
1560
|
+
*
|
|
1561
|
+
* isSwiftCode('BKTWTWTP010') // true
|
|
1562
|
+
* isSwiftCode('010BKTWTWTP') // false
|
|
1563
|
+
*
|
|
1564
|
+
* isSwiftCode('ICBKCNBJBJM') // true
|
|
1565
|
+
*
|
|
1566
|
+
*/
|
|
1567
|
+
|
|
1568
|
+
function isSwiftCode(value) {
|
|
1569
|
+
var valueStr = normalizeString(value);
|
|
1570
|
+
return reg$1.test(valueStr);
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
// 最大安全数字
|
|
1574
|
+
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // 最小安全数字
|
|
1575
|
+
|
|
1576
|
+
var MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
|
|
1577
|
+
|
|
1578
|
+
/**
|
|
1579
|
+
* 检查值是否为NaN
|
|
1580
|
+
*
|
|
1581
|
+
* @static
|
|
1582
|
+
* @alias module:Type.isNaN
|
|
1583
|
+
* @since 1.1.0
|
|
1584
|
+
* @param {*} value 检查值
|
|
1585
|
+
* @returns {boolean} 是否为NaN
|
|
1586
|
+
* @example
|
|
1587
|
+
*
|
|
1588
|
+
* isNaN(NaN)
|
|
1589
|
+
* // => true
|
|
1590
|
+
*
|
|
1591
|
+
* isNaN(1)
|
|
1592
|
+
* // => false
|
|
1593
|
+
*/
|
|
1594
|
+
|
|
1595
|
+
function _isNaN(value) {
|
|
1596
|
+
return isType(value, 'Number') && isNaN(value);
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
/**
|
|
1600
|
+
* 检查值是否为Number
|
|
1601
|
+
*
|
|
1602
|
+
* @static
|
|
1603
|
+
* @alias module:Type.isNumber
|
|
1604
|
+
* @since 1.1.0
|
|
1605
|
+
* @param {*} value 检查值
|
|
1606
|
+
* @returns {boolean} 是否为Number
|
|
1607
|
+
* @example
|
|
1608
|
+
*
|
|
1609
|
+
* isNumber(1)
|
|
1610
|
+
* // => true
|
|
1611
|
+
*
|
|
1612
|
+
* isNumber(Number.MIN_VALUE)
|
|
1613
|
+
* // => true
|
|
1272
1614
|
*
|
|
1273
|
-
*
|
|
1274
|
-
*
|
|
1615
|
+
* isNumber(Infinity)
|
|
1616
|
+
* // => true
|
|
1275
1617
|
*
|
|
1276
|
-
*
|
|
1618
|
+
* isNumber(NaN)
|
|
1619
|
+
* // => true
|
|
1277
1620
|
*
|
|
1621
|
+
* isNumber('1')
|
|
1622
|
+
* // => false
|
|
1278
1623
|
*/
|
|
1279
|
-
function isSwiftCode(value) {
|
|
1280
|
-
const valueStr = normalizeString(value);
|
|
1281
|
-
return reg$1.test(valueStr);
|
|
1282
|
-
}
|
|
1283
1624
|
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
|
|
1625
|
+
function isNumber(value) {
|
|
1626
|
+
return isType(value, 'Number');
|
|
1627
|
+
}
|
|
1288
1628
|
|
|
1289
1629
|
/**
|
|
1290
1630
|
* 参考: https://github.com/nefe/number-precision/blob/master/src/index.ts
|
|
@@ -1292,17 +1632,45 @@
|
|
|
1292
1632
|
* 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
|
|
1293
1633
|
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
|
|
1294
1634
|
*/
|
|
1635
|
+
/**
|
|
1636
|
+
* 值是否为有效的数值
|
|
1637
|
+
*
|
|
1638
|
+
* @param {*} value 待检测的值
|
|
1639
|
+
* @returns {boolean} 是否为有效的数值
|
|
1640
|
+
*/
|
|
1641
|
+
|
|
1642
|
+
function isEffectiveNumeric(value) {
|
|
1643
|
+
if (isNumber(value) && !isNaN(value)) {
|
|
1644
|
+
return true;
|
|
1645
|
+
} // 避免空字符串 或 带空格的字符串
|
|
1295
1646
|
|
|
1647
|
+
|
|
1648
|
+
if (isString(value)) {
|
|
1649
|
+
var fmtStrValue = value.trim(); // 带空格的字符串也不转换数字
|
|
1650
|
+
// Number(' ') => 0
|
|
1651
|
+
|
|
1652
|
+
if (fmtStrValue === value) {
|
|
1653
|
+
var numValue = fmtStrValue ? Number(fmtStrValue) : NaN;
|
|
1654
|
+
|
|
1655
|
+
if (isNumber(numValue) && !isNaN(numValue)) {
|
|
1656
|
+
return true;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
devWarn("".concat(value, " is not a valid number."));
|
|
1662
|
+
return false;
|
|
1663
|
+
}
|
|
1296
1664
|
/**
|
|
1297
1665
|
* 是否为科学计数法数字
|
|
1298
1666
|
*
|
|
1299
1667
|
* @param {string} num 检查值
|
|
1300
1668
|
* @returns {boolean}
|
|
1301
1669
|
*/
|
|
1670
|
+
|
|
1302
1671
|
function isScientificNumber(num) {
|
|
1303
1672
|
return /\d+\.?\d*e[\+\-]*\d+/i.test(num);
|
|
1304
1673
|
}
|
|
1305
|
-
|
|
1306
1674
|
/**
|
|
1307
1675
|
* 把错误的数据转正
|
|
1308
1676
|
*
|
|
@@ -1313,61 +1681,63 @@
|
|
|
1313
1681
|
*
|
|
1314
1682
|
* strip(0.09999999999999998)=0.1
|
|
1315
1683
|
*/
|
|
1316
|
-
|
|
1684
|
+
|
|
1685
|
+
function strip(num) {
|
|
1686
|
+
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 12;
|
|
1317
1687
|
return +parseFloat(num.toPrecision(precision));
|
|
1318
1688
|
}
|
|
1319
|
-
|
|
1320
1689
|
/**
|
|
1321
1690
|
* 计算数字的小数点长度,支持科学记数法
|
|
1322
1691
|
*
|
|
1323
1692
|
* @param {number|string} num 输入数
|
|
1324
1693
|
* @returns {number} 小数点长度
|
|
1325
1694
|
*/
|
|
1695
|
+
|
|
1326
1696
|
function digitLength(num) {
|
|
1327
1697
|
// Get digit length of e
|
|
1328
|
-
|
|
1329
|
-
|
|
1698
|
+
var eSplit = num.toString().split(/e/i);
|
|
1699
|
+
var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
|
|
1330
1700
|
return len > 0 ? len : 0;
|
|
1331
1701
|
}
|
|
1332
|
-
|
|
1333
1702
|
/**
|
|
1334
1703
|
* 把小数转成整数,支持科学计数法。如果是小数则放大成整数
|
|
1335
1704
|
*
|
|
1336
1705
|
* @param {number|string} num 输入数
|
|
1337
1706
|
* @returns {number}
|
|
1338
1707
|
*/
|
|
1708
|
+
|
|
1339
1709
|
function float2Fixed(num) {
|
|
1340
|
-
|
|
1341
|
-
|
|
1710
|
+
var strNum = String(num);
|
|
1711
|
+
|
|
1712
|
+
if (!isScientificNumber(strNum)) {
|
|
1713
|
+
return Number(strNum.replace('.', ''));
|
|
1342
1714
|
}
|
|
1343
|
-
|
|
1715
|
+
|
|
1716
|
+
var dLen = digitLength(num);
|
|
1344
1717
|
return dLen > 0 ? strip(+num * Math.pow(10, dLen)) : +num;
|
|
1345
1718
|
}
|
|
1346
|
-
|
|
1347
1719
|
/**
|
|
1348
1720
|
* 检测数字是否越界,如果越界给出提示
|
|
1349
1721
|
* @param {number} num 输入数
|
|
1350
1722
|
* @returns
|
|
1351
1723
|
*/
|
|
1724
|
+
|
|
1352
1725
|
function checkBoundary(num) {
|
|
1353
1726
|
if (+num > MAX_SAFE_INTEGER || +num < MIN_SAFE_INTEGER) {
|
|
1354
|
-
|
|
1355
|
-
console.warn(`${num} is beyond boundary when transfer to integer, the results may not be accurate`);
|
|
1356
|
-
}
|
|
1727
|
+
devWarn("".concat(num, " is beyond boundary when transfer to integer, the results may not be accurate"));
|
|
1357
1728
|
}
|
|
1358
1729
|
}
|
|
1359
|
-
|
|
1360
1730
|
/**
|
|
1361
1731
|
* 去掉左边数字0
|
|
1362
1732
|
*
|
|
1363
1733
|
* @param {string} num 数字字符串
|
|
1364
1734
|
* @returns {string}
|
|
1365
1735
|
*/
|
|
1366
|
-
function trimLeftZero(num) {
|
|
1367
|
-
const reg = /^([+-])?(0+)([0-9\.]+)$/;
|
|
1368
|
-
const result = reg.exec(num);
|
|
1369
1736
|
|
|
1370
|
-
|
|
1737
|
+
function trimLeftZero(num) {
|
|
1738
|
+
var reg = /^([+-])?(0+)([0-9\.]+)$/;
|
|
1739
|
+
var result = reg.exec(num);
|
|
1740
|
+
var sign;
|
|
1371
1741
|
|
|
1372
1742
|
if (result) {
|
|
1373
1743
|
sign = result[1] || '';
|
|
@@ -1376,7 +1746,6 @@
|
|
|
1376
1746
|
|
|
1377
1747
|
return num;
|
|
1378
1748
|
}
|
|
1379
|
-
|
|
1380
1749
|
/**
|
|
1381
1750
|
* 科学计数法转换成普通数字
|
|
1382
1751
|
*
|
|
@@ -1385,61 +1754,67 @@
|
|
|
1385
1754
|
* 2.小数点前边是0,小数点后十分位(包含十分位)之后连续零的个数大于等于6个
|
|
1386
1755
|
*
|
|
1387
1756
|
* @param {string | number} num 科学计数法数字
|
|
1388
|
-
* @returns {string} 转换后的数字字符串
|
|
1757
|
+
* @returns {string | number} 转换后的数字字符串
|
|
1389
1758
|
*/
|
|
1759
|
+
|
|
1390
1760
|
function scientificToNumber(num) {
|
|
1391
|
-
|
|
1392
|
-
const zero = '0';
|
|
1393
|
-
const parts = String(num).toLowerCase().split('e');
|
|
1394
|
-
const e = parts.pop(); // 存储指数
|
|
1395
|
-
// @ts-ignore
|
|
1396
|
-
const l = Math.abs(e); // 取绝对值,l-1就是0的个数
|
|
1397
|
-
// @ts-ignore
|
|
1398
|
-
const sign = e / l; //判断正负
|
|
1399
|
-
const coeff_array = parts[0].split('.'); // 将系数按照小数点拆分
|
|
1761
|
+
var strNum = String(num);
|
|
1400
1762
|
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
} else {
|
|
1406
|
-
const dec = coeff_array[1];
|
|
1763
|
+
if (!isScientificNumber(strNum)) {
|
|
1764
|
+
return num;
|
|
1765
|
+
}
|
|
1766
|
+
/** @type string */
|
|
1407
1767
|
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1768
|
+
|
|
1769
|
+
var ret;
|
|
1770
|
+
var zero = '0';
|
|
1771
|
+
var parts = strNum.toLowerCase().split('e');
|
|
1772
|
+
var e = parts.pop(); // 存储指数
|
|
1773
|
+
// @ts-ignore
|
|
1774
|
+
|
|
1775
|
+
var l = Math.abs(e); // 取绝对值,l-1就是0的个数
|
|
1776
|
+
// @ts-ignore
|
|
1777
|
+
|
|
1778
|
+
var sign = e / l; //判断正负
|
|
1779
|
+
|
|
1780
|
+
var coeff_array = parts[0].split('.'); // 将系数按照小数点拆分
|
|
1781
|
+
// 如果是小数
|
|
1782
|
+
|
|
1783
|
+
if (sign === -1) {
|
|
1784
|
+
// 整数部分
|
|
1785
|
+
var intVal = trimLeftZero(coeff_array[0]); // 整数部分大于科学计数后面部分
|
|
1786
|
+
// 如: 10e-1, 10.2e-1
|
|
1787
|
+
|
|
1788
|
+
if (intVal.length > l) {
|
|
1789
|
+
var thanLen = intVal.length - l;
|
|
1790
|
+
var dec = coeff_array[1] || '';
|
|
1791
|
+
ret = intVal.slice(0, thanLen); // 处理 10e-1, 100e-1
|
|
1792
|
+
|
|
1793
|
+
if (intVal.slice(thanLen) !== '0' || dec) {
|
|
1794
|
+
ret += '.' + intVal.slice(thanLen) + dec;
|
|
1414
1795
|
}
|
|
1796
|
+
} else {
|
|
1797
|
+
// 整数部分小于等于科学计数后面部分
|
|
1798
|
+
// 如: 1e-1, 0.2e-1, 1.2e-2, 1.2e-1
|
|
1799
|
+
ret = zero + '.' + new Array(l - intVal.length + 1).join(zero) + coeff_array.join('');
|
|
1800
|
+
}
|
|
1801
|
+
} else {
|
|
1802
|
+
// 小数部分
|
|
1803
|
+
var _dec = coeff_array[1] || ''; // 如果是整数,将整数除第一位之外的非零数字计入位数,相应的减少0的个数
|
|
1804
|
+
|
|
1805
|
+
|
|
1806
|
+
if (l - _dec.length < 0) {
|
|
1807
|
+
ret = trimLeftZero(coeff_array[0] + _dec.substring(0, l)) + '.' + _dec.substring(l);
|
|
1808
|
+
} else {
|
|
1809
|
+
// 拼接字符串,如果是整数,不需要拼接小数点
|
|
1810
|
+
ret = coeff_array.join('') + new Array(l - _dec.length + 1).join(zero);
|
|
1415
1811
|
}
|
|
1416
1812
|
}
|
|
1417
|
-
// @ts-ignore
|
|
1418
|
-
return num;
|
|
1419
|
-
}
|
|
1420
1813
|
|
|
1421
|
-
|
|
1422
|
-
* 检查值是否为NaN
|
|
1423
|
-
*
|
|
1424
|
-
* @static
|
|
1425
|
-
* @alias module:Type.isNaN
|
|
1426
|
-
* @since 1.1.0
|
|
1427
|
-
* @param {*} value 检查值
|
|
1428
|
-
* @returns {boolean} 是否为NaN
|
|
1429
|
-
* @example
|
|
1430
|
-
*
|
|
1431
|
-
* isNaN(NaN)
|
|
1432
|
-
* // => true
|
|
1433
|
-
*
|
|
1434
|
-
* isNaN(1)
|
|
1435
|
-
* // => false
|
|
1436
|
-
*/
|
|
1437
|
-
function _isNaN(value) {
|
|
1438
|
-
return isType(value, 'Number') && isNaN(value);
|
|
1814
|
+
return trimLeftZero(ret);
|
|
1439
1815
|
}
|
|
1440
1816
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1817
|
+
var reg = /^[+-]?\d*\.?\d*$/;
|
|
1443
1818
|
/**
|
|
1444
1819
|
* 检查数字或数字字符串
|
|
1445
1820
|
*
|
|
@@ -1447,24 +1822,21 @@
|
|
|
1447
1822
|
* @param {string} num
|
|
1448
1823
|
* @returns 是否为数字
|
|
1449
1824
|
*/
|
|
1450
|
-
function checkNumber(num) {
|
|
1451
|
-
if (!(reg.test(num) || isScientificNumber(num)) || _isNaN(num) || (typeof num !== 'number' && typeof num !== 'string') || num === '') {
|
|
1452
|
-
if (!config.disableWarning) {
|
|
1453
|
-
console.warn(`${num} invalid parameter.`);
|
|
1454
|
-
}
|
|
1455
1825
|
|
|
1826
|
+
function checkNumber(num) {
|
|
1827
|
+
if (!(reg.test(num) || isScientificNumber(num)) || _isNaN(num) || typeof num !== 'number' && typeof num !== 'string' || num === '') {
|
|
1828
|
+
devWarn("".concat(num, " invalid parameter."));
|
|
1456
1829
|
return false;
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
// 数字超限如果不是是字符串,可能有异常
|
|
1830
|
+
} // 数字超限如果不是是字符串,可能有异常
|
|
1460
1831
|
// 如 1111111111111111111111 // => 1.1111111111111111e+21
|
|
1832
|
+
|
|
1833
|
+
|
|
1461
1834
|
if (typeof num === 'number') {
|
|
1462
1835
|
checkBoundary(num);
|
|
1463
1836
|
}
|
|
1464
1837
|
|
|
1465
1838
|
return true;
|
|
1466
1839
|
}
|
|
1467
|
-
|
|
1468
1840
|
/**
|
|
1469
1841
|
* 格式化整数部分
|
|
1470
1842
|
*
|
|
@@ -1473,20 +1845,22 @@
|
|
|
1473
1845
|
* @param {string} thousand 千分位符号
|
|
1474
1846
|
* @returns 格式化后的值
|
|
1475
1847
|
*/
|
|
1848
|
+
|
|
1849
|
+
|
|
1476
1850
|
function formatInt(intStr, thousand) {
|
|
1477
|
-
|
|
1851
|
+
var txt = '';
|
|
1478
1852
|
intStr = trimLeftZero(intStr);
|
|
1479
1853
|
intStr = intStr[0] === '+' ? intStr.substring(1) : intStr; // 去掉+符号
|
|
1480
|
-
const negativeSymbol = Number(intStr) < 0 ? '-' : '';
|
|
1481
|
-
const reArr = negativeSymbol ? intStr.substring(1).split('').reverse() : intStr.split('').reverse();
|
|
1482
1854
|
|
|
1483
|
-
|
|
1855
|
+
var negativeSymbol = Number(intStr) < 0 ? '-' : '';
|
|
1856
|
+
var reArr = negativeSymbol ? intStr.substring(1).split('').reverse() : intStr.split('').reverse();
|
|
1857
|
+
|
|
1858
|
+
for (var i = 0; i < reArr.length; i++) {
|
|
1484
1859
|
txt += reArr[i] + ((i + 1) % 3 === 0 && i + 1 !== reArr.length ? thousand : '');
|
|
1485
1860
|
}
|
|
1486
1861
|
|
|
1487
1862
|
return negativeSymbol + txt.split('').reverse().join('');
|
|
1488
1863
|
}
|
|
1489
|
-
|
|
1490
1864
|
/**
|
|
1491
1865
|
* 格式化小数部分,如果使用 toFixed,超大额数字会自动被截断
|
|
1492
1866
|
*
|
|
@@ -1496,16 +1870,18 @@
|
|
|
1496
1870
|
* @param {string} decimal 小数点符号
|
|
1497
1871
|
* @returns 格式化后的值
|
|
1498
1872
|
*/
|
|
1873
|
+
|
|
1874
|
+
|
|
1499
1875
|
function formatDec(decStr, precision, decimal) {
|
|
1500
1876
|
if (precision === 0) {
|
|
1501
1877
|
return '';
|
|
1502
1878
|
}
|
|
1503
1879
|
|
|
1504
|
-
|
|
1505
|
-
|
|
1880
|
+
var zero = 0;
|
|
1881
|
+
var ret = '';
|
|
1506
1882
|
|
|
1507
1883
|
if (decStr && Number(decStr) > 0) {
|
|
1508
|
-
|
|
1884
|
+
var tmpNum = parseFloat('0.' + decStr);
|
|
1509
1885
|
ret = tmpNum.toFixed(precision).substring(2);
|
|
1510
1886
|
} else {
|
|
1511
1887
|
ret = zero.toFixed(precision).substring(2);
|
|
@@ -1513,7 +1889,6 @@
|
|
|
1513
1889
|
|
|
1514
1890
|
return decimal + ret;
|
|
1515
1891
|
}
|
|
1516
|
-
|
|
1517
1892
|
/**
|
|
1518
1893
|
* 格式化金额
|
|
1519
1894
|
*
|
|
@@ -1557,27 +1932,41 @@
|
|
|
1557
1932
|
* formatMoney(1000.00, { decimal: '&' });
|
|
1558
1933
|
* // => 1,000&00
|
|
1559
1934
|
*/
|
|
1560
|
-
|
|
1935
|
+
|
|
1936
|
+
|
|
1937
|
+
var formatMoney = function formatMoney(num) {
|
|
1938
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1939
|
+
_ref$precision = _ref.precision,
|
|
1940
|
+
precision = _ref$precision === void 0 ? 2 : _ref$precision,
|
|
1941
|
+
symbol = _ref.symbol,
|
|
1942
|
+
_ref$thousand = _ref.thousand,
|
|
1943
|
+
thousand = _ref$thousand === void 0 ? ',' : _ref$thousand,
|
|
1944
|
+
_ref$decimal = _ref.decimal,
|
|
1945
|
+
decimal = _ref$decimal === void 0 ? '.' : _ref$decimal;
|
|
1946
|
+
|
|
1561
1947
|
// 数字参数不正确,返回空字符串
|
|
1562
1948
|
// @ts-ignore
|
|
1563
1949
|
if (!checkNumber(num)) {
|
|
1564
1950
|
return '';
|
|
1565
|
-
}
|
|
1951
|
+
} // 参数规整化
|
|
1952
|
+
|
|
1566
1953
|
|
|
1567
|
-
// 参数规整化
|
|
1568
1954
|
if (typeof precision !== 'number' || _isNaN(precision) || precision < 0) {
|
|
1569
1955
|
precision = 2;
|
|
1570
1956
|
} else if (precision > 10) {
|
|
1571
1957
|
precision = 10;
|
|
1572
1958
|
}
|
|
1959
|
+
|
|
1573
1960
|
symbol = typeof symbol === 'string' ? symbol : '';
|
|
1574
1961
|
thousand = typeof thousand === 'string' ? thousand : ',';
|
|
1575
|
-
decimal = typeof decimal === 'string' ? decimal : '.';
|
|
1962
|
+
decimal = typeof decimal === 'string' ? decimal : '.'; // 转换数字字符串,支持科学记数法
|
|
1963
|
+
|
|
1964
|
+
var strNum = scientificToNumber(num) + ''; // 整数和小数部分
|
|
1576
1965
|
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1966
|
+
var _strNum$split = strNum.split('.'),
|
|
1967
|
+
_strNum$split2 = _slicedToArray(_strNum$split, 2),
|
|
1968
|
+
intStr = _strNum$split2[0],
|
|
1969
|
+
decStr = _strNum$split2[1];
|
|
1581
1970
|
|
|
1582
1971
|
return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
|
|
1583
1972
|
};
|
|
@@ -1612,13 +2001,20 @@
|
|
|
1612
2001
|
* // => 6228-4804-0256-4890
|
|
1613
2002
|
*
|
|
1614
2003
|
*/
|
|
1615
|
-
function formatBankCard(bankCardNo = '', { char = ' ', length = 4 } = {}) {
|
|
1616
|
-
const reg = new RegExp(`(.{${length}})`, 'g');
|
|
1617
|
-
const regChar = new RegExp(`${char}`, 'g');
|
|
1618
2004
|
|
|
1619
|
-
|
|
1620
|
-
|
|
2005
|
+
function formatBankCard() {
|
|
2006
|
+
var bankCardNo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
1621
2007
|
|
|
2008
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
2009
|
+
_ref$char = _ref["char"],
|
|
2010
|
+
_char = _ref$char === void 0 ? ' ' : _ref$char,
|
|
2011
|
+
_ref$length = _ref.length,
|
|
2012
|
+
length = _ref$length === void 0 ? 4 : _ref$length;
|
|
2013
|
+
|
|
2014
|
+
var reg = new RegExp("(.{".concat(length, "})"), 'g');
|
|
2015
|
+
var regChar = new RegExp("".concat(_char), 'g');
|
|
2016
|
+
var realValue = normalizeString(bankCardNo).replace(regChar, '');
|
|
2017
|
+
var str = realValue.replace(reg, "$1".concat(_char));
|
|
1622
2018
|
return realValue.length % length === 0 ? str.substring(0, str.length - 1) : str;
|
|
1623
2019
|
}
|
|
1624
2020
|
|
|
@@ -1668,63 +2064,69 @@
|
|
|
1668
2064
|
* // => 林**
|
|
1669
2065
|
*
|
|
1670
2066
|
*/
|
|
1671
|
-
function replaceChar(str = '', { start = 3, end = -4, char = '*', repeat, exclude } = {}) {
|
|
1672
|
-
const strLen = str.length;
|
|
1673
2067
|
|
|
1674
|
-
|
|
2068
|
+
function replaceChar(str) {
|
|
2069
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
2070
|
+
_ref$start = _ref.start,
|
|
2071
|
+
start = _ref$start === void 0 ? 3 : _ref$start,
|
|
2072
|
+
_ref$end = _ref.end,
|
|
2073
|
+
end = _ref$end === void 0 ? -4 : _ref$end,
|
|
2074
|
+
_ref$char = _ref["char"],
|
|
2075
|
+
_char = _ref$char === void 0 ? '*' : _ref$char,
|
|
2076
|
+
repeat = _ref.repeat,
|
|
2077
|
+
exclude = _ref.exclude;
|
|
2078
|
+
|
|
2079
|
+
var realStr = normalizeString(str);
|
|
2080
|
+
var strLen = realStr.length; // 开始位置超过str长度
|
|
2081
|
+
|
|
1675
2082
|
if (Math.abs(start) >= strLen) {
|
|
1676
|
-
return
|
|
2083
|
+
return realStr;
|
|
1677
2084
|
}
|
|
1678
2085
|
|
|
1679
2086
|
start = start >= 0 ? start : strLen + start;
|
|
1680
|
-
end = end >= 0 ? end : strLen + end;
|
|
2087
|
+
end = end >= 0 ? end : strLen + end; // 开始位置大于结束位置
|
|
1681
2088
|
|
|
1682
|
-
// 开始位置大于结束位置
|
|
1683
2089
|
if (start >= end) {
|
|
1684
|
-
return
|
|
2090
|
+
return realStr;
|
|
1685
2091
|
}
|
|
1686
2092
|
|
|
1687
|
-
|
|
2093
|
+
var middleStr = realStr.substring(start, end);
|
|
1688
2094
|
|
|
1689
2095
|
if (exclude) {
|
|
1690
|
-
|
|
1691
|
-
middleStr = middleStr.replace(reg,
|
|
2096
|
+
var reg = new RegExp("[^".concat(exclude, "]"), 'g');
|
|
2097
|
+
middleStr = middleStr.replace(reg, _char);
|
|
1692
2098
|
} else {
|
|
1693
2099
|
repeat = typeof repeat === 'number' && repeat >= 0 ? repeat : middleStr.length;
|
|
1694
|
-
middleStr =
|
|
2100
|
+
middleStr = _char.repeat(repeat);
|
|
1695
2101
|
}
|
|
1696
2102
|
|
|
1697
|
-
return
|
|
2103
|
+
return realStr.substring(0, start) + middleStr + realStr.substring(end);
|
|
1698
2104
|
}
|
|
1699
2105
|
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
const chnUnitChar = ['', '十', '百', '千'];
|
|
1703
|
-
|
|
1704
|
-
// 繁体
|
|
1705
|
-
const big5NumberChar = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
1706
|
-
const big5UnitChar = ['', '拾', '佰', '仟'];
|
|
2106
|
+
var chnNumberChar = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
|
|
2107
|
+
var chnUnitChar = ['', '十', '百', '千']; // 繁体
|
|
1707
2108
|
|
|
1708
|
-
|
|
2109
|
+
var big5NumberChar = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
2110
|
+
var big5UnitChar = ['', '拾', '佰', '仟']; // 数字字符、计数单位
|
|
1709
2111
|
|
|
1710
2112
|
/**
|
|
1711
2113
|
* @type {string[]}
|
|
1712
2114
|
* @private
|
|
1713
2115
|
*/
|
|
1714
|
-
let numberChar;
|
|
1715
2116
|
|
|
2117
|
+
var numberChar;
|
|
1716
2118
|
/**
|
|
1717
2119
|
* @type {string[]}
|
|
1718
2120
|
* @private
|
|
1719
2121
|
*/
|
|
1720
|
-
let unitChar;
|
|
1721
2122
|
|
|
2123
|
+
var unitChar;
|
|
1722
2124
|
/**
|
|
1723
2125
|
* @type {string[]}
|
|
1724
2126
|
* @private
|
|
1725
2127
|
*/
|
|
1726
|
-
let unitSection;
|
|
1727
2128
|
|
|
2129
|
+
var unitSection;
|
|
1728
2130
|
/**
|
|
1729
2131
|
* 每个小节的内部进行转化
|
|
1730
2132
|
*
|
|
@@ -1732,17 +2134,18 @@
|
|
|
1732
2134
|
* @param {number} section 数字
|
|
1733
2135
|
* @returns {string} 转化的数字
|
|
1734
2136
|
*/
|
|
2137
|
+
|
|
1735
2138
|
function sectionToChinese(section) {
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
2139
|
+
var str = '';
|
|
2140
|
+
var chnstr = '';
|
|
2141
|
+
var zero = false; //zero为是否进行补零, 第一次进行取余由于为个位数,默认不补零
|
|
2142
|
+
|
|
2143
|
+
var unitPos = 0;
|
|
1740
2144
|
|
|
1741
2145
|
while (section > 0) {
|
|
1742
2146
|
// 对数字取余10,得到的数即为个位数
|
|
1743
|
-
|
|
2147
|
+
var v = section % 10; //如果数字为零,则对字符串进行补零
|
|
1744
2148
|
|
|
1745
|
-
//如果数字为零,则对字符串进行补零
|
|
1746
2149
|
if (v == 0) {
|
|
1747
2150
|
if (zero) {
|
|
1748
2151
|
//如果遇到连续多次取余都是0,那么只需补一个零即可
|
|
@@ -1756,12 +2159,13 @@
|
|
|
1756
2159
|
str += unitChar[unitPos];
|
|
1757
2160
|
chnstr = str + chnstr;
|
|
1758
2161
|
}
|
|
2162
|
+
|
|
1759
2163
|
unitPos++;
|
|
1760
2164
|
section = Math.floor(section / 10);
|
|
1761
2165
|
}
|
|
2166
|
+
|
|
1762
2167
|
return chnstr;
|
|
1763
2168
|
}
|
|
1764
|
-
|
|
1765
2169
|
/**
|
|
1766
2170
|
* 转换整数
|
|
1767
2171
|
*
|
|
@@ -1769,52 +2173,56 @@
|
|
|
1769
2173
|
* @param {number} num 要转换的数字
|
|
1770
2174
|
* @returns {string} 中文数字
|
|
1771
2175
|
*/
|
|
1772
|
-
function convertInteger(num) {
|
|
1773
|
-
num = Math.floor(num);
|
|
1774
2176
|
|
|
1775
|
-
let unitPos = 0;
|
|
1776
|
-
let strIns = '',
|
|
1777
|
-
chnStr = '';
|
|
1778
|
-
let needZero = false;
|
|
1779
2177
|
|
|
1780
|
-
|
|
2178
|
+
function convertInteger(num) {
|
|
2179
|
+
var numInt = Math.floor(num);
|
|
2180
|
+
var unitPos = 0;
|
|
2181
|
+
var strIns = '';
|
|
2182
|
+
var chnStr = '';
|
|
2183
|
+
var needZero = false;
|
|
2184
|
+
|
|
2185
|
+
if (numInt === 0) {
|
|
1781
2186
|
return numberChar[0];
|
|
1782
2187
|
}
|
|
1783
|
-
|
|
1784
|
-
|
|
2188
|
+
|
|
2189
|
+
while (numInt > 0) {
|
|
2190
|
+
var section = numInt % 10000;
|
|
2191
|
+
|
|
1785
2192
|
if (needZero) {
|
|
1786
2193
|
chnStr = numberChar[0] + chnStr;
|
|
1787
2194
|
}
|
|
2195
|
+
|
|
1788
2196
|
strIns = sectionToChinese(section);
|
|
1789
2197
|
strIns += section !== 0 ? unitSection[unitPos] : unitSection[0];
|
|
1790
2198
|
chnStr = strIns + chnStr;
|
|
1791
2199
|
needZero = section < 1000 && section > 0;
|
|
1792
|
-
|
|
2200
|
+
numInt = Math.floor(numInt / 10000);
|
|
1793
2201
|
unitPos++;
|
|
1794
2202
|
}
|
|
2203
|
+
|
|
1795
2204
|
return chnStr;
|
|
1796
2205
|
}
|
|
1797
|
-
|
|
1798
2206
|
/**
|
|
1799
2207
|
* 转换小数
|
|
1800
2208
|
*
|
|
1801
2209
|
* @private
|
|
1802
2210
|
* @param {number} num 要转换的数字
|
|
1803
2211
|
*/
|
|
1804
|
-
function convertDecimal(num) {
|
|
1805
|
-
const numStr = num + '';
|
|
1806
|
-
const index = numStr.indexOf('.');
|
|
1807
2212
|
|
|
1808
|
-
|
|
2213
|
+
|
|
2214
|
+
function convertDecimal(num) {
|
|
2215
|
+
var strNum = num + '';
|
|
2216
|
+
var index = strNum.indexOf('.');
|
|
2217
|
+
var ret = '';
|
|
1809
2218
|
|
|
1810
2219
|
if (index > -1) {
|
|
1811
|
-
|
|
2220
|
+
var decimalStr = strNum.slice(index + 1);
|
|
1812
2221
|
ret = mapNumberChar(parseInt(decimalStr));
|
|
1813
2222
|
}
|
|
1814
2223
|
|
|
1815
2224
|
return ret;
|
|
1816
2225
|
}
|
|
1817
|
-
|
|
1818
2226
|
/**
|
|
1819
2227
|
* 映射为中文数字
|
|
1820
2228
|
*
|
|
@@ -1822,17 +2230,18 @@
|
|
|
1822
2230
|
* @param {number} num 要处理的数字
|
|
1823
2231
|
* @returns {string} 返回中文数字的映射
|
|
1824
2232
|
*/
|
|
2233
|
+
|
|
2234
|
+
|
|
1825
2235
|
function mapNumberChar(num) {
|
|
1826
|
-
|
|
1827
|
-
|
|
2236
|
+
var strNum = num + '';
|
|
2237
|
+
var ret = '';
|
|
1828
2238
|
|
|
1829
|
-
for (
|
|
1830
|
-
ret += numberChar[parseInt(
|
|
2239
|
+
for (var i = 0, len = strNum.length; i < len; i++) {
|
|
2240
|
+
ret += numberChar[parseInt(strNum[i])];
|
|
1831
2241
|
}
|
|
1832
2242
|
|
|
1833
2243
|
return ret;
|
|
1834
2244
|
}
|
|
1835
|
-
|
|
1836
2245
|
/**
|
|
1837
2246
|
* 数字转中文数字
|
|
1838
2247
|
* 不在安全数字 -9007199254740991~9007199254740991 内,处理会有异常
|
|
@@ -1878,68 +2287,65 @@
|
|
|
1878
2287
|
* // => 一九九〇
|
|
1879
2288
|
*
|
|
1880
2289
|
*/
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
2290
|
+
|
|
2291
|
+
|
|
2292
|
+
function numberToChinese(num) {
|
|
2293
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
2294
|
+
_ref$big = _ref.big5,
|
|
2295
|
+
big5 = _ref$big === void 0 ? false : _ref$big,
|
|
2296
|
+
_ref$unit = _ref.unit,
|
|
2297
|
+
unit = _ref$unit === void 0 ? true : _ref$unit,
|
|
2298
|
+
_ref$decimal = _ref.decimal,
|
|
2299
|
+
decimal = _ref$decimal === void 0 ? '点' : _ref$decimal,
|
|
2300
|
+
_ref$zero = _ref.zero,
|
|
2301
|
+
zero = _ref$zero === void 0 ? '' : _ref$zero,
|
|
2302
|
+
_ref$negative = _ref.negative,
|
|
2303
|
+
negative = _ref$negative === void 0 ? '负' : _ref$negative,
|
|
2304
|
+
_ref$unitConfig = _ref.unitConfig,
|
|
2305
|
+
unitConfig = _ref$unitConfig === void 0 ? {} : _ref$unitConfig;
|
|
2306
|
+
|
|
1895
2307
|
// 非数字 或 NaN 不处理
|
|
1896
2308
|
if (typeof num !== 'number' || isNaN(num)) {
|
|
1897
|
-
|
|
1898
|
-
console.warn(`参数错误 ${num},请传入数字`);
|
|
1899
|
-
}
|
|
1900
|
-
|
|
2309
|
+
devWarn("\u53C2\u6570\u9519\u8BEF ".concat(num, "\uFF0C\u8BF7\u4F20\u5165\u6570\u5B57"));
|
|
1901
2310
|
return '';
|
|
1902
|
-
}
|
|
2311
|
+
} // 超过安全数字提示
|
|
2312
|
+
|
|
1903
2313
|
|
|
1904
|
-
//
|
|
1905
|
-
checkBoundary(num);
|
|
2314
|
+
checkBoundary(num); // 设置数字字符和计数单位
|
|
1906
2315
|
|
|
1907
|
-
// 设置数字字符和计数单位
|
|
1908
2316
|
if (big5) {
|
|
1909
2317
|
numberChar = big5NumberChar.slice();
|
|
1910
2318
|
unitChar = big5UnitChar.slice();
|
|
1911
2319
|
} else {
|
|
1912
2320
|
numberChar = chnNumberChar.slice();
|
|
1913
2321
|
unitChar = chnUnitChar.slice();
|
|
1914
|
-
}
|
|
2322
|
+
} // 设置节点计数单位,万、亿、万亿
|
|
2323
|
+
|
|
1915
2324
|
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
unitSection = ['',
|
|
2325
|
+
var unitWan = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.w) || '万';
|
|
2326
|
+
var unitYi = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.y) || '亿';
|
|
2327
|
+
var unitWanYi = unitWan + unitYi;
|
|
2328
|
+
unitSection = ['', unitWan, unitYi, unitWanYi]; // 设置0
|
|
1920
2329
|
|
|
1921
|
-
// 设置0
|
|
1922
2330
|
if (zero) {
|
|
1923
2331
|
numberChar[0] = zero;
|
|
1924
|
-
}
|
|
2332
|
+
} // 前置字符,负数处理
|
|
2333
|
+
|
|
1925
2334
|
|
|
1926
|
-
//
|
|
1927
|
-
const preStr = num < 0 ? negative : '';
|
|
2335
|
+
var preStr = num < 0 ? negative : ''; // 整数和小数
|
|
1928
2336
|
|
|
1929
|
-
|
|
1930
|
-
|
|
2337
|
+
var chnInteger, chnDecimal;
|
|
2338
|
+
var numAbs = Math.abs(num); // 处理整数
|
|
1931
2339
|
|
|
1932
|
-
// 处理整数
|
|
1933
2340
|
if (unit) {
|
|
1934
|
-
chnInteger = convertInteger(
|
|
2341
|
+
chnInteger = convertInteger(numAbs);
|
|
1935
2342
|
} else {
|
|
1936
|
-
chnInteger = mapNumberChar(Math.floor(
|
|
1937
|
-
}
|
|
2343
|
+
chnInteger = mapNumberChar(Math.floor(numAbs));
|
|
2344
|
+
} // 处理小数
|
|
1938
2345
|
|
|
1939
|
-
// 处理小数
|
|
1940
|
-
chnDecimal = convertDecimal(num);
|
|
1941
2346
|
|
|
1942
|
-
|
|
2347
|
+
chnDecimal = convertDecimal(numAbs);
|
|
2348
|
+
return chnDecimal ? "".concat(preStr).concat(chnInteger).concat(decimal).concat(chnDecimal) : "".concat(preStr).concat(chnInteger);
|
|
1943
2349
|
}
|
|
1944
2350
|
|
|
1945
2351
|
/**
|
|
@@ -1965,74 +2371,36 @@
|
|
|
1965
2371
|
* // => 1 GB
|
|
1966
2372
|
*/
|
|
1967
2373
|
function bytesToSize(bytes) {
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
// 存储单位
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
return sizes[i] ?
|
|
1975
|
-
}
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
['36', '江西省'],
|
|
1999
|
-
['37', '山东省'],
|
|
2000
|
-
|
|
2001
|
-
// 华中地区: 河南省|410000,湖北省|420000,湖南省|430000
|
|
2002
|
-
['41', '河南省'],
|
|
2003
|
-
['42', '湖北省'],
|
|
2004
|
-
['43', '湖南省'],
|
|
2005
|
-
|
|
2006
|
-
// 华南地区:广东省|440000,广西壮族自治区|450000,海南省|460000
|
|
2007
|
-
['44', '广东省'],
|
|
2008
|
-
['45', '广西壮族自治区'],
|
|
2009
|
-
['46', '海南省'],
|
|
2010
|
-
|
|
2011
|
-
// 西南地区:重庆市|500000,四川省|510000,贵州省|520000,云南省|530000,西藏自治区|540000
|
|
2012
|
-
['50', '重庆市'],
|
|
2013
|
-
['51', '四川省'],
|
|
2014
|
-
['52', '贵州省'],
|
|
2015
|
-
['53', '云南省'],
|
|
2016
|
-
['54', '西藏自治区'],
|
|
2017
|
-
|
|
2018
|
-
// 西北地区: 陕西省|610000,甘肃省|620000,青海省|630000,宁夏回族自治区|640000,新疆维吾尔自治区|650000
|
|
2019
|
-
['61', '陕西省'],
|
|
2020
|
-
['62', '甘肃省'],
|
|
2021
|
-
['63', '青海省'],
|
|
2022
|
-
['64', '宁夏回族自治区'],
|
|
2023
|
-
['65', '新疆维吾尔自治区'],
|
|
2024
|
-
|
|
2025
|
-
// 台湾地区:台湾省|710000
|
|
2026
|
-
// 台湾居民公民身份号码地址码为830000,参考 http://www.wanweibaike.com/wiki-中华人民共和国行政区划代码_(7区)、https://zh.wikipedia.org/wiki/港澳台居民居住证
|
|
2027
|
-
['71', '台湾省'],
|
|
2028
|
-
['83', '台湾省'],
|
|
2029
|
-
|
|
2030
|
-
// 港澳地区:香港特别行政区|810000,澳门特别行政区|820000
|
|
2031
|
-
['81', '香港特别行政区'],
|
|
2032
|
-
['82', '澳门特别行政区']
|
|
2033
|
-
];
|
|
2034
|
-
|
|
2035
|
-
// 第一位数字是以前的大区制代码。第二位是大区所在省市编码。全国共分为8个大区:华北(1)、东北(2)、华东(3)、中南(4)、西南(5)、西北(6)、台湾(7)和港澳(8)。
|
|
2374
|
+
var numBytes = typeof bytes !== 'number' ? Number(bytes) : bytes;
|
|
2375
|
+
if (numBytes === 0 || isNaN(numBytes)) return '0 B';
|
|
2376
|
+
var k = 1024; // 存储单位
|
|
2377
|
+
|
|
2378
|
+
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
2379
|
+
var i = Math.floor(Math.log(numBytes) / Math.log(k));
|
|
2380
|
+
return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(2)), " ").concat(sizes[i]) : numBytes + '';
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
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, {
|
|
2384
|
+
province: 1,
|
|
2385
|
+
city: 2,
|
|
2386
|
+
area: 3,
|
|
2387
|
+
year: 4,
|
|
2388
|
+
month: 5,
|
|
2389
|
+
day: 6,
|
|
2390
|
+
gender: 7
|
|
2391
|
+
});
|
|
2392
|
+
|
|
2393
|
+
var Provinces = [// 华北地区:北京市|110000,天津市|120000,河北省|130000,山西省|140000,内蒙古自治区|150000
|
|
2394
|
+
['11', '北京市'], ['12', '天津市'], ['13', '河北省'], ['14', '山西省'], ['15', '内蒙古自治区'], // 东北地区: 辽宁省|210000,吉林省|220000,黑龙江省|230000
|
|
2395
|
+
['21', '辽宁省'], ['22', '吉林省'], ['23', '黑龙江省'], // 华东地区: 上海市|310000,江苏省|320000,浙江省|330000,安徽省|340000,福建省|350000,江西省|360000,山东省|370000
|
|
2396
|
+
['31', '上海市'], ['32', '江苏省'], ['33', '浙江省'], ['34', '安徽省'], ['35', '福建省'], ['36', '江西省'], ['37', '山东省'], // 华中地区: 河南省|410000,湖北省|420000,湖南省|430000
|
|
2397
|
+
['41', '河南省'], ['42', '湖北省'], ['43', '湖南省'], // 华南地区:广东省|440000,广西壮族自治区|450000,海南省|460000
|
|
2398
|
+
['44', '广东省'], ['45', '广西壮族自治区'], ['46', '海南省'], // 西南地区:重庆市|500000,四川省|510000,贵州省|520000,云南省|530000,西藏自治区|540000
|
|
2399
|
+
['50', '重庆市'], ['51', '四川省'], ['52', '贵州省'], ['53', '云南省'], ['54', '西藏自治区'], // 西北地区: 陕西省|610000,甘肃省|620000,青海省|630000,宁夏回族自治区|640000,新疆维吾尔自治区|650000
|
|
2400
|
+
['61', '陕西省'], ['62', '甘肃省'], ['63', '青海省'], ['64', '宁夏回族自治区'], ['65', '新疆维吾尔自治区'], // 台湾地区:台湾省|710000
|
|
2401
|
+
// 台湾居民公民身份号码地址码为830000,参考 http://www.wanweibaike.com/wiki-中华人民共和国行政区划代码_(7区)、https://zh.wikipedia.org/wiki/港澳台居民居住证
|
|
2402
|
+
['71', '台湾省'], ['83', '台湾省'], // 港澳地区:香港特别行政区|810000,澳门特别行政区|820000
|
|
2403
|
+
['81', '香港特别行政区'], ['82', '澳门特别行政区']]; // 第一位数字是以前的大区制代码。第二位是大区所在省市编码。全国共分为8个大区:华北(1)、东北(2)、华东(3)、中南(4)、西南(5)、西北(6)、台湾(7)和港澳(8)。
|
|
2036
2404
|
// const Regions = [
|
|
2037
2405
|
// ['1', '华北地区'],
|
|
2038
2406
|
// ['2', '东北地区'],
|
|
@@ -2097,62 +2465,52 @@
|
|
|
2097
2465
|
* }
|
|
2098
2466
|
*
|
|
2099
2467
|
*/
|
|
2468
|
+
|
|
2100
2469
|
function parseIdCard(id) {
|
|
2101
|
-
if (!isIdCard(id, {
|
|
2470
|
+
if (!isIdCard(id, {
|
|
2471
|
+
loose: true
|
|
2472
|
+
})) {
|
|
2102
2473
|
return null;
|
|
2103
2474
|
}
|
|
2104
2475
|
|
|
2105
|
-
|
|
2476
|
+
var info = regIdCard.exec(id);
|
|
2106
2477
|
|
|
2107
2478
|
if (!info) {
|
|
2108
2479
|
return null;
|
|
2109
2480
|
}
|
|
2110
|
-
|
|
2111
2481
|
/**
|
|
2112
2482
|
* @type {{ province: string, city: string, area: string, year: string, month: string, day: string, gender: string }}
|
|
2113
2483
|
*
|
|
2114
2484
|
*/
|
|
2115
|
-
|
|
2116
|
-
province: '',
|
|
2117
|
-
city: '',
|
|
2118
|
-
area: '',
|
|
2119
|
-
year: '',
|
|
2120
|
-
month: '',
|
|
2121
|
-
day: '',
|
|
2122
|
-
gender: ''
|
|
2123
|
-
};
|
|
2485
|
+
// @ts-ignore
|
|
2124
2486
|
|
|
2125
|
-
if (info.groups) {
|
|
2126
|
-
// @ts-ignore
|
|
2127
|
-
origin = info.groups;
|
|
2128
|
-
} else {
|
|
2129
|
-
origin = {
|
|
2130
|
-
province: info[1],
|
|
2131
|
-
city: info[2],
|
|
2132
|
-
area: info[3],
|
|
2133
|
-
year: info[4],
|
|
2134
|
-
month: info[5],
|
|
2135
|
-
day: info[6],
|
|
2136
|
-
gender: info[7]
|
|
2137
|
-
};
|
|
2138
|
-
}
|
|
2139
2487
|
|
|
2140
|
-
|
|
2488
|
+
var origin = (info === null || info === void 0 ? void 0 : info.groups) || {
|
|
2489
|
+
province: info[1],
|
|
2490
|
+
city: info[2],
|
|
2491
|
+
area: info[3],
|
|
2492
|
+
year: info[4],
|
|
2493
|
+
month: info[5],
|
|
2494
|
+
day: info[6],
|
|
2495
|
+
gender: info[7]
|
|
2496
|
+
};
|
|
2497
|
+
var province = Provinces.find(function (item) {
|
|
2498
|
+
return item[0] === origin.province;
|
|
2499
|
+
});
|
|
2141
2500
|
|
|
2142
2501
|
if (!province) {
|
|
2143
2502
|
return null;
|
|
2144
2503
|
}
|
|
2145
2504
|
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
// const region = Regions.find(item => item[0] === origin.province?.substring(0, 1));
|
|
2505
|
+
var birthday = "".concat(origin.year, "-").concat(origin.month, "-").concat(origin.day);
|
|
2506
|
+
var gender = Number(origin.gender) % 2 === 0 ? '女' : '男'; // const region = Regions.find(item => item[0] === origin.province?.substring(0, 1));
|
|
2149
2507
|
|
|
2150
2508
|
return {
|
|
2151
2509
|
// region,
|
|
2152
2510
|
province: province[1],
|
|
2153
|
-
birthday,
|
|
2154
|
-
gender,
|
|
2155
|
-
origin
|
|
2511
|
+
birthday: birthday,
|
|
2512
|
+
gender: gender,
|
|
2513
|
+
origin: origin
|
|
2156
2514
|
};
|
|
2157
2515
|
}
|
|
2158
2516
|
|
|
@@ -2184,12 +2542,17 @@
|
|
|
2184
2542
|
* });
|
|
2185
2543
|
*/
|
|
2186
2544
|
function blobToDataURL(blob) {
|
|
2187
|
-
return new Promise((resolve, reject)
|
|
2188
|
-
|
|
2189
|
-
reader.readAsDataURL(blob);
|
|
2190
|
-
|
|
2191
|
-
reader.onload = ()
|
|
2192
|
-
|
|
2545
|
+
return new Promise(function (resolve, reject) {
|
|
2546
|
+
var reader = new FileReader();
|
|
2547
|
+
reader.readAsDataURL(blob); // @ts-ignore
|
|
2548
|
+
|
|
2549
|
+
reader.onload = function () {
|
|
2550
|
+
return resolve(reader.result);
|
|
2551
|
+
};
|
|
2552
|
+
|
|
2553
|
+
reader.onerror = function (error) {
|
|
2554
|
+
return reject(error);
|
|
2555
|
+
};
|
|
2193
2556
|
});
|
|
2194
2557
|
}
|
|
2195
2558
|
|
|
@@ -2207,17 +2570,20 @@
|
|
|
2207
2570
|
* dataURLToBlob(dataurl);
|
|
2208
2571
|
*/
|
|
2209
2572
|
function dataURLToBlob(dataurl) {
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2573
|
+
var arr = dataurl.split(','); // @ts-ignore
|
|
2574
|
+
|
|
2575
|
+
var mime = arr[0].match(/:(.*?);/)[1];
|
|
2576
|
+
var bstr = atob(arr[1]);
|
|
2577
|
+
var n = bstr.length;
|
|
2578
|
+
var u8arr = new Uint8Array(n);
|
|
2216
2579
|
|
|
2217
2580
|
while (n--) {
|
|
2218
2581
|
u8arr[n] = bstr.charCodeAt(n);
|
|
2219
2582
|
}
|
|
2220
|
-
|
|
2583
|
+
|
|
2584
|
+
return new Blob([u8arr], {
|
|
2585
|
+
type: mime
|
|
2586
|
+
});
|
|
2221
2587
|
}
|
|
2222
2588
|
|
|
2223
2589
|
/**
|
|
@@ -2242,12 +2608,12 @@
|
|
|
2242
2608
|
* setDataURLPrefix(data, ''); // data:;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
|
|
2243
2609
|
* setDataURLPrefix(data, '', false); // data:,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
|
|
2244
2610
|
*/
|
|
2245
|
-
function setDataURLPrefix(data
|
|
2246
|
-
|
|
2611
|
+
function setDataURLPrefix(data) {
|
|
2612
|
+
var mimetype = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'image/png';
|
|
2613
|
+
var base64 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
2614
|
+
return "data:".concat(mimetype).concat(base64 ? ';base64' : '', ",").concat(data);
|
|
2247
2615
|
}
|
|
2248
2616
|
|
|
2249
|
-
// TODO: 函数重载,类型参照 Date
|
|
2250
|
-
|
|
2251
2617
|
/**
|
|
2252
2618
|
* 创建一个 Date 实例日期对象,同 new Date() 。<br/>
|
|
2253
2619
|
* 规避了苹果设备浏览器不支持部分格式(YYYY-MM-DD HH-mm 或 YYYY.MM.DD)。
|
|
@@ -2268,15 +2634,20 @@
|
|
|
2268
2634
|
* safeDate(1646711233171); // Tue Mar 08 2022 11:47:13 GMT+0800 (中国标准时间)
|
|
2269
2635
|
*
|
|
2270
2636
|
*/
|
|
2271
|
-
|
|
2272
|
-
|
|
2637
|
+
|
|
2638
|
+
function safeDate(value) {
|
|
2639
|
+
var safeValue = typeof value === 'string' ? value.replace(/[\\.-]/g, '/') : value;
|
|
2640
|
+
|
|
2641
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
2642
|
+
args[_key - 1] = arguments[_key];
|
|
2643
|
+
}
|
|
2273
2644
|
|
|
2274
2645
|
if (args && args.length > 0) {
|
|
2275
2646
|
// @ts-ignore
|
|
2276
|
-
return
|
|
2277
|
-
}
|
|
2647
|
+
return _construct(Date, [safeValue].concat(args));
|
|
2648
|
+
} // @ts-ignore
|
|
2649
|
+
|
|
2278
2650
|
|
|
2279
|
-
// @ts-ignore
|
|
2280
2651
|
return isNil(safeValue) ? new Date() : new Date(safeValue);
|
|
2281
2652
|
}
|
|
2282
2653
|
|
|
@@ -2303,16 +2674,23 @@
|
|
|
2303
2674
|
* formatMobile('133456') // '133 456'
|
|
2304
2675
|
* formatMobile('13345678') // '133 4567 8'
|
|
2305
2676
|
*/
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2677
|
+
|
|
2678
|
+
function formatMobile(mobileNo) {
|
|
2679
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
2680
|
+
_ref$char = _ref["char"],
|
|
2681
|
+
_char = _ref$char === void 0 ? ' ' : _ref$char;
|
|
2682
|
+
|
|
2683
|
+
var regChar = new RegExp(_char, 'g');
|
|
2684
|
+
var realValue = normalizeString(mobileNo).replace(regChar, '').substring(0, 11);
|
|
2309
2685
|
|
|
2310
2686
|
if (realValue.length > 7) {
|
|
2311
|
-
return realValue.replace(/^(...)(....)/g,
|
|
2687
|
+
return realValue.replace(/^(...)(....)/g, "$1".concat(_char, "$2").concat(_char));
|
|
2312
2688
|
}
|
|
2689
|
+
|
|
2313
2690
|
if (realValue.length > 3) {
|
|
2314
|
-
return realValue.replace(/^(...)/g,
|
|
2691
|
+
return realValue.replace(/^(...)/g, "$1".concat(_char));
|
|
2315
2692
|
}
|
|
2693
|
+
|
|
2316
2694
|
return realValue;
|
|
2317
2695
|
}
|
|
2318
2696
|
|
|
@@ -2338,9 +2716,11 @@
|
|
|
2338
2716
|
* padZero(688, 5); // '00688'
|
|
2339
2717
|
* padZero('688', 5); // '00688'
|
|
2340
2718
|
*/
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2719
|
+
|
|
2720
|
+
function padZero(value) {
|
|
2721
|
+
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
2722
|
+
var str = normalizeString(value);
|
|
2723
|
+
var len = str.length;
|
|
2344
2724
|
|
|
2345
2725
|
if (typeof size !== 'number' || size < 0) {
|
|
2346
2726
|
size = 0;
|
|
@@ -2349,36 +2729,8 @@
|
|
|
2349
2729
|
if (len < size) {
|
|
2350
2730
|
return '0'.repeat(size - len) + str;
|
|
2351
2731
|
}
|
|
2352
|
-
return str;
|
|
2353
|
-
}
|
|
2354
2732
|
|
|
2355
|
-
|
|
2356
|
-
* 检查值是否为Number
|
|
2357
|
-
*
|
|
2358
|
-
* @static
|
|
2359
|
-
* @alias module:Type.isNumber
|
|
2360
|
-
* @since 1.1.0
|
|
2361
|
-
* @param {*} value 检查值
|
|
2362
|
-
* @returns {boolean} 是否为Number
|
|
2363
|
-
* @example
|
|
2364
|
-
*
|
|
2365
|
-
* isNumber(1)
|
|
2366
|
-
* // => true
|
|
2367
|
-
*
|
|
2368
|
-
* isNumber(Number.MIN_VALUE)
|
|
2369
|
-
* // => true
|
|
2370
|
-
*
|
|
2371
|
-
* isNumber(Infinity)
|
|
2372
|
-
* // => true
|
|
2373
|
-
*
|
|
2374
|
-
* isNumber(NaN)
|
|
2375
|
-
* // => true
|
|
2376
|
-
*
|
|
2377
|
-
* isNumber('1')
|
|
2378
|
-
* // => false
|
|
2379
|
-
*/
|
|
2380
|
-
function isNumber(value) {
|
|
2381
|
-
return isType(value, 'Number');
|
|
2733
|
+
return str;
|
|
2382
2734
|
}
|
|
2383
2735
|
|
|
2384
2736
|
/**
|
|
@@ -2400,25 +2752,32 @@
|
|
|
2400
2752
|
* times(3, 0.6, 2, 10);
|
|
2401
2753
|
* // => 36
|
|
2402
2754
|
*/
|
|
2403
|
-
function times(...nums) {
|
|
2404
|
-
const [num1, num2, ...rest] = nums;
|
|
2405
|
-
if (rest.length > 0) {
|
|
2406
|
-
return times(times(num1, num2), ...rest);
|
|
2407
|
-
}
|
|
2408
2755
|
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
return num1;
|
|
2756
|
+
function times() {
|
|
2757
|
+
for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2758
|
+
nums[_key] = arguments[_key];
|
|
2413
2759
|
}
|
|
2414
2760
|
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
const leftValue = num1Changed * num2Changed;
|
|
2761
|
+
var num1 = nums[0],
|
|
2762
|
+
num2 = nums[1],
|
|
2763
|
+
rest = nums.slice(2);
|
|
2419
2764
|
|
|
2420
|
-
|
|
2765
|
+
if (rest.length > 0) {
|
|
2766
|
+
return times.apply(void 0, [times(num1, num2)].concat(_toConsumableArray(rest)));
|
|
2767
|
+
} // 兼容处理,如果参数包含无效数值时,尝试取出有效数值参数
|
|
2768
|
+
|
|
2769
|
+
|
|
2770
|
+
if (!isEffectiveNumeric(num1)) {
|
|
2771
|
+
return isEffectiveNumeric(num2) ? Number(num2) : NaN;
|
|
2772
|
+
} else if (!isEffectiveNumeric(num2)) {
|
|
2773
|
+
return Number(num1);
|
|
2774
|
+
}
|
|
2421
2775
|
|
|
2776
|
+
var num1Changed = float2Fixed(num1);
|
|
2777
|
+
var num2Changed = float2Fixed(num2);
|
|
2778
|
+
var baseNum = digitLength(num1) + digitLength(num2);
|
|
2779
|
+
var leftValue = num1Changed * num2Changed;
|
|
2780
|
+
checkBoundary(leftValue);
|
|
2422
2781
|
return leftValue / Math.pow(10, baseNum);
|
|
2423
2782
|
}
|
|
2424
2783
|
|
|
@@ -2441,20 +2800,28 @@
|
|
|
2441
2800
|
* plus(0.1, 0.2, 0.3, 0.4);
|
|
2442
2801
|
* // => 1
|
|
2443
2802
|
*/
|
|
2444
|
-
function plus(...nums) {
|
|
2445
|
-
const [num1, num2, ...rest] = nums;
|
|
2446
2803
|
|
|
2447
|
-
|
|
2448
|
-
|
|
2804
|
+
function plus() {
|
|
2805
|
+
for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2806
|
+
nums[_key] = arguments[_key];
|
|
2449
2807
|
}
|
|
2450
2808
|
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2809
|
+
var num1 = nums[0],
|
|
2810
|
+
num2 = nums[1],
|
|
2811
|
+
rest = nums.slice(2);
|
|
2812
|
+
|
|
2813
|
+
if (rest.length > 0) {
|
|
2814
|
+
return plus.apply(void 0, [plus(num1, num2)].concat(_toConsumableArray(rest)));
|
|
2815
|
+
} // 兼容处理,如果参数包含无效数值时,尝试取出有效数值参数
|
|
2816
|
+
|
|
2817
|
+
|
|
2818
|
+
if (!isEffectiveNumeric(num1)) {
|
|
2819
|
+
return isEffectiveNumeric(num2) ? Number(num2) : NaN;
|
|
2820
|
+
} else if (!isEffectiveNumeric(num2)) {
|
|
2821
|
+
return Number(num1);
|
|
2455
2822
|
}
|
|
2456
2823
|
|
|
2457
|
-
|
|
2824
|
+
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
2458
2825
|
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
|
|
2459
2826
|
}
|
|
2460
2827
|
|
|
@@ -2477,20 +2844,28 @@
|
|
|
2477
2844
|
* minus(1, 0.9, 0.02, 0.08);
|
|
2478
2845
|
* // => 0
|
|
2479
2846
|
*/
|
|
2480
|
-
function minus(...nums) {
|
|
2481
|
-
const [num1, num2, ...rest] = nums;
|
|
2482
2847
|
|
|
2483
|
-
|
|
2484
|
-
|
|
2848
|
+
function minus() {
|
|
2849
|
+
for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2850
|
+
nums[_key] = arguments[_key];
|
|
2485
2851
|
}
|
|
2486
2852
|
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2853
|
+
var num1 = nums[0],
|
|
2854
|
+
num2 = nums[1],
|
|
2855
|
+
rest = nums.slice(2);
|
|
2856
|
+
|
|
2857
|
+
if (rest.length > 0) {
|
|
2858
|
+
return minus.apply(void 0, [minus(num1, num2)].concat(_toConsumableArray(rest)));
|
|
2859
|
+
} // 兼容处理,如果参数包含无效数值时,尝试取出有效数值参数
|
|
2860
|
+
|
|
2861
|
+
|
|
2862
|
+
if (!isEffectiveNumeric(num1)) {
|
|
2863
|
+
return isEffectiveNumeric(num2) ? Number(num2) : NaN;
|
|
2864
|
+
} else if (!isEffectiveNumeric(num2)) {
|
|
2865
|
+
return Number(num1);
|
|
2491
2866
|
}
|
|
2492
2867
|
|
|
2493
|
-
|
|
2868
|
+
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
2494
2869
|
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
|
|
2495
2870
|
}
|
|
2496
2871
|
|
|
@@ -2513,24 +2888,32 @@
|
|
|
2513
2888
|
* divide(1000, 10, 10, 10);
|
|
2514
2889
|
* // => 1
|
|
2515
2890
|
*/
|
|
2516
|
-
function divide(...nums) {
|
|
2517
|
-
const [num1, num2, ...rest] = nums;
|
|
2518
2891
|
|
|
2519
|
-
|
|
2520
|
-
|
|
2892
|
+
function divide() {
|
|
2893
|
+
for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2894
|
+
nums[_key] = arguments[_key];
|
|
2521
2895
|
}
|
|
2522
2896
|
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2897
|
+
var num1 = nums[0],
|
|
2898
|
+
num2 = nums[1],
|
|
2899
|
+
rest = nums.slice(2);
|
|
2900
|
+
|
|
2901
|
+
if (rest.length > 0) {
|
|
2902
|
+
return divide.apply(void 0, [divide(num1, num2)].concat(_toConsumableArray(rest)));
|
|
2903
|
+
} // 兼容处理,如果参数包含无效数值时,尝试取出有效数值参数
|
|
2904
|
+
|
|
2905
|
+
|
|
2906
|
+
if (!isEffectiveNumeric(num1)) {
|
|
2907
|
+
return isEffectiveNumeric(num2) ? Number(num2) : NaN;
|
|
2908
|
+
} else if (!isEffectiveNumeric(num2)) {
|
|
2909
|
+
return Number(num1);
|
|
2527
2910
|
}
|
|
2528
2911
|
|
|
2529
|
-
|
|
2530
|
-
|
|
2912
|
+
var num1Changed = float2Fixed(num1);
|
|
2913
|
+
var num2Changed = float2Fixed(num2);
|
|
2531
2914
|
checkBoundary(num1Changed);
|
|
2532
|
-
checkBoundary(num2Changed);
|
|
2533
|
-
|
|
2915
|
+
checkBoundary(num2Changed); // fix: 类似 10 ** -4 为 0.00009999999999999999,strip 修正
|
|
2916
|
+
|
|
2534
2917
|
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
|
|
2535
2918
|
}
|
|
2536
2919
|
|
|
@@ -2554,8 +2937,16 @@
|
|
|
2554
2937
|
* round(4060, -2);
|
|
2555
2938
|
* // => 4100
|
|
2556
2939
|
*/
|
|
2557
|
-
|
|
2558
|
-
|
|
2940
|
+
|
|
2941
|
+
function round(num) {
|
|
2942
|
+
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
2943
|
+
|
|
2944
|
+
// 兼容处理,如果参数包含无效数值时,返回第一个参数
|
|
2945
|
+
if (!isEffectiveNumeric(num)) {
|
|
2946
|
+
return NaN;
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
var base = Math.pow(10, precision);
|
|
2559
2950
|
return divide(Math.round(times(num, base)), base);
|
|
2560
2951
|
}
|
|
2561
2952
|
|
|
@@ -2577,14 +2968,13 @@
|
|
|
2577
2968
|
* // do something
|
|
2578
2969
|
* })
|
|
2579
2970
|
*/
|
|
2580
|
-
function waitTime(
|
|
2581
|
-
|
|
2971
|
+
function waitTime() {
|
|
2972
|
+
var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
|
|
2973
|
+
return new Promise(function (resolve) {
|
|
2582
2974
|
setTimeout(resolve, time);
|
|
2583
2975
|
});
|
|
2584
2976
|
}
|
|
2585
2977
|
|
|
2586
|
-
// ref: https://github.com/ant-design/ant-design-mobile/blob/v2/components/input-item/index.tsx#L240
|
|
2587
|
-
|
|
2588
2978
|
/**
|
|
2589
2979
|
* 计算输入框的值格式化后光标位置
|
|
2590
2980
|
*
|
|
@@ -2605,22 +2995,28 @@
|
|
|
2605
2995
|
* @param {'mobile'|'bankCard'} [options.type] 格式化类型,内置手机号码和银行卡号特殊处理
|
|
2606
2996
|
* @returns {number} 格式化后的光标位置
|
|
2607
2997
|
*/
|
|
2608
|
-
function calculateCursorPosition(prevPos, prevCtrlValue, rawValue, ctrlValue, { placeholderChar = ' ', maskReg = /\D/g, type } = {}) {
|
|
2609
|
-
const realCtrlValue = normalizeString(prevCtrlValue);
|
|
2610
|
-
const realRawValue = normalizeString(rawValue);
|
|
2611
|
-
const placeholderChars = Array.isArray(placeholderChar) ? placeholderChar : [placeholderChar];
|
|
2612
2998
|
|
|
2613
|
-
|
|
2614
|
-
|
|
2999
|
+
function calculateCursorPosition(prevPos, prevCtrlValue, rawValue, ctrlValue) {
|
|
3000
|
+
var _ref = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
|
|
3001
|
+
_ref$placeholderChar = _ref.placeholderChar,
|
|
3002
|
+
placeholderChar = _ref$placeholderChar === void 0 ? ' ' : _ref$placeholderChar,
|
|
3003
|
+
_ref$maskReg = _ref.maskReg,
|
|
3004
|
+
maskReg = _ref$maskReg === void 0 ? /\D/g : _ref$maskReg,
|
|
3005
|
+
type = _ref.type;
|
|
2615
3006
|
|
|
2616
|
-
|
|
3007
|
+
var realCtrlValue = normalizeString(prevCtrlValue);
|
|
3008
|
+
var realRawValue = normalizeString(rawValue);
|
|
3009
|
+
var placeholderChars = Array.isArray(placeholderChar) ? placeholderChar : [placeholderChar];
|
|
3010
|
+
var editLength = realRawValue.length - realCtrlValue.length;
|
|
3011
|
+
var isAddition = editLength > 0;
|
|
3012
|
+
var pos = prevPos;
|
|
2617
3013
|
|
|
2618
3014
|
if (isAddition) {
|
|
2619
|
-
|
|
2620
|
-
|
|
3015
|
+
var additionStr = realRawValue.substring(pos - editLength, pos);
|
|
3016
|
+
var ctrlCharCount = additionStr.replace(maskReg, '').length;
|
|
2621
3017
|
pos -= editLength - ctrlCharCount;
|
|
3018
|
+
var placeholderCharCount = 0;
|
|
2622
3019
|
|
|
2623
|
-
let placeholderCharCount = 0;
|
|
2624
3020
|
while (ctrlCharCount > 0) {
|
|
2625
3021
|
if (placeholderChars.indexOf(ctrlValue.charAt(pos - ctrlCharCount + placeholderCharCount)) !== -1) {
|
|
2626
3022
|
placeholderCharCount++;
|
|
@@ -2628,20 +3024,20 @@
|
|
|
2628
3024
|
ctrlCharCount--;
|
|
2629
3025
|
}
|
|
2630
3026
|
}
|
|
3027
|
+
|
|
2631
3028
|
pos += placeholderCharCount;
|
|
2632
3029
|
}
|
|
2633
3030
|
|
|
2634
|
-
if (
|
|
3031
|
+
if (type === 'mobile' && (pos === 4 || pos === 9) || type === 'bankCard' && pos > 0 && pos % 5 === 0) {
|
|
2635
3032
|
pos -= 1;
|
|
2636
3033
|
}
|
|
2637
3034
|
|
|
2638
3035
|
return pos;
|
|
2639
3036
|
}
|
|
2640
3037
|
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
3038
|
+
var numberChars = '0123456789';
|
|
3039
|
+
var letterChars = 'abcdefghijklmnopqrstuvwxyz';
|
|
3040
|
+
var defaultChars = numberChars + letterChars + letterChars.toUpperCase();
|
|
2645
3041
|
/**
|
|
2646
3042
|
* @private
|
|
2647
3043
|
* @param {number} [len=0] 长度
|
|
@@ -2649,14 +3045,19 @@
|
|
|
2649
3045
|
* @param {string} [prefix=''] 前缀部分,不计入长度
|
|
2650
3046
|
* @returns {string}
|
|
2651
3047
|
*/
|
|
2652
|
-
|
|
3048
|
+
|
|
3049
|
+
function internalRandomString() {
|
|
3050
|
+
var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
3051
|
+
var optionalChars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultChars;
|
|
3052
|
+
var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
3053
|
+
|
|
2653
3054
|
while (len-- > 0) {
|
|
2654
|
-
|
|
3055
|
+
var r = optionalChars[Math.floor(Math.random() * optionalChars.length)];
|
|
2655
3056
|
return internalRandomString(len, optionalChars, prefix + r);
|
|
2656
3057
|
}
|
|
3058
|
+
|
|
2657
3059
|
return prefix;
|
|
2658
3060
|
}
|
|
2659
|
-
|
|
2660
3061
|
/**
|
|
2661
3062
|
* 生成随机字符串
|
|
2662
3063
|
*
|
|
@@ -2674,10 +3075,13 @@
|
|
|
2674
3075
|
* randomString(5, 'abc'); // ccbcb
|
|
2675
3076
|
* randomString(8, 'abcefg'); // bcgcfabg
|
|
2676
3077
|
*/
|
|
2677
|
-
function randomString(len = 0, optionalChars) {
|
|
2678
3078
|
|
|
2679
|
-
const realChars = typeof optionalChars === 'string' && optionalChars ? optionalChars : defaultChars;
|
|
2680
3079
|
|
|
3080
|
+
function randomString() {
|
|
3081
|
+
var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
3082
|
+
var optionalChars = arguments.length > 1 ? arguments[1] : undefined;
|
|
3083
|
+
|
|
3084
|
+
var realChars = typeof optionalChars === 'string' && optionalChars ? optionalChars : defaultChars;
|
|
2681
3085
|
return internalRandomString(len, realChars);
|
|
2682
3086
|
}
|
|
2683
3087
|
|
|
@@ -2699,17 +3103,21 @@
|
|
|
2699
3103
|
* strlen('🍎'); // 4
|
|
2700
3104
|
*
|
|
2701
3105
|
*/
|
|
3106
|
+
|
|
2702
3107
|
function strlen(str) {
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
3108
|
+
var realStr = normalizeString(str);
|
|
3109
|
+
var len = 0;
|
|
3110
|
+
|
|
3111
|
+
for (var i = 0; i < realStr.length; i++) {
|
|
3112
|
+
var c = realStr.charCodeAt(i);
|
|
3113
|
+
|
|
3114
|
+
if (c >= 0x0001 && c <= 0x007e || 0xff60 <= c && c <= 0xff9f) {
|
|
2708
3115
|
len++;
|
|
2709
3116
|
} else {
|
|
2710
3117
|
len += 2;
|
|
2711
3118
|
}
|
|
2712
3119
|
}
|
|
3120
|
+
|
|
2713
3121
|
return len;
|
|
2714
3122
|
}
|
|
2715
3123
|
|