util-helpers 4.16.2 → 4.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/util-helpers.js +1600 -4039
- 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/validatePassword.js
CHANGED
|
@@ -1,262 +1,111 @@
|
|
|
1
|
-
import devWarn from './utils/devWarn';
|
|
1
|
+
import devWarn from './utils/devWarn.js';
|
|
2
|
+
|
|
2
3
|
var regNumber = /[\d]/;
|
|
3
4
|
var regLowerCaseLetter = /[a-z]/;
|
|
4
5
|
var regUpperCaseLetter = /[A-Z]/;
|
|
5
6
|
var regAllNumberAndLetter = /[\d|a-z]/gi;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 是否包含数字
|
|
9
|
-
*
|
|
10
|
-
* @private
|
|
11
|
-
* @param {string} val 检查的值
|
|
12
|
-
* @returns {boolean} 是否包含数字
|
|
13
|
-
*/
|
|
14
7
|
function hasNumber(val) {
|
|
15
|
-
|
|
8
|
+
return regNumber.test(val);
|
|
16
9
|
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 是否包含小写字母
|
|
20
|
-
*
|
|
21
|
-
* @private
|
|
22
|
-
* @param {string} val 检测的值
|
|
23
|
-
* @returns {boolean} 是否包含小写字母
|
|
24
|
-
*/
|
|
25
10
|
function hasLowerCaseLetter(val) {
|
|
26
|
-
|
|
11
|
+
return regLowerCaseLetter.test(val);
|
|
27
12
|
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 是否包含大写字母
|
|
31
|
-
*
|
|
32
|
-
* @private
|
|
33
|
-
* @param {string} val 检测的值
|
|
34
|
-
* @returns {boolean} 是否包含大写字母
|
|
35
|
-
*/
|
|
36
13
|
function hasUpperCaseLetter(val) {
|
|
37
|
-
|
|
14
|
+
return regUpperCaseLetter.test(val);
|
|
38
15
|
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 是否为十六进制
|
|
42
|
-
*
|
|
43
|
-
* @private
|
|
44
|
-
* @param {string} val 检测的值
|
|
45
|
-
* @returns {boolean} 是否为十六进制
|
|
46
|
-
*/
|
|
47
16
|
function hasHex(val) {
|
|
48
|
-
|
|
17
|
+
return val.indexOf('\\x') > -1 || val.indexOf('\\u') > -1;
|
|
49
18
|
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 是否包含特殊字符
|
|
53
|
-
*
|
|
54
|
-
* @private
|
|
55
|
-
* @param {string} val 检测的值
|
|
56
|
-
* @param {string} chars 特殊字符
|
|
57
|
-
* @returns {boolean} 是否包含特殊字符
|
|
58
|
-
*/
|
|
59
19
|
function hasSpecialCharacter(val, chars) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
var ret = false;
|
|
72
|
-
specialChars.split('').some(function (charItem) {
|
|
73
|
-
if (chars.indexOf(charItem) > -1) {
|
|
74
|
-
ret = true;
|
|
20
|
+
if (!chars || !val) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
var specialChars = val.replace(regAllNumberAndLetter, '');
|
|
24
|
+
if (!specialChars) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
var regChars = hasHex(chars) ? new RegExp("[".concat(chars, "]")) : null;
|
|
28
|
+
if (regChars) {
|
|
29
|
+
return regChars.test(specialChars);
|
|
75
30
|
}
|
|
31
|
+
var ret = false;
|
|
32
|
+
specialChars.split('').some(function (charItem) {
|
|
33
|
+
if (chars.indexOf(charItem) > -1) {
|
|
34
|
+
ret = true;
|
|
35
|
+
}
|
|
36
|
+
return ret;
|
|
37
|
+
});
|
|
76
38
|
return ret;
|
|
77
|
-
});
|
|
78
|
-
return ret;
|
|
79
39
|
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 是否包含非法字符
|
|
83
|
-
*
|
|
84
|
-
* @private
|
|
85
|
-
* @param {string} val 检测的值
|
|
86
|
-
* @param {string} chars 特殊字符
|
|
87
|
-
* @returns {boolean} 是否包含非法字符
|
|
88
|
-
*/
|
|
89
40
|
function hasUnallowableCharacter(val, chars) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
} else if (!chars) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
var regChars = hasHex(chars) ? new RegExp("[^".concat(chars, "]")) : null;
|
|
100
|
-
if (regChars) {
|
|
101
|
-
return regChars.test(specialChars);
|
|
102
|
-
}
|
|
103
|
-
var ret = false;
|
|
104
|
-
specialChars.split('').some(function (charItem) {
|
|
105
|
-
if (chars.indexOf(charItem) === -1) {
|
|
106
|
-
ret = true;
|
|
41
|
+
if (!val) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
var specialChars = val.replace(regAllNumberAndLetter, '');
|
|
45
|
+
if (!specialChars) {
|
|
46
|
+
return false;
|
|
107
47
|
}
|
|
48
|
+
else if (!chars) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
var regChars = hasHex(chars) ? new RegExp("[^".concat(chars, "]")) : null;
|
|
52
|
+
if (regChars) {
|
|
53
|
+
return regChars.test(specialChars);
|
|
54
|
+
}
|
|
55
|
+
var ret = false;
|
|
56
|
+
specialChars.split('').some(function (charItem) {
|
|
57
|
+
if (chars.indexOf(charItem) === -1) {
|
|
58
|
+
ret = true;
|
|
59
|
+
}
|
|
60
|
+
return ret;
|
|
61
|
+
});
|
|
108
62
|
return ret;
|
|
109
|
-
});
|
|
110
|
-
return ret;
|
|
111
63
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
* @property {boolean} unallowableCharacter - 包含非法字符
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @typedef {Object} ValidatePasswordReturn - 验证结果
|
|
124
|
-
* @property {boolean} validated - 验证结果,根据密码强度、是否包含非法字符得出
|
|
125
|
-
* @property {number} level - 强度级别,包含数字/大小写字母/特殊字符
|
|
126
|
-
* @property {PasswordContaines} containes - 包含内容
|
|
127
|
-
*/
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* 验证密码(数字、大小写字母、特殊字符、非法字符)
|
|
131
|
-
*
|
|
132
|
-
* @static
|
|
133
|
-
* @alias module:Validator.validatePassword
|
|
134
|
-
* @since 3.7.0
|
|
135
|
-
* @see {@link https://baike.baidu.com/item/ASCII#3|ASCII}
|
|
136
|
-
* @param {string} value 要检测的值
|
|
137
|
-
* @param {Object} [options] 配置项
|
|
138
|
-
* @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
|
|
139
|
-
* @param {boolean} [options.ignoreCase=false] 是否忽略大小写,为 ture 时,大小写字母视为一种字符
|
|
140
|
-
* @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符
|
|
141
|
-
* @returns {ValidatePasswordReturn} 验证结果
|
|
142
|
-
* @example
|
|
143
|
-
*
|
|
144
|
-
* validatePassword('a12345678');
|
|
145
|
-
* // =>
|
|
146
|
-
* {
|
|
147
|
-
* validated: true, // 验证结果,根据密码强度、是否包含非法字符得出
|
|
148
|
-
* level: 2, // 强度级别
|
|
149
|
-
* containes: {
|
|
150
|
-
* number: true, // 包含数字
|
|
151
|
-
* lowerCaseLetter: true, // 包含小写字母
|
|
152
|
-
* upperCaseLetter: false, // 包含大写字母
|
|
153
|
-
* specialCharacter: false, // 包含特殊字符
|
|
154
|
-
* unallowableCharacter: false // 包含非法字符
|
|
155
|
-
* }
|
|
156
|
-
* }
|
|
157
|
-
*
|
|
158
|
-
* validatePassword('a12345678', { level: 3 });
|
|
159
|
-
* // =>
|
|
160
|
-
* {
|
|
161
|
-
* validated: false,
|
|
162
|
-
* level: 2,
|
|
163
|
-
* containes: {
|
|
164
|
-
* number: true,
|
|
165
|
-
* lowerCaseLetter: true,
|
|
166
|
-
* upperCaseLetter: false,
|
|
167
|
-
* specialCharacter: false,
|
|
168
|
-
* unallowableCharacter: false
|
|
169
|
-
* }
|
|
170
|
-
* }
|
|
171
|
-
*
|
|
172
|
-
* validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true });
|
|
173
|
-
* // =>
|
|
174
|
-
* {
|
|
175
|
-
* validated: false,
|
|
176
|
-
* level: 3,
|
|
177
|
-
* containes: {
|
|
178
|
-
* number: true,
|
|
179
|
-
* lowerCaseLetter: true,
|
|
180
|
-
* upperCaseLetter: true,
|
|
181
|
-
* specialCharacter: true,
|
|
182
|
-
* unallowableCharacter: true
|
|
183
|
-
* }
|
|
184
|
-
* }
|
|
185
|
-
*
|
|
186
|
-
* // 自定义特殊字符
|
|
187
|
-
* validatePassword('_Aa一二三45678', { level: 3, ignoreCase: true, special: '_一二三' });
|
|
188
|
-
* // =>
|
|
189
|
-
* {
|
|
190
|
-
* validated: true,
|
|
191
|
-
* level: 3,
|
|
192
|
-
* containes: {
|
|
193
|
-
* number: true,
|
|
194
|
-
* lowerCaseLetter: true,
|
|
195
|
-
* upperCaseLetter: true,
|
|
196
|
-
* specialCharacter: true,
|
|
197
|
-
* unallowableCharacter: false
|
|
198
|
-
* }
|
|
199
|
-
* }
|
|
200
|
-
*/
|
|
201
|
-
function validatePassword(value) {
|
|
202
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
203
|
-
var _options$level = options.level,
|
|
204
|
-
level = _options$level === void 0 ? 2 : _options$level,
|
|
205
|
-
_options$ignoreCase = options.ignoreCase,
|
|
206
|
-
ignoreCase = _options$ignoreCase === void 0 ? false : _options$ignoreCase,
|
|
207
|
-
_options$special = options.special,
|
|
208
|
-
special = _options$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _options$special;
|
|
209
|
-
var valStr = value;
|
|
210
|
-
if (typeof value !== 'string') {
|
|
211
|
-
devWarn("[validatePassword] value must be a string.");
|
|
212
|
-
valStr = '';
|
|
213
|
-
}
|
|
214
|
-
var currentLevel = 0;
|
|
215
|
-
|
|
216
|
-
// 包含数字
|
|
217
|
-
var containesNumber = hasNumber(valStr);
|
|
218
|
-
// 包含小写字母
|
|
219
|
-
var containesLowerCaseLetter = hasLowerCaseLetter(valStr);
|
|
220
|
-
// 包含大写字母
|
|
221
|
-
var containesUpperCaseLetter = hasUpperCaseLetter(valStr);
|
|
222
|
-
// 包含特殊字符
|
|
223
|
-
var containesSpecialCharacter = hasSpecialCharacter(valStr, special);
|
|
224
|
-
// 包含非法字符,即含有非数字字母特殊字符以外的其他字符
|
|
225
|
-
var containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
|
|
226
|
-
if (containesNumber) {
|
|
227
|
-
currentLevel += 1;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// 不区分大小写
|
|
231
|
-
if (ignoreCase) {
|
|
232
|
-
if (containesLowerCaseLetter || containesUpperCaseLetter) {
|
|
233
|
-
currentLevel += 1;
|
|
64
|
+
function validatePassword(value, options) {
|
|
65
|
+
if (options === void 0) { options = {}; }
|
|
66
|
+
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;
|
|
67
|
+
var valStr = value;
|
|
68
|
+
if (typeof value !== 'string') {
|
|
69
|
+
devWarn("[validatePassword] value must be a string.");
|
|
70
|
+
valStr = '';
|
|
234
71
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
72
|
+
var currentLevel = 0;
|
|
73
|
+
var containesNumber = hasNumber(valStr);
|
|
74
|
+
var containesLowerCaseLetter = hasLowerCaseLetter(valStr);
|
|
75
|
+
var containesUpperCaseLetter = hasUpperCaseLetter(valStr);
|
|
76
|
+
var containesSpecialCharacter = hasSpecialCharacter(valStr, special);
|
|
77
|
+
var containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
|
|
78
|
+
if (containesNumber) {
|
|
79
|
+
currentLevel += 1;
|
|
239
80
|
}
|
|
240
|
-
if (
|
|
241
|
-
|
|
81
|
+
if (ignoreCase) {
|
|
82
|
+
if (containesLowerCaseLetter || containesUpperCaseLetter) {
|
|
83
|
+
currentLevel += 1;
|
|
84
|
+
}
|
|
242
85
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
validated: validated,
|
|
252
|
-
level: currentLevel,
|
|
253
|
-
containes: {
|
|
254
|
-
number: containesNumber,
|
|
255
|
-
lowerCaseLetter: containesLowerCaseLetter,
|
|
256
|
-
upperCaseLetter: containesUpperCaseLetter,
|
|
257
|
-
specialCharacter: containesSpecialCharacter,
|
|
258
|
-
unallowableCharacter: containesUnallowableCharacter
|
|
86
|
+
else {
|
|
87
|
+
if (containesLowerCaseLetter) {
|
|
88
|
+
currentLevel += 1;
|
|
89
|
+
}
|
|
90
|
+
if (containesUpperCaseLetter) {
|
|
91
|
+
currentLevel += 1;
|
|
92
|
+
}
|
|
259
93
|
}
|
|
260
|
-
|
|
94
|
+
if (containesSpecialCharacter) {
|
|
95
|
+
currentLevel += 1;
|
|
96
|
+
}
|
|
97
|
+
var validated = currentLevel >= level && !containesUnallowableCharacter;
|
|
98
|
+
return {
|
|
99
|
+
validated: validated,
|
|
100
|
+
level: currentLevel,
|
|
101
|
+
containes: {
|
|
102
|
+
number: containesNumber,
|
|
103
|
+
lowerCaseLetter: containesLowerCaseLetter,
|
|
104
|
+
upperCaseLetter: containesUpperCaseLetter,
|
|
105
|
+
specialCharacter: containesSpecialCharacter,
|
|
106
|
+
unallowableCharacter: containesUnallowableCharacter
|
|
107
|
+
}
|
|
108
|
+
};
|
|
261
109
|
}
|
|
262
|
-
|
|
110
|
+
|
|
111
|
+
export { validatePassword as default };
|
package/esm/waitTime.js
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @since 4.2.0
|
|
7
|
-
* @param {number} [time=1000] 延时时间,单位毫秒
|
|
8
|
-
* @returns {Promise<void>}
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* const test = async ()=>{
|
|
12
|
-
* await waitTime();
|
|
13
|
-
* // do something
|
|
14
|
-
* }
|
|
15
|
-
*
|
|
16
|
-
* waitTime(500).then(()=>{
|
|
17
|
-
* // do something
|
|
18
|
-
* });
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
function waitTime() {
|
|
22
|
-
var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
|
|
23
|
-
return new Promise(function (resolve) {
|
|
24
|
-
setTimeout(resolve, time);
|
|
25
|
-
});
|
|
1
|
+
function waitTime(time) {
|
|
2
|
+
if (time === void 0) { time = 1000; }
|
|
3
|
+
return new Promise(function (resolve) {
|
|
4
|
+
setTimeout(resolve, time);
|
|
5
|
+
});
|
|
26
6
|
}
|
|
27
|
-
|
|
7
|
+
|
|
8
|
+
export { waitTime as default };
|
package/lib/ajax.js
CHANGED
|
@@ -1,156 +1,55 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {XMLHttpRequest['onloadstart']} XMLHttpRequestEvent XMLHttpRequest 事件对象
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
|
|
14
|
-
* @typedef {Object} AjaxOptions ajax配置项
|
|
15
|
-
* @property {string} [method="get"] 创建请求时使用的方法
|
|
16
|
-
* @property {Document | XMLHttpRequestBodyInit | null} [data=null] 请求体被发送的数据
|
|
17
|
-
* @property {Object.<string, string>} [headers] 自定义请求头
|
|
18
|
-
* @property {XMLHttpRequestResponseType} [responseType] 响应类型
|
|
19
|
-
* @property {number} [timeout] 请求超时的毫秒数
|
|
20
|
-
* @property {boolean} [withCredentials=false] 跨域请求时是否需要使用凭证
|
|
21
|
-
* @property {boolean} [async=true] 是否异步执行操作
|
|
22
|
-
* @property {string|null} [user=null] 用户名,用于认证用途
|
|
23
|
-
* @property {string|null} [password=null] 密码,用于认证用途
|
|
24
|
-
* @property {XMLHttpRequestEvent} [onLoadStart] 接收到响应数据时触发
|
|
25
|
-
* @property {XMLHttpRequestEvent} [onProgress] 请求接收到更多数据时,周期性地触发
|
|
26
|
-
* @property {XMLHttpRequestEvent} [onAbort] 当 request 被停止时触发,例如当程序调用 XMLHttpRequest.abort() 时
|
|
27
|
-
* @property {XMLHttpRequestEvent} [onTimeout] 在预设时间内没有接收到响应时触发
|
|
28
|
-
* @property {XMLHttpRequestEvent} [onError] 当 request 遭遇错误时触发
|
|
29
|
-
* @property {XMLHttpRequestEvent} [onLoad] 请求成功完成时触发
|
|
30
|
-
* @property {XMLHttpRequestEvent} [onLoadEnd] 请求结束时触发,无论请求成功 (load) 还是失败 (abort 或 error)
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 请求<br/><br/>
|
|
35
|
-
*
|
|
36
|
-
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
37
|
-
*
|
|
38
|
-
* @static
|
|
39
|
-
* @alias module:Other.ajax
|
|
40
|
-
* @since 4.16.0
|
|
41
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
|
|
42
|
-
* @param {string} url 地址
|
|
43
|
-
* @param {AjaxOptions} [options] 配置项
|
|
44
|
-
* @returns {Promise<ProgressEvent<EventTarget>>}
|
|
45
|
-
* @example
|
|
46
|
-
* ajax('/somefile').then(res=>{
|
|
47
|
-
* // do something
|
|
48
|
-
* });
|
|
49
|
-
*
|
|
50
|
-
* ajax('/api', { method: 'post' }).then(res=>{
|
|
51
|
-
* // do something
|
|
52
|
-
* });
|
|
53
|
-
*/
|
|
54
3
|
function ajax(url, options) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
* 请求成功异步调用
|
|
104
|
-
* @param {XMLHttpRequestEvent} [cb] 回调方法
|
|
105
|
-
*/
|
|
106
|
-
var wrapSuccess = function wrapSuccess(cb) {
|
|
107
|
-
/**
|
|
108
|
-
* 内部方法
|
|
109
|
-
* @param {ProgressEvent<EventTarget>} e 事件对象
|
|
110
|
-
*/
|
|
111
|
-
return function (e) {
|
|
112
|
-
resolve(e);
|
|
113
|
-
cb === null || cb === void 0 ? void 0 : cb.call(xhr, e);
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* 请求失败(中断/超时/失败)处理
|
|
119
|
-
* @param {XMLHttpRequestEvent} [cb] 回调方法
|
|
120
|
-
*/
|
|
121
|
-
var wrapError = function wrapError(cb) {
|
|
122
|
-
/**
|
|
123
|
-
* 内部方法
|
|
124
|
-
* @param {ProgressEvent<EventTarget>} e 事件对象
|
|
125
|
-
*/
|
|
126
|
-
return function (e) {
|
|
127
|
-
reject(e);
|
|
128
|
-
cb === null || cb === void 0 ? void 0 : cb.call(xhr, e);
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// 事件处理
|
|
133
|
-
/**@type {Object.<keyof XMLHttpRequestEventTargetEventMap, XMLHttpRequestEvent | undefined>} */
|
|
134
|
-
var events = {
|
|
135
|
-
loadstart: onLoadStart,
|
|
136
|
-
progress: onProgress,
|
|
137
|
-
abort: wrapError(onAbort),
|
|
138
|
-
timeout: wrapError(onTimeout),
|
|
139
|
-
error: wrapError(onError),
|
|
140
|
-
load: wrapSuccess(onLoad),
|
|
141
|
-
loadend: onLoadEnd
|
|
142
|
-
};
|
|
143
|
-
/**@type {(keyof XMLHttpRequestEventTargetEventMap)[]} */
|
|
144
|
-
// @ts-ignore
|
|
145
|
-
var eventNames = Object.keys(events);
|
|
146
|
-
eventNames.map(function (item) {
|
|
147
|
-
var func = events[item];
|
|
148
|
-
if (func) {
|
|
149
|
-
xhr.addEventListener(item, func);
|
|
150
|
-
}
|
|
4
|
+
var _a = options || {}, _b = _a.method, method = _b === void 0 ? 'get' : _b, _c = _a.data, data = _c === void 0 ? null : _c, timeout = _a.timeout, headers = _a.headers, _d = _a.withCredentials, withCredentials = _d === void 0 ? false : _d, _e = _a.async, async = _e === void 0 ? true : _e, _f = _a.user, user = _f === void 0 ? null : _f, _g = _a.password, password = _g === void 0 ? null : _g, responseType = _a.responseType, onReadyStateChange = _a.onReadyStateChange, onLoadStart = _a.onLoadStart, onProgress = _a.onProgress, onAbort = _a.onAbort, onTimeout = _a.onTimeout, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd;
|
|
5
|
+
return new Promise(function (resolve, reject) {
|
|
6
|
+
var xhr = new XMLHttpRequest();
|
|
7
|
+
xhr.open(method.toLowerCase(), url, async, user, password);
|
|
8
|
+
if (onReadyStateChange) {
|
|
9
|
+
xhr.onreadystatechange = onReadyStateChange;
|
|
10
|
+
}
|
|
11
|
+
if (typeof timeout === 'number' && timeout > 0) {
|
|
12
|
+
xhr.timeout = timeout;
|
|
13
|
+
}
|
|
14
|
+
xhr.withCredentials = withCredentials;
|
|
15
|
+
if (responseType) {
|
|
16
|
+
xhr.responseType = responseType;
|
|
17
|
+
}
|
|
18
|
+
if (typeof headers === 'object') {
|
|
19
|
+
Object.keys(headers).map(function (item) {
|
|
20
|
+
xhr.setRequestHeader(item, headers[item]);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
var wrapSuccess = function (cb) {
|
|
24
|
+
return function (e) {
|
|
25
|
+
resolve(e);
|
|
26
|
+
cb === null || cb === void 0 ? void 0 : cb.call(xhr, e);
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
var wrapError = function (cb) {
|
|
30
|
+
return function (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
cb === null || cb === void 0 ? void 0 : cb.call(xhr, e);
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
var events = {
|
|
36
|
+
loadstart: onLoadStart,
|
|
37
|
+
progress: onProgress,
|
|
38
|
+
abort: wrapError(onAbort),
|
|
39
|
+
timeout: wrapError(onTimeout),
|
|
40
|
+
error: wrapError(onError),
|
|
41
|
+
load: wrapSuccess(onLoad),
|
|
42
|
+
loadend: onLoadEnd
|
|
43
|
+
};
|
|
44
|
+
var eventKeys = Object.keys(events);
|
|
45
|
+
eventKeys.map(function (item) {
|
|
46
|
+
var func = events[item];
|
|
47
|
+
if (func) {
|
|
48
|
+
xhr.addEventListener(item, func);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
xhr.send(data);
|
|
151
52
|
});
|
|
152
|
-
xhr.send(data);
|
|
153
|
-
});
|
|
154
53
|
}
|
|
155
|
-
|
|
156
|
-
exports
|
|
54
|
+
|
|
55
|
+
module.exports = ajax;
|
package/lib/blobToDataURL.js
CHANGED
|
@@ -1,44 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _fileReader = _interopRequireDefault(require("./fileReader"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
9
|
-
// file、blob文件如何预览图片?
|
|
10
|
-
// 方法1:将file或者blob类型文件转成base64数据,再作为src赋值给img标签
|
|
11
|
-
// 方法2:使用 window.URL.createObjectURL(blob) 为blob、file 创建一个指向该参数对象的URL
|
|
3
|
+
var fileReader = require('./fileReader.js');
|
|
12
4
|
|
|
13
|
-
/**
|
|
14
|
-
* 将 Blob 或 File 对象转成 data:URL 格式的 Base64 字符串<br/><br/>
|
|
15
|
-
*
|
|
16
|
-
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
17
|
-
*
|
|
18
|
-
* @ignore
|
|
19
|
-
* @static
|
|
20
|
-
* @alias module:Processor.blobToDataURL
|
|
21
|
-
* @since 4.1.0
|
|
22
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL|FileReader.readAsDataURL()}
|
|
23
|
-
* @deprecated 请使用 `fileReader` 方法
|
|
24
|
-
* @param {Blob} blob Blob 或 File 对象
|
|
25
|
-
* @returns {Promise<string>} data:URL 格式的 Base64 字符串。
|
|
26
|
-
* @example
|
|
27
|
-
* const aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // 一个包含DOMString的数组
|
|
28
|
-
* const htmlBlob = new Blob(aFileParts, { type: 'text/html' }); // 得到 blob
|
|
29
|
-
*
|
|
30
|
-
* blobToDataURL(htmlBlob).then(data=>{
|
|
31
|
-
* console.log(data); // data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* const textBlob = new Blob(aFileParts, { type: 'text/plain' });
|
|
35
|
-
*
|
|
36
|
-
* blobToDataURL(textBlob).then(data=>{
|
|
37
|
-
* console.log(data); // data:text/plain;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
|
|
38
|
-
* });
|
|
39
|
-
*/
|
|
40
5
|
function blobToDataURL(blob) {
|
|
41
|
-
|
|
6
|
+
return fileReader(blob);
|
|
42
7
|
}
|
|
43
|
-
|
|
44
|
-
exports
|
|
8
|
+
|
|
9
|
+
module.exports = blobToDataURL;
|