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/index.js
CHANGED
|
@@ -1,130 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export { default as
|
|
8
|
-
export { default as
|
|
9
|
-
export { default as
|
|
10
|
-
export { default as
|
|
11
|
-
export { default as
|
|
12
|
-
export { default as
|
|
13
|
-
export { default as
|
|
14
|
-
export { default as
|
|
15
|
-
export { default as
|
|
16
|
-
export { default as
|
|
17
|
-
export { default as
|
|
18
|
-
export { default as
|
|
19
|
-
export { default as
|
|
20
|
-
export { default as
|
|
21
|
-
export { default as
|
|
22
|
-
export { default as
|
|
23
|
-
export { default as
|
|
24
|
-
export { default as
|
|
25
|
-
export { default as
|
|
26
|
-
export { default as
|
|
27
|
-
export { default as
|
|
28
|
-
export { default as
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export { default as
|
|
37
|
-
export { default as
|
|
38
|
-
export { default as
|
|
39
|
-
export { default as
|
|
40
|
-
export { default as
|
|
41
|
-
export { default as
|
|
42
|
-
export { default as
|
|
43
|
-
export { default as
|
|
44
|
-
export { default as
|
|
45
|
-
export { default as
|
|
46
|
-
export { default as
|
|
47
|
-
export { default as
|
|
48
|
-
export { default as
|
|
49
|
-
export { default as
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* @see {@link https://github.com/camsong/blog/issues/9|JavaScript 浮点数陷阱及解法}
|
|
57
|
-
* @see {@link https://2zbuy.csb.app/|JS浮点数计算测试}
|
|
58
|
-
* @example
|
|
59
|
-
* // 从 4.12.0 版本开始,规范了有效数值。(注意:4.12.3 对有效数值重新定义)
|
|
60
|
-
* // 有效数值即能通过 Number(value) 转为数字,且不能为 NaN 。
|
|
61
|
-
*
|
|
62
|
-
* // 以下为有效数值:
|
|
63
|
-
* // 1. 数字: 1, -1, 1e-2, 1.312, 0.1, Infinity
|
|
64
|
-
* // 2. 字符串: '1', '10e2', '-1', '0.1', '', ' ', ' 15', ' 15 '
|
|
65
|
-
* // 4. 其他类型: null, new Date(), [], new Array(), true, false,...
|
|
66
|
-
*
|
|
67
|
-
* // 以下为无效数值:
|
|
68
|
-
* // 1. 字符串: '1a', '-12a', '10.2.2', '10e2.1'
|
|
69
|
-
* // 2. 其他类型: undefined, [], {}, Symbol(), function(){}, ()=>{}
|
|
70
|
-
*
|
|
71
|
-
* // 计算说明:
|
|
72
|
-
* // 四则运算的第二个参数都是有默认值(乘数和除数默认1,加数和减数默认0)
|
|
73
|
-
* plus(); // NaN 0个参数时,被加数转换为 Number(undefined) NaN ,NaN+0 = NaN 。其他计算方法如果没有参数一样返回 NaN 。
|
|
74
|
-
* plus(0.1); // 0.1 第二个参数,加数默认为 0
|
|
75
|
-
* plus(undefined, 0.1); // NaN 第一个参数被加数转换为 Number(undefined) NaN ,NaN+0 = NaN 。其他计算方法如果第一个参数为无效数值一样返回 NaN 。
|
|
76
|
-
* plus(true, null); // 1 Number(true) 转换为 1 , Number(null) 转换为 0 , 1+0=1
|
|
77
|
-
*
|
|
78
|
-
* // 2. 参数中包含无效数值,返回NaN
|
|
79
|
-
* plus('0.1', ' a'); // NaN
|
|
80
|
-
* plus(true, {}); // NaN
|
|
81
|
-
* plus(true, 0.1, Symbol()); // NaN
|
|
82
|
-
*
|
|
83
|
-
* // 注意:
|
|
84
|
-
* // 如果第二个及后面的参数如果值为 undefined 取默认值,即乘除数取 1 ,加减法取 0 。
|
|
85
|
-
* plus(0.1, undefined); // 0.1
|
|
86
|
-
* plus(0.1, undefined, 0.2, undefined); // 0.3 后面的 undefined 取默认值 0
|
|
87
|
-
* times(0.1, undefined, 0.2, undefined); // 0.02 后面的 undefined 取默认值 1
|
|
88
|
-
*
|
|
89
|
-
*/
|
|
90
|
-
export { default as plus } from './plus';
|
|
91
|
-
export { default as minus } from './minus';
|
|
92
|
-
export { default as times } from './times';
|
|
93
|
-
export { default as divide } from './divide';
|
|
94
|
-
export { default as round } from './round';
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 其他
|
|
98
|
-
*
|
|
99
|
-
* @module Other
|
|
100
|
-
* @since 4.2.0
|
|
101
|
-
*/
|
|
102
|
-
export { default as ajax } from './ajax';
|
|
103
|
-
export { default as calculateCursorPosition } from './calculateCursorPosition';
|
|
104
|
-
export { default as download } from './download';
|
|
105
|
-
export { default as randomString } from './randomString';
|
|
106
|
-
export { default as strlen } from './strlen';
|
|
107
|
-
export { default as waitTime } from './waitTime';
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* 树结构数据查询、过滤、转换等处理方法
|
|
111
|
-
*
|
|
112
|
-
* @module Tree
|
|
113
|
-
* @since 4.14.0
|
|
114
|
-
*/
|
|
115
|
-
export { default as transformFieldNames } from './transformFieldNames';
|
|
116
|
-
export { default as listToTree } from './listToTree';
|
|
117
|
-
export { default as treeToList } from './treeToList';
|
|
118
|
-
export { default as filterTree } from './filterTree';
|
|
119
|
-
export { default as findTreeNode } from './findTreeNode';
|
|
120
|
-
export { default as findTreeNodes } from './findTreeNodes';
|
|
121
|
-
export { default as findTreeSelect } from './findTreeSelect';
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 调试相关
|
|
125
|
-
*
|
|
126
|
-
* @module Debug
|
|
127
|
-
* @ignore
|
|
128
|
-
* @since 3.6.1
|
|
129
|
-
*/
|
|
130
|
-
export { setDisableWarning, version } from './utils/config';
|
|
1
|
+
export { default as isMobile } from './isMobile.js';
|
|
2
|
+
export { default as isTelephone } from './isTelephone.js';
|
|
3
|
+
export { default as isPostcode } from './isPostcode.js';
|
|
4
|
+
export { default as isIdCard } from './isIdCard.js';
|
|
5
|
+
export { default as isEmail } from './isEmail.js';
|
|
6
|
+
export { default as isQQ } from './isQQ.js';
|
|
7
|
+
export { default as isWX } from './isWX.js';
|
|
8
|
+
export { default as isVehicle } from './isVehicle.js';
|
|
9
|
+
export { default as isBankCard } from './isBankCard.js';
|
|
10
|
+
export { default as isSocialCreditCode } from './isSocialCreditCode.js';
|
|
11
|
+
export { default as isPassword } from './isPassword.js';
|
|
12
|
+
export { default as isPassport } from './isPassport.js';
|
|
13
|
+
export { default as isChinese } from './isChinese.js';
|
|
14
|
+
export { default as isIPv4 } from './isIPv4.js';
|
|
15
|
+
export { default as isIPv6 } from './isIPv6.js';
|
|
16
|
+
export { default as isUrl } from './isUrl.js';
|
|
17
|
+
export { default as isBusinessLicense } from './isBusinessLicense.js';
|
|
18
|
+
export { default as validatePassword } from './validatePassword.js';
|
|
19
|
+
export { default as isPromiseLike } from './isPromiseLike.js';
|
|
20
|
+
export { default as isHMCard } from './isHMCard.js';
|
|
21
|
+
export { default as isTWCard } from './isTWCard.js';
|
|
22
|
+
export { default as isSwiftCode } from './isSwiftCode.js';
|
|
23
|
+
export { default as formatMoney } from './formatMoney.js';
|
|
24
|
+
export { default as formatBankCard } from './formatBankCard.js';
|
|
25
|
+
export { default as replaceChar } from './replaceChar.js';
|
|
26
|
+
export { default as numberToChinese } from './numberToChinese.js';
|
|
27
|
+
export { default as bytesToSize } from './bytesToSize.js';
|
|
28
|
+
export { default as parseIdCard } from './parseIdCard.js';
|
|
29
|
+
export { default as blobToDataURL } from './blobToDataURL.js';
|
|
30
|
+
export { default as fileReader } from './fileReader.js';
|
|
31
|
+
export { default as dataURLToBlob } from './dataURLToBlob.js';
|
|
32
|
+
export { default as setDataURLPrefix } from './setDataURLPrefix.js';
|
|
33
|
+
export { default as normalizeString } from './normalizeString.js';
|
|
34
|
+
export { default as safeDate } from './safeDate.js';
|
|
35
|
+
export { default as formatMobile } from './formatMobile.js';
|
|
36
|
+
export { default as padZero } from './padZero.js';
|
|
37
|
+
export { default as plus } from './plus.js';
|
|
38
|
+
export { default as minus } from './minus.js';
|
|
39
|
+
export { default as times } from './times.js';
|
|
40
|
+
export { default as divide } from './divide.js';
|
|
41
|
+
export { default as round } from './round.js';
|
|
42
|
+
export { default as ajax } from './ajax.js';
|
|
43
|
+
export { default as calculateCursorPosition } from './calculateCursorPosition.js';
|
|
44
|
+
export { default as download } from './download.js';
|
|
45
|
+
export { default as randomString } from './randomString.js';
|
|
46
|
+
export { default as strlen } from './strlen.js';
|
|
47
|
+
export { default as waitTime } from './waitTime.js';
|
|
48
|
+
export { default as transformFieldNames } from './transformFieldNames.js';
|
|
49
|
+
export { default as listToTree } from './listToTree.js';
|
|
50
|
+
export { default as treeToList } from './treeToList.js';
|
|
51
|
+
export { default as filterTree } from './filterTree.js';
|
|
52
|
+
export { default as findTreeNode } from './findTreeNode.js';
|
|
53
|
+
export { default as findTreeNodes } from './findTreeNodes.js';
|
|
54
|
+
export { default as findTreeSelect } from './findTreeSelect.js';
|
|
55
|
+
export { setDisableWarning, version } from './utils/config.js';
|
package/esm/isBankCard.js
CHANGED
|
@@ -1,63 +1,28 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// 非0开头,10~21位数字
|
|
4
3
|
var reg = /^[1-9]\d{9,20}$/;
|
|
5
|
-
|
|
6
|
-
// 8~30位数字
|
|
7
4
|
var regLoose = /^\d{8,30}$/;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* luhn 计算校验位
|
|
11
|
-
* @private
|
|
12
|
-
* @param {string} numStr 银行卡前面数字
|
|
13
|
-
* @returns {number}
|
|
14
|
-
*/
|
|
15
5
|
function sumCheckCode(numStr) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
var numArr = (numStr + '').replace(/\D/g, '').split('').reverse();
|
|
7
|
+
var sum = 0;
|
|
8
|
+
for (var i = 0; i < numArr.length; i++) {
|
|
9
|
+
var currNum = parseInt(numArr[i]);
|
|
10
|
+
sum += i % 2 === 0 ? currNum * 2 - (currNum > 4 ? 9 : 0) : currNum;
|
|
11
|
+
}
|
|
12
|
+
var mod = sum % 10;
|
|
13
|
+
return mod !== 0 ? 10 - mod : 0;
|
|
24
14
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* @param {boolean} [options.luhn=false] 使用 Luhn 算法校验校验码
|
|
37
|
-
* @returns {boolean} 值是否为银行卡号
|
|
38
|
-
* @example
|
|
39
|
-
*
|
|
40
|
-
* isBankCard('6228480402564890018'); // true
|
|
41
|
-
* isBankCard('6228480402564890'); // true
|
|
42
|
-
* isBankCard('123456789'); // false
|
|
43
|
-
*
|
|
44
|
-
* // 宽松模式
|
|
45
|
-
* isBankCard('123456789', { loose: true }); // true
|
|
46
|
-
*
|
|
47
|
-
*/
|
|
48
|
-
function isBankCard(value) {
|
|
49
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
50
|
-
var _options$loose = options.loose,
|
|
51
|
-
loose = _options$loose === void 0 ? false : _options$loose,
|
|
52
|
-
_options$luhn = options.luhn,
|
|
53
|
-
luhn = _options$luhn === void 0 ? false : _options$luhn;
|
|
54
|
-
var valueStr = normalizeString(value);
|
|
55
|
-
var validateResult = loose ? regLoose.test(valueStr) : reg.test(valueStr);
|
|
56
|
-
if (validateResult && luhn) {
|
|
57
|
-
var precode = valueStr.substring(0, valueStr.length - 1);
|
|
58
|
-
var checkCode = valueStr[valueStr.length - 1];
|
|
59
|
-
return checkCode === String(sumCheckCode(precode));
|
|
60
|
-
}
|
|
61
|
-
return validateResult;
|
|
15
|
+
function isBankCard(value, options) {
|
|
16
|
+
if (options === void 0) { options = {}; }
|
|
17
|
+
var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.luhn, luhn = _b === void 0 ? false : _b;
|
|
18
|
+
var valueStr = normalizeString(value);
|
|
19
|
+
var validateResult = loose ? regLoose.test(valueStr) : reg.test(valueStr);
|
|
20
|
+
if (validateResult && luhn) {
|
|
21
|
+
var precode = valueStr.substring(0, valueStr.length - 1);
|
|
22
|
+
var checkCode = valueStr[valueStr.length - 1];
|
|
23
|
+
return checkCode === String(sumCheckCode(precode));
|
|
24
|
+
}
|
|
25
|
+
return validateResult;
|
|
62
26
|
}
|
|
63
|
-
|
|
27
|
+
|
|
28
|
+
export { isBankCard as default };
|
package/esm/isBusinessLicense.js
CHANGED
|
@@ -1,83 +1,37 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// 基础规则,由14位数字本体码和1位数字校验码组成,其中本体码从左至右依次为:6位首次登记机关码、8位顺序码。
|
|
4
3
|
var baseReg = /^\d{15}$/;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 计算校验码
|
|
8
|
-
*
|
|
9
|
-
* @private
|
|
10
|
-
* @since 3.5.0
|
|
11
|
-
* @param {string} preCode 营业执照前14位
|
|
12
|
-
* @returns {number} 校验码
|
|
13
|
-
*/
|
|
14
4
|
function sumCheckCode(preCode) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
pj
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
retNum = 11 - pj;
|
|
32
|
-
}
|
|
33
|
-
return retNum;
|
|
5
|
+
var retNum;
|
|
6
|
+
var pj = 10;
|
|
7
|
+
for (var j = 0; j < 14; j++) {
|
|
8
|
+
var sj = pj + Number(preCode[j]);
|
|
9
|
+
var sj10 = sj % 10;
|
|
10
|
+
sj10 = sj10 === 0 ? 10 : sj10;
|
|
11
|
+
var pj1 = sj10 * 2;
|
|
12
|
+
pj = pj1 % 11;
|
|
13
|
+
}
|
|
14
|
+
if (pj === 1) {
|
|
15
|
+
retNum = 0;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
retNum = 11 - pj;
|
|
19
|
+
}
|
|
20
|
+
return retNum;
|
|
34
21
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
* isBusinessLicense('310115600985533'); // true
|
|
50
|
-
* isBusinessLicense('310115600985535'); // false
|
|
51
|
-
*
|
|
52
|
-
* // 不校验验证码,长度和类型还是有校验
|
|
53
|
-
* isBusinessLicense('310115600985535', { checkCode: false }); // true
|
|
54
|
-
* isBusinessLicense('ac115600985535', { checkCode: false }); // false
|
|
55
|
-
* isBusinessLicense('31011560098', { checkCode: false }); // false
|
|
56
|
-
*
|
|
57
|
-
*/
|
|
58
|
-
function isBusinessLicense(value) {
|
|
59
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
60
|
-
var valueStr = normalizeString(value);
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
// TODO 下个版本废弃 loose
|
|
63
|
-
var _options$loose = options.loose,
|
|
64
|
-
loose = _options$loose === void 0 ? false : _options$loose,
|
|
65
|
-
_options$checkCode = options.checkCode,
|
|
66
|
-
cc = _options$checkCode === void 0 ? true : _options$checkCode;
|
|
67
|
-
var needCheckCode = !loose && cc;
|
|
68
|
-
var passBaseRule = baseReg.test(valueStr);
|
|
69
|
-
|
|
70
|
-
// 宽松模式 或 基础规则不通过直接返回
|
|
71
|
-
if (!needCheckCode || !passBaseRule) {
|
|
72
|
-
return passBaseRule;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 前14位
|
|
76
|
-
var preCode = valueStr.substring(0, 14);
|
|
77
|
-
// 校验码
|
|
78
|
-
var lastCode = valueStr.substring(valueStr.length - 1);
|
|
79
|
-
// 计算校验码
|
|
80
|
-
var checkCode = sumCheckCode(preCode);
|
|
81
|
-
return lastCode === String(checkCode);
|
|
22
|
+
function isBusinessLicense(value, options) {
|
|
23
|
+
if (options === void 0) { options = {}; }
|
|
24
|
+
var valueStr = normalizeString(value);
|
|
25
|
+
var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.checkCode, cc = _b === void 0 ? true : _b;
|
|
26
|
+
var needCheckCode = !loose && cc;
|
|
27
|
+
var passBaseRule = baseReg.test(valueStr);
|
|
28
|
+
if (!needCheckCode || !passBaseRule) {
|
|
29
|
+
return passBaseRule;
|
|
30
|
+
}
|
|
31
|
+
var preCode = valueStr.substring(0, 14);
|
|
32
|
+
var lastCode = valueStr.substring(valueStr.length - 1);
|
|
33
|
+
var checkCode = sumCheckCode(preCode);
|
|
34
|
+
return lastCode === String(checkCode);
|
|
82
35
|
}
|
|
83
|
-
|
|
36
|
+
|
|
37
|
+
export { isBusinessLicense as default };
|
package/esm/isChinese.js
CHANGED
|
@@ -1,75 +1,32 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
|
+
|
|
2
3
|
var chineseDictionary = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// 汉字扩展C
|
|
12
|
-
chineseExtendC: "[\uD869\uDF00-\uD86D\uDF34]",
|
|
13
|
-
// 汉字扩展D
|
|
14
|
-
chineseExtendD: "[\uD86D\uDF40-\uD86E\uDC1D]",
|
|
15
|
-
// 汉字扩展E
|
|
16
|
-
chineseExtendE: "[\uD86E\uDC20-\uD873\uDEA1]",
|
|
17
|
-
// 汉字扩展F
|
|
18
|
-
chineseExtendF: "[\uD873\uDEB0-\uD87A\uDFE0]"
|
|
4
|
+
chineseBasic: '[\u4e00-\u9fa5]',
|
|
5
|
+
chineseExtend: '[\u9ea6-\u9fef]',
|
|
6
|
+
chineseExtendA: '[\u3400-\u4DB5]',
|
|
7
|
+
chineseExtendB: "[\uD840\uDC00-\uD869\uDED6]",
|
|
8
|
+
chineseExtendC: "[\uD869\uDF00-\uD86D\uDF34]",
|
|
9
|
+
chineseExtendD: "[\uD86D\uDF40-\uD86E\uDC1D]",
|
|
10
|
+
chineseExtendE: "[\uD86E\uDC20-\uD873\uDEA1]",
|
|
11
|
+
chineseExtendF: "[\uD873\uDEB0-\uD87A\uDFE0]"
|
|
19
12
|
};
|
|
20
13
|
var looseChineseRegExp = chineseDictionary.chineseBasic + '+';
|
|
21
14
|
var chineseRegExp = '^' + chineseDictionary.chineseBasic + '+$';
|
|
22
15
|
var chineseWithExtend = '(?:' + chineseDictionary.chineseBasic + '|' + chineseDictionary.chineseExtend + '|' + chineseDictionary.chineseExtendA + '|' + chineseDictionary.chineseExtendB + '|' + chineseDictionary.chineseExtendC + '|' + chineseDictionary.chineseExtendD + '|' + chineseDictionary.chineseExtendE + '|' + chineseDictionary.chineseExtendF + ')';
|
|
23
16
|
var looseChineseExtendRegExp = chineseWithExtend + '+';
|
|
24
17
|
var chineseExtendRegExp = '^' + chineseWithExtend + '+$';
|
|
25
|
-
|
|
26
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
27
18
|
var supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* @param {Object} [options] 配置项
|
|
40
|
-
* @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
|
|
41
|
-
* @param {boolean} [options.useExtend=false] 使用统一表意文字扩展A-F。注意:如果不支持 `RegExp.prototype.unicode`,扩展字符集将自动不生效,如IE浏览器。
|
|
42
|
-
* @returns {boolean} 值是否为中文
|
|
43
|
-
* @example
|
|
44
|
-
*
|
|
45
|
-
* isChinese('林某某'); // true
|
|
46
|
-
* isChinese('林A'); // false
|
|
47
|
-
*
|
|
48
|
-
* // 宽松模式,只要包含中文即为true
|
|
49
|
-
* isChinese('林A', { loose: true }); // true
|
|
50
|
-
* isChinese('A林A', { loose: true }); // true
|
|
51
|
-
*
|
|
52
|
-
* // 扩展字符集的字符
|
|
53
|
-
* isChinese('𠮷'); // false
|
|
54
|
-
*
|
|
55
|
-
* // 使用中文扩展字符集,需要浏览器支持 RegExp.prototype.unicode 才生效。
|
|
56
|
-
* isChinese('𠮷', { useExtend: true }); // true
|
|
57
|
-
* isChinese('𠮷aa', { useExtend: true, loose: true }); // true
|
|
58
|
-
*
|
|
59
|
-
*/
|
|
60
|
-
function isChinese(value) {
|
|
61
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
62
|
-
var _options$loose = options.loose,
|
|
63
|
-
loose = _options$loose === void 0 ? false : _options$loose,
|
|
64
|
-
_options$useExtend = options.useExtend,
|
|
65
|
-
useExtend = _options$useExtend === void 0 ? false : _options$useExtend;
|
|
66
|
-
var valueStr = normalizeString(value);
|
|
67
|
-
var basicRegExp = loose ? looseChineseRegExp : chineseRegExp;
|
|
68
|
-
var extendRegExp = loose ? looseChineseExtendRegExp : chineseExtendRegExp;
|
|
69
|
-
var hasExtend = useExtend && supportRegExpUnicode;
|
|
70
|
-
var resultRegExp = hasExtend ? extendRegExp : basicRegExp;
|
|
71
|
-
var flag = hasExtend ? 'u' : undefined;
|
|
72
|
-
var reg = new RegExp(resultRegExp, flag);
|
|
73
|
-
return reg.test(valueStr);
|
|
19
|
+
function isChinese(value, options) {
|
|
20
|
+
if (options === void 0) { options = {}; }
|
|
21
|
+
var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.useExtend, useExtend = _b === void 0 ? false : _b;
|
|
22
|
+
var valueStr = normalizeString(value);
|
|
23
|
+
var basicRegExp = loose ? looseChineseRegExp : chineseRegExp;
|
|
24
|
+
var extendRegExp = loose ? looseChineseExtendRegExp : chineseExtendRegExp;
|
|
25
|
+
var hasExtend = useExtend && supportRegExpUnicode;
|
|
26
|
+
var resultRegExp = hasExtend ? extendRegExp : basicRegExp;
|
|
27
|
+
var flag = hasExtend ? 'u' : undefined;
|
|
28
|
+
var reg = new RegExp(resultRegExp, flag);
|
|
29
|
+
return reg.test(valueStr);
|
|
74
30
|
}
|
|
75
|
-
|
|
31
|
+
|
|
32
|
+
export { isChinese as default };
|
package/esm/isEmail.js
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var reg = /^[\da-z]+([\-\.\_]?[\da-z]+)*@[\da-z]+([\-\.]?[\da-z]+)*(\.[a-z]{2,})+$/i;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 检测值是否为Email
|
|
8
|
-
*
|
|
9
|
-
* @static
|
|
10
|
-
* @alias module:Validator.isEmail
|
|
11
|
-
* @since 1.1.0
|
|
12
|
-
* @param {*} value 要检测的值
|
|
13
|
-
* @returns {boolean} 值是否为Email
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* isEmail('1232@qq.com'); // true
|
|
17
|
-
* isEmail('123@'); // false
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
3
|
+
var reg = /^[\da-z]+([-._]?[\da-z]+)*@[\da-z]+([-.]?[\da-z]+)*(\.[a-z]{2,})+$/i;
|
|
20
4
|
function isEmail(value) {
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
var valueStr = normalizeString(value);
|
|
6
|
+
return reg.test(valueStr);
|
|
23
7
|
}
|
|
24
|
-
|
|
8
|
+
|
|
9
|
+
export { isEmail as default };
|
package/esm/isHMCard.js
CHANGED
|
@@ -1,32 +1,9 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// 港澳居民来往内地通行证正则
|
|
4
3
|
var regHMCard = /^[hm]{1}([0-9]{10}|[0-9]{8})$/i;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 检测值是否为港澳居民来往内地通行证,俗称回乡证或回乡卡。
|
|
8
|
-
*
|
|
9
|
-
* @static
|
|
10
|
-
* @alias module:Validator.isHMCard
|
|
11
|
-
* @since 4.0.0
|
|
12
|
-
* @see {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证|港澳居民来往内地通行证}
|
|
13
|
-
* @param {*} value 要检测的值
|
|
14
|
-
* @returns {boolean} 是否为港澳居民来往内地通行证
|
|
15
|
-
* @example
|
|
16
|
-
* // 第一代 11 位
|
|
17
|
-
* isHMCard('h3203117707'); // true
|
|
18
|
-
* isHMCard('H3203117707'); // true
|
|
19
|
-
* isHMCard('m3203117707'); // true
|
|
20
|
-
* isHMCard('M3203117707'); // true
|
|
21
|
-
*
|
|
22
|
-
* // 第二代 9 位
|
|
23
|
-
* isHMCard('h32031177'); // true
|
|
24
|
-
* isHMCard('H32031177'); // true
|
|
25
|
-
* isHMCard('m32031177'); // true
|
|
26
|
-
* isHMCard('M32031177'); // true
|
|
27
|
-
*/
|
|
28
4
|
function isHMCard(value) {
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
var valueStr = normalizeString(value);
|
|
6
|
+
return regHMCard.test(valueStr);
|
|
31
7
|
}
|
|
32
|
-
|
|
8
|
+
|
|
9
|
+
export { isHMCard as default };
|
package/esm/isIPv4.js
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// ipv4正则
|
|
4
3
|
var reg = /^((\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])$/;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 检测值是否为ipv4
|
|
8
|
-
*
|
|
9
|
-
* @static
|
|
10
|
-
* @alias module:Validator.isIPv4
|
|
11
|
-
* @since 1.1.0
|
|
12
|
-
* @param {*} value 要检测的值
|
|
13
|
-
* @returns {boolean} 值是否为ipv4
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* isIPv4('192.168.1.1'); // true
|
|
17
|
-
* isIPv4('255.255.255.255'); // true
|
|
18
|
-
* isIPv4('256.256.256.256'); // false
|
|
19
|
-
* isIPv4('0.0'); // false
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
4
|
function isIPv4(value) {
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
var valueStr = normalizeString(value);
|
|
6
|
+
return reg.test(valueStr);
|
|
25
7
|
}
|
|
26
|
-
|
|
8
|
+
|
|
9
|
+
export { isIPv4 as default };
|
package/esm/isIPv6.js
CHANGED
|
@@ -1,40 +1,9 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// ipv6正则
|
|
4
3
|
var reg = /^((([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;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 检测值是否为ipv6
|
|
8
|
-
*
|
|
9
|
-
* @static
|
|
10
|
-
* @alias module:Validator.isIPv6
|
|
11
|
-
* @since 1.1.0
|
|
12
|
-
* @param {*} value 要检测的值
|
|
13
|
-
* @returns {boolean} 值是否为ipv6
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* // 冒分十六进制表示法
|
|
17
|
-
* isIPv6('2001:0DB8:0000:0023:0008:0800:200C:417A'); // true
|
|
18
|
-
*
|
|
19
|
-
* // 前导0省略
|
|
20
|
-
* isIPv6('2001:DB8:0:23:8:800:200C:417A'); // true
|
|
21
|
-
* isIPv6('FF01:0:0:0:0:0:0:1101'); // true
|
|
22
|
-
*
|
|
23
|
-
* // 0位压缩表示法
|
|
24
|
-
* isIPv6('FF01::1101'); // true
|
|
25
|
-
* isIPv6('::1'); // true
|
|
26
|
-
* isIPv6('::'); // true
|
|
27
|
-
* isIPv6('0:0:0:0:0:0:0:1'); // true
|
|
28
|
-
* isIPv6('0:0:0:0:0:0:0:0'); // true
|
|
29
|
-
*
|
|
30
|
-
* // 内嵌IPv4地址表示法
|
|
31
|
-
* isIPv6('::192.168.1.1'); // true
|
|
32
|
-
* isIPv6('::FFFF:192.168.1.1'); // true
|
|
33
|
-
* isIPv6('192.168.1.1'); // false
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
4
|
function isIPv6(value) {
|
|
37
|
-
|
|
38
|
-
|
|
5
|
+
var valueStr = normalizeString(value);
|
|
6
|
+
return reg.test(valueStr);
|
|
39
7
|
}
|
|
40
|
-
|
|
8
|
+
|
|
9
|
+
export { isIPv6 as default };
|