util-helpers 4.16.2 → 4.17.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 +1542 -4040
- 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/ajax.js +50 -146
- package/esm/blobToDataURL.js +4 -34
- package/esm/bytesToSize.js +12 -37
- package/esm/calculateCursorPosition.js +30 -52
- package/esm/dataURLToBlob.js +14 -28
- package/esm/divide.js +24 -48
- package/esm/download.js +83 -164
- package/esm/fileReader.js +18 -64
- package/esm/filterTree.js +25 -55
- package/esm/findTreeNode.js +39 -67
- package/esm/findTreeNodes.js +35 -66
- package/esm/findTreeSelect.js +38 -74
- package/esm/formatBankCard.js +13 -43
- package/esm/formatMobile.js +17 -43
- package/esm/formatMoney.js +59 -139
- package/esm/index.js +55 -130
- package/esm/isBankCard.js +22 -57
- package/esm/isBusinessLicense.js +32 -78
- package/esm/isChinese.js +23 -66
- package/esm/isEmail.js +6 -21
- package/esm/isHMCard.js +5 -28
- package/esm/isIPv4.js +5 -22
- package/esm/isIPv6.js +5 -36
- package/esm/isIdCard.js +27 -66
- package/esm/isMobile.js +5 -20
- package/esm/isPassport.js +5 -22
- package/esm/isPassword.js +7 -48
- package/esm/isPostcode.js +5 -20
- package/esm/isPromiseLike.js +3 -18
- package/esm/isQQ.js +5 -20
- package/esm/isSocialCreditCode.js +28 -83
- package/esm/isSwiftCode.js +6 -25
- package/esm/isTWCard.js +11 -37
- package/esm/isTelephone.js +6 -27
- package/esm/isUrl.js +5 -44
- package/esm/isVehicle.js +5 -28
- package/esm/isWX.js +5 -20
- package/esm/listToTree.js +51 -120
- package/esm/minus.js +21 -39
- package/esm/normalizeString.js +8 -29
- package/esm/numberToChinese.js +96 -215
- package/esm/padZero.js +14 -36
- package/esm/parseIdCard.js +64 -129
- package/esm/plus.js +21 -39
- package/esm/randomString.js +13 -45
- package/esm/replaceChar.js +27 -77
- package/esm/round.js +14 -31
- package/esm/safeDate.js +12 -55
- package/esm/setDataURLPrefix.js +6 -29
- package/esm/strlen.js +14 -30
- package/esm/times.js +24 -42
- package/esm/transformFieldNames.js +37 -93
- package/esm/treeToList.js +25 -84
- package/esm/utils/config.js +4 -14
- package/esm/utils/constants.js +4 -4
- package/esm/utils/convertToString.js +4 -9
- package/esm/utils/devWarn.js +11 -11
- package/esm/utils/math.util.js +95 -181
- package/esm/utils/type/isBlob.js +4 -24
- package/esm/utils/type/isNaN.js +4 -19
- package/esm/utils/type/isNil.js +5 -13
- package/esm/utils/type/isNull.js +3 -18
- package/esm/utils/type/isNumber.js +4 -28
- package/esm/utils/type/isObject.js +4 -23
- package/esm/utils/type/isString.js +4 -19
- package/esm/utils/type/isSymbol.js +4 -19
- package/esm/utils/type/isType.js +3 -12
- package/esm/utils/type/isUndefined.js +3 -21
- package/esm/validatePassword.js +86 -237
- package/esm/waitTime.js +7 -26
- package/lib/ajax.js +51 -152
- package/lib/blobToDataURL.js +5 -40
- package/lib/bytesToSize.js +13 -43
- package/lib/calculateCursorPosition.js +32 -58
- package/lib/dataURLToBlob.js +15 -34
- package/lib/divide.js +26 -60
- package/lib/download.js +85 -169
- package/lib/fileReader.js +19 -70
- package/lib/filterTree.js +27 -66
- package/lib/findTreeNode.js +40 -77
- package/lib/findTreeNodes.js +36 -76
- package/lib/findTreeSelect.js +40 -82
- package/lib/formatBankCard.js +15 -50
- package/lib/formatMobile.js +19 -50
- package/lib/formatMoney.js +60 -150
- package/lib/index.js +117 -395
- package/lib/isBankCard.js +24 -64
- package/lib/isBusinessLicense.js +34 -85
- package/lib/isChinese.js +24 -73
- package/lib/isEmail.js +7 -27
- package/lib/isHMCard.js +7 -35
- package/lib/isIPv4.js +7 -29
- package/lib/isIPv6.js +7 -43
- package/lib/isIdCard.js +29 -73
- package/lib/isMobile.js +7 -27
- package/lib/isPassport.js +7 -29
- package/lib/isPassword.js +9 -55
- package/lib/isPostcode.js +7 -27
- package/lib/isPromiseLike.js +4 -24
- package/lib/isQQ.js +7 -27
- package/lib/isSocialCreditCode.js +30 -90
- package/lib/isSwiftCode.js +7 -32
- package/lib/isTWCard.js +13 -44
- package/lib/isTelephone.js +7 -33
- package/lib/isUrl.js +6 -49
- package/lib/isVehicle.js +7 -35
- package/lib/isWX.js +7 -27
- package/lib/listToTree.js +53 -131
- package/lib/minus.js +23 -51
- package/lib/normalizeString.js +10 -36
- package/lib/numberToChinese.js +98 -222
- package/lib/padZero.js +16 -43
- package/lib/parseIdCard.js +65 -138
- package/lib/plus.js +23 -51
- package/lib/randomString.js +14 -51
- package/lib/replaceChar.js +28 -83
- package/lib/round.js +15 -37
- package/lib/safeDate.js +13 -63
- package/lib/setDataURLPrefix.js +7 -35
- package/lib/strlen.js +16 -37
- package/lib/times.js +26 -53
- package/lib/transformFieldNames.js +38 -101
- package/lib/treeToList.js +27 -94
- package/lib/utils/config.js +6 -23
- package/lib/utils/constants.js +3 -11
- package/lib/utils/convertToString.js +6 -16
- package/lib/utils/devWarn.js +13 -17
- package/lib/utils/math.util.js +95 -185
- package/lib/utils/type/isBlob.js +6 -31
- package/lib/utils/type/isNaN.js +6 -26
- package/lib/utils/type/isNil.js +7 -20
- package/lib/utils/type/isNull.js +4 -24
- package/lib/utils/type/isNumber.js +6 -35
- package/lib/utils/type/isObject.js +5 -29
- package/lib/utils/type/isString.js +6 -26
- package/lib/utils/type/isSymbol.js +6 -26
- package/lib/utils/type/isType.js +4 -18
- package/lib/utils/type/isUndefined.js +4 -27
- package/lib/validatePassword.js +87 -244
- package/lib/waitTime.js +8 -32
- package/package.json +21 -25
- package/types/ajax.d.ts +38 -95
- package/types/blobToDataURL.d.ts +2 -2
- package/types/bytesToSize.d.ts +7 -6
- package/types/calculateCursorPosition.d.ts +10 -9
- package/types/dataURLToBlob.d.ts +5 -5
- package/types/divide.d.ts +2 -2
- package/types/download.d.ts +22 -38
- package/types/fileReader.d.ts +35 -2
- package/types/filterTree.d.ts +6 -7
- package/types/findTreeNode.d.ts +5 -7
- package/types/findTreeNodes.d.ts +5 -7
- package/types/findTreeSelect.d.ts +5 -7
- package/types/formatBankCard.d.ts +8 -5
- package/types/formatMobile.d.ts +7 -4
- package/types/formatMoney.d.ts +8 -7
- package/types/index.d.ts +125 -55
- package/types/isBankCard.d.ts +9 -8
- package/types/isBusinessLicense.d.ts +8 -5
- package/types/isChinese.d.ts +9 -8
- package/types/isEmail.d.ts +1 -1
- package/types/isHMCard.d.ts +2 -2
- package/types/isIPv4.d.ts +1 -1
- package/types/isIPv6.d.ts +1 -1
- package/types/isIdCard.d.ts +8 -7
- package/types/isMobile.d.ts +1 -1
- package/types/isPassport.d.ts +2 -2
- package/types/isPassword.d.ts +4 -7
- package/types/isPostcode.d.ts +1 -1
- package/types/isPromiseLike.d.ts +1 -1
- package/types/isQQ.d.ts +1 -1
- package/types/isSocialCreditCode.d.ts +8 -5
- package/types/isSwiftCode.d.ts +2 -2
- package/types/isTWCard.d.ts +6 -5
- package/types/isTelephone.d.ts +1 -1
- package/types/isUrl.d.ts +2 -2
- package/types/isVehicle.d.ts +2 -2
- package/types/isWX.d.ts +1 -1
- package/types/listToTree.d.ts +12 -12
- package/types/minus.d.ts +3 -2
- package/types/normalizeString.d.ts +2 -2
- package/types/numberToChinese.d.ts +13 -12
- package/types/padZero.d.ts +2 -2
- package/types/parseIdCard.d.ts +17 -56
- package/types/plus.d.ts +3 -2
- package/types/randomString.d.ts +2 -2
- package/types/replaceChar.d.ts +15 -11
- package/types/round.d.ts +2 -2
- package/types/safeDate.d.ts +24 -2
- package/types/setDataURLPrefix.d.ts +5 -5
- package/types/strlen.d.ts +1 -1
- package/types/times.d.ts +3 -2
- package/types/transformFieldNames.d.ts +12 -10
- package/types/treeToList.d.ts +1 -1
- package/types/utils/config.d.ts +6 -5
- package/types/utils/constants.d.ts +2 -2
- package/types/utils/convertToString.d.ts +1 -1
- package/types/utils/devWarn.d.ts +1 -1
- package/types/utils/math.util.d.ts +15 -9
- package/types/utils/type/index.d.ts +7 -0
- package/types/utils/type/isArguments.d.ts +1 -1
- package/types/utils/type/isArray.d.ts +1 -1
- package/types/utils/type/isArrayBuffer.d.ts +1 -1
- package/types/utils/type/isBlob.d.ts +1 -1
- package/types/utils/type/isBoolean.d.ts +1 -1
- package/types/utils/type/isDate.d.ts +1 -1
- package/types/utils/type/isError.d.ts +1 -1
- package/types/utils/type/isFunction.d.ts +1 -1
- package/types/utils/type/isMap.d.ts +1 -1
- package/types/utils/type/isNaN.d.ts +1 -1
- package/types/utils/type/isNil.d.ts +1 -1
- package/types/utils/type/isNull.d.ts +1 -1
- package/types/utils/type/isNumber.d.ts +1 -1
- package/types/utils/type/isObject.d.ts +1 -1
- package/types/utils/type/isRegExp.d.ts +1 -1
- package/types/utils/type/isSet.d.ts +1 -1
- package/types/utils/type/isString.d.ts +1 -1
- package/types/utils/type/isSymbol.d.ts +1 -1
- package/types/utils/type/isType.d.ts +1 -1
- package/types/utils/type/isUndefined.d.ts +1 -1
- package/types/utils/type/isWeakMap.d.ts +1 -1
- package/types/utils/type/isWeakSet.d.ts +1 -1
- package/types/validatePassword.d.ts +17 -48
- package/types/waitTime.d.ts +2 -2
- package/esm/interface.doc.js +0 -125
- package/esm/interface.type.js +0 -17
- package/esm/utils/type/index.js +0 -29
- package/esm/utils/type/isArguments.js +0 -22
- package/esm/utils/type/isArray.js +0 -22
- package/esm/utils/type/isArrayBuffer.js +0 -25
- package/esm/utils/type/isBoolean.js +0 -22
- package/esm/utils/type/isDate.js +0 -22
- package/esm/utils/type/isError.js +0 -22
- package/esm/utils/type/isFunction.js +0 -22
- package/esm/utils/type/isMap.js +0 -22
- package/esm/utils/type/isRegExp.js +0 -22
- package/esm/utils/type/isSet.js +0 -22
- package/esm/utils/type/isWeakMap.js +0 -22
- package/esm/utils/type/isWeakSet.js +0 -22
- package/lib/interface.doc.js +0 -127
- package/lib/interface.type.js +0 -5
- package/lib/utils/type/index.js +0 -146
- package/lib/utils/type/isArguments.js +0 -29
- package/lib/utils/type/isArray.js +0 -29
- package/lib/utils/type/isArrayBuffer.js +0 -32
- package/lib/utils/type/isBoolean.js +0 -29
- package/lib/utils/type/isDate.js +0 -29
- package/lib/utils/type/isError.js +0 -29
- package/lib/utils/type/isFunction.js +0 -29
- package/lib/utils/type/isMap.js +0 -29
- package/lib/utils/type/isRegExp.js +0 -29
- package/lib/utils/type/isSet.js +0 -29
- package/lib/utils/type/isWeakMap.js +0 -29
- package/lib/utils/type/isWeakSet.js +0 -29
- package/types/interface.type.d.ts +0 -2
package/esm/isIdCard.js
CHANGED
|
@@ -1,72 +1,33 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// 身份证号正则
|
|
4
3
|
var regIdCard = /^[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;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 校验码计算
|
|
8
|
-
*
|
|
9
|
-
* @private
|
|
10
|
-
* @param {string} id 身份证号码
|
|
11
|
-
* @returns {boolean} 校验码是否正确
|
|
12
|
-
*/
|
|
13
4
|
function check(id) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
var index, sum;
|
|
6
|
+
for (sum = index = 0; index < 17; index++) {
|
|
7
|
+
sum += (Math.pow(2, 17 - index) % 11) * Number(id[index]);
|
|
8
|
+
}
|
|
9
|
+
var num = (12 - (sum % 11)) % 11;
|
|
10
|
+
if (num < 10) {
|
|
11
|
+
return num === Number(id[17]);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return id[17].toUpperCase() === 'X';
|
|
15
|
+
}
|
|
24
16
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,仅支持18位身份证号码
|
|
38
|
-
* @returns {boolean} 值是否为身份证号
|
|
39
|
-
* @example
|
|
40
|
-
*
|
|
41
|
-
* isIdCard('130701199310302288'); // true
|
|
42
|
-
* isIdCard('13070119931030228X'); // false
|
|
43
|
-
*
|
|
44
|
-
* // 不校验校验码
|
|
45
|
-
* isIdCard('13070119931030228X', { checkCode: false }); // true
|
|
46
|
-
*
|
|
47
|
-
* // 默认不支持15位身份证号码
|
|
48
|
-
* isIdCard('320311770706001'); // false
|
|
49
|
-
*
|
|
50
|
-
* // 宽松模式,支持15位身份证号
|
|
51
|
-
* isIdCard('320311770706001', { loose: true }); // true
|
|
52
|
-
*
|
|
53
|
-
*/
|
|
54
|
-
function isIdCard(value) {
|
|
55
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
56
|
-
var _options$loose = options.loose,
|
|
57
|
-
loose = _options$loose === void 0 ? false : _options$loose,
|
|
58
|
-
_options$checkCode = options.checkCode,
|
|
59
|
-
checkCode = _options$checkCode === void 0 ? true : _options$checkCode;
|
|
60
|
-
var valueStr = normalizeString(value);
|
|
61
|
-
if (valueStr.length === 15 && loose) {
|
|
62
|
-
return regIdCard.test(valueStr);
|
|
63
|
-
}
|
|
64
|
-
if (valueStr.length === 18 && regIdCard.test(valueStr)) {
|
|
65
|
-
if (checkCode) {
|
|
66
|
-
return check(valueStr);
|
|
17
|
+
function isIdCard(value, options) {
|
|
18
|
+
if (options === void 0) { options = {}; }
|
|
19
|
+
var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.checkCode, checkCode = _b === void 0 ? true : _b;
|
|
20
|
+
var valueStr = normalizeString(value);
|
|
21
|
+
if (valueStr.length === 15 && loose) {
|
|
22
|
+
return regIdCard.test(valueStr);
|
|
23
|
+
}
|
|
24
|
+
if (valueStr.length === 18 && regIdCard.test(valueStr)) {
|
|
25
|
+
if (checkCode) {
|
|
26
|
+
return check(valueStr);
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
67
29
|
}
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
return false;
|
|
30
|
+
return false;
|
|
71
31
|
}
|
|
72
|
-
|
|
32
|
+
|
|
33
|
+
export { isIdCard as default };
|
package/esm/isMobile.js
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// 手机号码 11位数字,以1开头,第二位是3456789其中一个,后面再加9个数字
|
|
4
3
|
var reg = /^1[3456789]\d{9}$/;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 检测值是否为手机号码
|
|
8
|
-
*
|
|
9
|
-
* @static
|
|
10
|
-
* @alias module:Validator.isMobile
|
|
11
|
-
* @since 1.1.0
|
|
12
|
-
* @param {*} value 要检测的值
|
|
13
|
-
* @returns {boolean} 值是否为手机号码
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* isMobile('13000000000'); // true
|
|
17
|
-
* isMobile('13000'); // false
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
4
|
function isMobile(value) {
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
var valueStr = normalizeString(value);
|
|
6
|
+
return reg.test(valueStr);
|
|
23
7
|
}
|
|
24
|
-
|
|
8
|
+
|
|
9
|
+
export { isMobile as default };
|
package/esm/isPassport.js
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// 护照号 9位,包括首字母和数字;支持 普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ/H*)、澳门特区护照(MA/MB/M*)
|
|
4
3
|
var reg = /^((e[\da-z])|(de)|(se)|(pe)|([khm][\da-z]))[\da-z]{7}$/i;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 检测值是否为护照号
|
|
8
|
-
* 支持普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ/H*)、澳门特区护照(MA/MB/M*),注意不区分大小写
|
|
9
|
-
*
|
|
10
|
-
* @static
|
|
11
|
-
* @alias module:Validator.isPassport
|
|
12
|
-
* @since 1.1.0
|
|
13
|
-
* @see {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页|中华人民共和国护照#个人资料页}
|
|
14
|
-
* @param {*} value 要检测的值
|
|
15
|
-
* @returns {boolean} 值是否为护照号
|
|
16
|
-
* @example
|
|
17
|
-
*
|
|
18
|
-
* isPassport('E12345678'); // true
|
|
19
|
-
* isPassport('abc'); // false
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
4
|
function isPassport(value) {
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
var valueStr = normalizeString(value);
|
|
6
|
+
return reg.test(valueStr);
|
|
25
7
|
}
|
|
26
|
-
|
|
8
|
+
|
|
9
|
+
export { isPassport as default };
|
package/esm/isPassword.js
CHANGED
|
@@ -1,50 +1,9 @@
|
|
|
1
|
-
import validatePassword from './validatePassword';
|
|
1
|
+
import validatePassword from './validatePassword.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* @static
|
|
9
|
-
* @alias module:Validator.isPassword
|
|
10
|
-
* @requires module:Validator.validatePassword
|
|
11
|
-
* @since 1.1.0
|
|
12
|
-
* @see {@link https://baike.baidu.com/item/ASCII#3|ASCII}
|
|
13
|
-
* @param {*} value 要检测的值
|
|
14
|
-
* @param {Object} [options] 配置项
|
|
15
|
-
* @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
|
|
16
|
-
* @param {boolean} [options.ignoreCase=false] 是否忽略大小写,为 ture 时,大小写字母视为一种字符
|
|
17
|
-
* @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符
|
|
18
|
-
* @returns {boolean} 值是否符合密码强度
|
|
19
|
-
* @example
|
|
20
|
-
*
|
|
21
|
-
* isPassword('a12345678'); // true
|
|
22
|
-
*
|
|
23
|
-
* // 3级密码强度
|
|
24
|
-
* isPassword('a12345678', {level: 3}); // false
|
|
25
|
-
* isPassword('Aa12345678', {level: 3}); // true
|
|
26
|
-
*
|
|
27
|
-
* // 3级密码强度,大小写字符仅计算1级强度
|
|
28
|
-
* isPassword('Aa12345678', {level: 3, ignoreCase: true}); // false
|
|
29
|
-
* isPassword('_Aa12345678', {level: 3, ignoreCase: true}); // true
|
|
30
|
-
*
|
|
31
|
-
* // 仅支持 数字、字母、特殊字符,其他非法字符如中文字符是校验不通过的
|
|
32
|
-
* isPassword('_Aa一二三45678', {level: 3, ignoreCase: true}); // false
|
|
33
|
-
* isPassword(' _Aa12345678', {level: 3, ignoreCase: true}); // false
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
function isPassword(value) {
|
|
37
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
38
|
-
var _options$level = options.level,
|
|
39
|
-
level = _options$level === void 0 ? 2 : _options$level,
|
|
40
|
-
_options$ignoreCase = options.ignoreCase,
|
|
41
|
-
ignoreCase = _options$ignoreCase === void 0 ? false : _options$ignoreCase,
|
|
42
|
-
_options$special = options.special,
|
|
43
|
-
special = _options$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _options$special;
|
|
44
|
-
return validatePassword(value, {
|
|
45
|
-
level: level,
|
|
46
|
-
ignoreCase: ignoreCase,
|
|
47
|
-
special: special
|
|
48
|
-
}).validated;
|
|
3
|
+
function isPassword(value, options) {
|
|
4
|
+
if (options === void 0) { options = {}; }
|
|
5
|
+
var _a = options.level, level = _a === void 0 ? 2 : _a, _b = options.ignoreCase, ignoreCase = _b === void 0 ? false : _b, _c = options.special, special = _c === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _c;
|
|
6
|
+
return validatePassword(value, { level: level, ignoreCase: ignoreCase, special: special }).validated;
|
|
49
7
|
}
|
|
50
|
-
|
|
8
|
+
|
|
9
|
+
export { isPassword as default };
|
package/esm/isPostcode.js
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// 邮政编码
|
|
4
3
|
var reg = /^\d{6}$/;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 检测值是否为邮政编码,6位数字
|
|
8
|
-
*
|
|
9
|
-
* @static
|
|
10
|
-
* @alias module:Validator.isPostcode
|
|
11
|
-
* @since 1.1.0
|
|
12
|
-
* @param {*} value 要检测的值
|
|
13
|
-
* @returns {boolean} 值是否为邮政编码
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* isPostcode('101111'); // true
|
|
17
|
-
* isPostcode('123'); // false
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
4
|
function isPostcode(value) {
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
var valueStr = normalizeString(value);
|
|
6
|
+
return reg.test(valueStr);
|
|
23
7
|
}
|
|
24
|
-
|
|
8
|
+
|
|
9
|
+
export { isPostcode as default };
|
package/esm/isPromiseLike.js
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
-
/**
|
|
3
|
-
* 检测值是否类似Promise对象
|
|
4
|
-
*
|
|
5
|
-
* @static
|
|
6
|
-
* @alias module:Validator.isPromiseLike
|
|
7
|
-
* @since 3.8.0
|
|
8
|
-
* @param {*} obj 要检测的值
|
|
9
|
-
* @returns {boolean} 是否类似Promise对象
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* isPromiseLike([]); // false
|
|
13
|
-
* isPromiseLike({ then: () => { } }); // true
|
|
14
|
-
* isPromiseLike(Promise.resolve()); // true
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
1
|
function isPromiseLike(obj) {
|
|
18
|
-
|
|
2
|
+
return obj !== null && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
|
19
3
|
}
|
|
20
|
-
|
|
4
|
+
|
|
5
|
+
export { isPromiseLike as default };
|
package/esm/isQQ.js
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// QQ号正则
|
|
4
3
|
var reg = /^[1-9]\d{4,10}$/;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 检测值是否为QQ号,非0开头,5至11位数字
|
|
8
|
-
*
|
|
9
|
-
* @static
|
|
10
|
-
* @alias module:Validator.isQQ
|
|
11
|
-
* @since 1.1.0
|
|
12
|
-
* @param {*} value 要检测的值
|
|
13
|
-
* @returns {boolean} 值是否为QQ号
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* isQQ('12345'); // true
|
|
17
|
-
* isQQ('123'); // false
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
4
|
function isQQ(value) {
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
var valueStr = normalizeString(value);
|
|
6
|
+
return reg.test(valueStr);
|
|
23
7
|
}
|
|
24
|
-
|
|
8
|
+
|
|
9
|
+
export { isQQ as default };
|
|
@@ -1,89 +1,34 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// 基础规则,由18位数字和大写字母组成,不使用I、O、Z、S、V。
|
|
4
3
|
var baseReg = /^[\dA-HJ-NPQRTUWXY]{2}\d{6}[\dA-HJ-NPQRTUWXY]{10}$/;
|
|
5
|
-
|
|
6
|
-
// 基础字符组成
|
|
7
4
|
var baseCodeArr = '0123456789ABCDEFGHJKLMNPQRTUWXY'.split('');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 计算校验码
|
|
11
|
-
*
|
|
12
|
-
* @private
|
|
13
|
-
* @since 1.1.0
|
|
14
|
-
* @param {string} preCode 统一代码前17位
|
|
15
|
-
* @returns {string} 校验码
|
|
16
|
-
*/
|
|
17
5
|
function sumCheckCode(preCode) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
for (var i = 0; i < 17; i++) {
|
|
32
|
-
_loop(i);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 计算整数求余函数MOD
|
|
36
|
-
var remainder = total % 31;
|
|
37
|
-
// 校验码字符值序号
|
|
38
|
-
var checkCodeIndex = remainder !== 0 ? 31 - remainder : 0;
|
|
39
|
-
return baseCodeArr[checkCodeIndex];
|
|
6
|
+
var total = 0;
|
|
7
|
+
var _loop_1 = function (i) {
|
|
8
|
+
var index = baseCodeArr.findIndex(function (item) { return item === preCode[i]; });
|
|
9
|
+
var wf = Math.pow(3, i) % 31;
|
|
10
|
+
total += index * wf;
|
|
11
|
+
};
|
|
12
|
+
for (var i = 0; i < 17; i++) {
|
|
13
|
+
_loop_1(i);
|
|
14
|
+
}
|
|
15
|
+
var remainder = total % 31;
|
|
16
|
+
var checkCodeIndex = remainder !== 0 ? 31 - remainder : 0;
|
|
17
|
+
return baseCodeArr[checkCodeIndex];
|
|
40
18
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*
|
|
55
|
-
* isSocialCreditCode('91350100M000100Y43'); // true
|
|
56
|
-
* isSocialCreditCode('91350100M000100Y4A'); // false
|
|
57
|
-
*
|
|
58
|
-
* // 不校验校验位,长度和类型还是有校验的
|
|
59
|
-
* isSocialCreditCode('91350100M000100Y4A', { checkCode: false }); // true
|
|
60
|
-
* isSocialCreditCode('91350100M000100YIO', { checkCode: false }); // false
|
|
61
|
-
* isSocialCreditCode('91350100M000100Y', { checkCode: false }); // false
|
|
62
|
-
*
|
|
63
|
-
*/
|
|
64
|
-
function isSocialCreditCode(value) {
|
|
65
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
66
|
-
var valueStr = normalizeString(value);
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
// TODO 下个版本废弃 loose
|
|
69
|
-
var _options$loose = options.loose,
|
|
70
|
-
loose = _options$loose === void 0 ? false : _options$loose,
|
|
71
|
-
_options$checkCode = options.checkCode,
|
|
72
|
-
cc = _options$checkCode === void 0 ? true : _options$checkCode;
|
|
73
|
-
var needCheckCode = !loose && cc;
|
|
74
|
-
var passBaseRule = baseReg.test(valueStr);
|
|
75
|
-
|
|
76
|
-
// 宽松模式 或 基础规则不通过直接返回
|
|
77
|
-
if (!needCheckCode || !passBaseRule) {
|
|
78
|
-
return passBaseRule;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// 前17位
|
|
82
|
-
var preCode = valueStr.substring(0, 17);
|
|
83
|
-
// 校验码
|
|
84
|
-
var lastCode = valueStr.substring(valueStr.length - 1);
|
|
85
|
-
// 计算校验码
|
|
86
|
-
var checkCode = sumCheckCode(preCode);
|
|
87
|
-
return lastCode === checkCode;
|
|
19
|
+
function isSocialCreditCode(value, options) {
|
|
20
|
+
if (options === void 0) { options = {}; }
|
|
21
|
+
var valueStr = normalizeString(value);
|
|
22
|
+
var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.checkCode, cc = _b === void 0 ? true : _b;
|
|
23
|
+
var needCheckCode = !loose && cc;
|
|
24
|
+
var passBaseRule = baseReg.test(valueStr);
|
|
25
|
+
if (!needCheckCode || !passBaseRule) {
|
|
26
|
+
return passBaseRule;
|
|
27
|
+
}
|
|
28
|
+
var preCode = valueStr.substring(0, 17);
|
|
29
|
+
var lastCode = valueStr.substring(valueStr.length - 1);
|
|
30
|
+
var checkCode = sumCheckCode(preCode);
|
|
31
|
+
return lastCode === checkCode;
|
|
88
32
|
}
|
|
89
|
-
|
|
33
|
+
|
|
34
|
+
export { isSocialCreditCode as default };
|
package/esm/isSwiftCode.js
CHANGED
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
2
|
-
var reg = /^[A-Z]{6}[A-Z\d]{2}(?:[A-Z\d]{3})?$/;
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
* 检测值是否为 Swift Code。8位或11位,前6位为大写字母,7-8位为大写字母或数字,9-11位为可选的大写字母或数字。
|
|
6
|
-
*
|
|
7
|
-
* @static
|
|
8
|
-
* @alias module:Validator.isSwiftCode
|
|
9
|
-
* @since 4.9.0
|
|
10
|
-
* @see {@link https://zh.wikipedia.org/wiki/ISO_9362|ISO 9362}
|
|
11
|
-
* @param {*} value 要检测的值
|
|
12
|
-
* @returns {boolean} 值是否为 Swift Code
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* isSwiftCode('DEUTDEFF'); // true
|
|
16
|
-
* isSwiftCode('deutdeff'); // false
|
|
17
|
-
*
|
|
18
|
-
* isSwiftCode('BKTWTWTP010'); // true
|
|
19
|
-
* isSwiftCode('010BKTWTWTP'); // false
|
|
20
|
-
*
|
|
21
|
-
* isSwiftCode('ICBKCNBJBJM'); // true
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
3
|
+
var reg = /^[A-Z]{6}[A-Z\d]{2}(?:[A-Z\d]{3})?$/;
|
|
24
4
|
function isSwiftCode(value) {
|
|
25
|
-
|
|
26
|
-
|
|
5
|
+
var valueStr = normalizeString(value);
|
|
6
|
+
return reg.test(valueStr);
|
|
27
7
|
}
|
|
28
|
-
|
|
8
|
+
|
|
9
|
+
export { isSwiftCode as default };
|
package/esm/isTWCard.js
CHANGED
|
@@ -1,41 +1,15 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// 台湾居民来往大陆通行证正则
|
|
4
3
|
var regTWCard = /^\d{8}$/i;
|
|
5
|
-
|
|
6
|
-
// 一次性短期台胞证
|
|
7
4
|
var singleRegTWCard = /^[\da-z]{10,12}$/i;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* @param {*} value 要检测的值
|
|
17
|
-
* @param {Object} [options] 配置项
|
|
18
|
-
* @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
|
|
19
|
-
* @returns {boolean} 是否为台湾居民来往大陆通行证
|
|
20
|
-
* @example
|
|
21
|
-
*
|
|
22
|
-
* isTWCard('12345678'); // true
|
|
23
|
-
* isTWCard('07257456'); // true
|
|
24
|
-
*
|
|
25
|
-
* // 一次性短期
|
|
26
|
-
* isTWCard('F290299977'); // false
|
|
27
|
-
*
|
|
28
|
-
* // 宽松模式,支持一次性短期通行证
|
|
29
|
-
* isTWCard('F290299977', { loose: true }); // true
|
|
30
|
-
*/
|
|
31
|
-
function isTWCard(value) {
|
|
32
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
33
|
-
var _options$loose = options.loose,
|
|
34
|
-
loose = _options$loose === void 0 ? false : _options$loose;
|
|
35
|
-
var valueStr = normalizeString(value);
|
|
36
|
-
if (regTWCard.test(valueStr)) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
return loose ? singleRegTWCard.test(valueStr) : false;
|
|
5
|
+
function isTWCard(value, options) {
|
|
6
|
+
if (options === void 0) { options = {}; }
|
|
7
|
+
var _a = options.loose, loose = _a === void 0 ? false : _a;
|
|
8
|
+
var valueStr = normalizeString(value);
|
|
9
|
+
if (regTWCard.test(valueStr)) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return loose ? singleRegTWCard.test(valueStr) : false;
|
|
40
13
|
}
|
|
41
|
-
|
|
14
|
+
|
|
15
|
+
export { isTWCard as default };
|
package/esm/isTelephone.js
CHANGED
|
@@ -1,30 +1,9 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var reg = /^(0\d{2,3}\-)?([2-9]\d{6,7})(\-\d{1,6})?$/;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 检测值是否为固定电话
|
|
8
|
-
*
|
|
9
|
-
* @static
|
|
10
|
-
* @alias module:Validator.isTelephone
|
|
11
|
-
* @since 1.1.0
|
|
12
|
-
* @param {*} value 要检测的值
|
|
13
|
-
* @returns {boolean} 值是否为固定电话
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* isTelephone('22033212'); // true
|
|
17
|
-
* isTelephone('13000000000'); // false
|
|
18
|
-
*
|
|
19
|
-
* // 含区号
|
|
20
|
-
* isTelephone('021-22033212'); // true
|
|
21
|
-
*
|
|
22
|
-
* // 含区号和分机号
|
|
23
|
-
* isTelephone('021-22033212-123'); // true
|
|
24
|
-
*
|
|
25
|
-
*/
|
|
3
|
+
var reg = /^(0\d{2,3}-)?([2-9]\d{6,7})(-\d{1,6})?$/;
|
|
26
4
|
function isTelephone(value) {
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
var valueStr = normalizeString(value);
|
|
6
|
+
return reg.test(valueStr);
|
|
29
7
|
}
|
|
30
|
-
|
|
8
|
+
|
|
9
|
+
export { isTelephone as default };
|
package/esm/isUrl.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
2
|
-
|
|
3
|
-
// 标准格式如下:
|
|
4
|
-
// [协议类型]://[服务器地址]:[端口号]/[资源层级UNIX文件路径][文件名]?[查询]#[片段ID]
|
|
5
|
-
|
|
6
|
-
// 完整格式如下:
|
|
7
|
-
// [协议类型]://[访问资源需要的凭证信息]@[服务器地址]:[端口号]/[资源层级UNIX文件路径][文件名]?[查询]#[片段ID]
|
|
8
|
-
//
|
|
9
|
-
// 其中[访问凭证信息]、[端口号]、[查询]、[片段ID]都属于选填项。
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
10
2
|
|
|
11
3
|
var protocalReg = '[\\w-.]+:\\/\\/';
|
|
12
4
|
var credentialsReg = '[-;:&=\\+\\$,\\w]+@';
|
|
@@ -17,40 +9,9 @@ var searchReg = '\\?.*';
|
|
|
17
9
|
var hashReg = '#.*';
|
|
18
10
|
var regWithProtocal = new RegExp("^".concat(protocalReg, "(?:").concat(credentialsReg, ")?(?:").concat(serverReg, ")(?:").concat(portReg, ")?(?:").concat(pathReg, ")*(?:").concat(searchReg, ")?(?:").concat(hashReg, ")?$"));
|
|
19
11
|
var regNonProtocal = new RegExp("^(?:".concat(serverReg, ")(?:").concat(portReg, ")?(?:").concat(pathReg, ")*(?:").concat(searchReg, ")?(?:").concat(hashReg, ")?$"));
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 检测值是否为url
|
|
23
|
-
*
|
|
24
|
-
* @static
|
|
25
|
-
* @alias module:Validator.isUrl
|
|
26
|
-
* @since 3.4.0
|
|
27
|
-
* @see {@link https://zh.wikipedia.org/wiki/统一资源定位符|统一资源定位符}
|
|
28
|
-
* @param {*} value 要检测的值
|
|
29
|
-
* @returns {boolean} 值是否为url
|
|
30
|
-
* @example
|
|
31
|
-
*
|
|
32
|
-
* isUrl(''); // false
|
|
33
|
-
* isUrl('/foo/bar'); // false
|
|
34
|
-
*
|
|
35
|
-
* isUrl('8.8.8.8'); // true
|
|
36
|
-
* isUrl('example.com'); // true
|
|
37
|
-
* isUrl('http://example.com'); // true
|
|
38
|
-
* isUrl('https://example.com:8080'); // true
|
|
39
|
-
* isUrl('https://www.example.com/test/123'); // true
|
|
40
|
-
* isUrl('https://www.example.com/test/123?foo=bar'); // true
|
|
41
|
-
* isUrl('https://www.example.com/test/123?foo=中文#id'); // true
|
|
42
|
-
* isUrl('https://www.example.com/test/123?foo=中文#测试'); // true
|
|
43
|
-
* isUrl('ftp://127.0.0.1:8080/测试.tar'); // true
|
|
44
|
-
* isUrl('a.b'); // true
|
|
45
|
-
* isUrl('a.b:8080'); // true
|
|
46
|
-
* isUrl('p://a.b'); // true
|
|
47
|
-
* isUrl('p://a.b:8888'); // true
|
|
48
|
-
* isUrl('中文域名.中文后缀'); // true
|
|
49
|
-
* isUrl('中文域名.cn'); // true
|
|
50
|
-
*
|
|
51
|
-
*/
|
|
52
12
|
function isUrl(value) {
|
|
53
|
-
|
|
54
|
-
|
|
13
|
+
var valueStr = normalizeString(value);
|
|
14
|
+
return regWithProtocal.test(valueStr) || regNonProtocal.test(valueStr);
|
|
55
15
|
}
|
|
56
|
-
|
|
16
|
+
|
|
17
|
+
export { isUrl as default };
|
package/esm/isVehicle.js
CHANGED
|
@@ -1,32 +1,9 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// 车牌号正则
|
|
4
3
|
var reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})|([A-Z0-9]{5}[DF])|([DF][A-Z0-9]{5}))$/;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 检测值是否为车牌号,支持新能源和非新能源车牌
|
|
8
|
-
*
|
|
9
|
-
* @static
|
|
10
|
-
* @alias module:Validator.isVehicle
|
|
11
|
-
* @since 1.1.0
|
|
12
|
-
* @see {@link https://baike.baidu.com/item/车牌号|车牌号}
|
|
13
|
-
* @param {*} value 要检测的值
|
|
14
|
-
* @returns {boolean} 值是否为车牌号
|
|
15
|
-
* @example
|
|
16
|
-
*
|
|
17
|
-
* isVehicle('京L12345'); // true
|
|
18
|
-
* isVehicle('京L1234学'); // true
|
|
19
|
-
* isVehicle('BL1234警'); // true
|
|
20
|
-
*
|
|
21
|
-
* // 新能源车牌
|
|
22
|
-
* isVehicle('粤BD12345'); // true
|
|
23
|
-
* isVehicle('粤BF12345'); // true
|
|
24
|
-
* isVehicle('粤B12345D'); // true
|
|
25
|
-
* isVehicle('粤B12345F'); // true
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
4
|
function isVehicle(value) {
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
var valueStr = normalizeString(value);
|
|
6
|
+
return reg.test(valueStr);
|
|
31
7
|
}
|
|
32
|
-
|
|
8
|
+
|
|
9
|
+
export { isVehicle as default };
|