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/lib/numberToChinese.js
CHANGED
|
@@ -1,241 +1,117 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var math_util = require('./utils/math.util.js');
|
|
4
|
+
var devWarn = require('./utils/devWarn.js');
|
|
2
5
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _math = require("./utils/math.util");
|
|
8
|
-
var _devWarn = _interopRequireDefault(require("./utils/devWarn"));
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
-
// 简体
|
|
11
6
|
var chnNumberChar = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
|
|
12
7
|
var chnUnitChar = ['', '十', '百', '千'];
|
|
13
|
-
|
|
14
|
-
// 繁体
|
|
15
8
|
var big5NumberChar = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
16
9
|
var big5UnitChar = ['', '拾', '佰', '仟'];
|
|
17
|
-
|
|
18
|
-
// 数字字符、计数单位
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @type {string[]}
|
|
22
|
-
* @private
|
|
23
|
-
*/
|
|
24
10
|
var numberChar;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @type {string[]}
|
|
28
|
-
* @private
|
|
29
|
-
*/
|
|
30
11
|
var unitChar;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @type {string[]}
|
|
34
|
-
* @private
|
|
35
|
-
*/
|
|
36
12
|
var unitSection;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 每个小节的内部进行转化
|
|
40
|
-
*
|
|
41
|
-
* @private
|
|
42
|
-
* @param {number} section 数字
|
|
43
|
-
* @returns {string} 转化的数字
|
|
44
|
-
*/
|
|
45
13
|
function sectionToChinese(section) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
chnstr = str + chnstr;
|
|
14
|
+
var str = '';
|
|
15
|
+
var chnstr = '';
|
|
16
|
+
var zero = false;
|
|
17
|
+
var unitPos = 0;
|
|
18
|
+
while (section > 0) {
|
|
19
|
+
var v = section % 10;
|
|
20
|
+
if (v == 0) {
|
|
21
|
+
if (zero) {
|
|
22
|
+
zero = false;
|
|
23
|
+
chnstr = numberChar[v] + chnstr;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
zero = true;
|
|
28
|
+
str = numberChar[v];
|
|
29
|
+
str += unitChar[unitPos];
|
|
30
|
+
chnstr = str + chnstr;
|
|
31
|
+
}
|
|
32
|
+
unitPos++;
|
|
33
|
+
section = Math.floor(section / 10);
|
|
67
34
|
}
|
|
68
|
-
|
|
69
|
-
section = Math.floor(section / 10);
|
|
70
|
-
}
|
|
71
|
-
return chnstr;
|
|
35
|
+
return chnstr;
|
|
72
36
|
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 转换整数
|
|
76
|
-
*
|
|
77
|
-
* @private
|
|
78
|
-
* @param {number} num 要转换的数字
|
|
79
|
-
* @returns {string} 中文数字
|
|
80
|
-
*/
|
|
81
37
|
function convertInteger(num) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
38
|
+
var numInt = Math.floor(num);
|
|
39
|
+
var unitPos = 0;
|
|
40
|
+
var strIns = '';
|
|
41
|
+
var chnStr = '';
|
|
42
|
+
var needZero = false;
|
|
43
|
+
if (numInt === 0) {
|
|
44
|
+
return numberChar[0];
|
|
45
|
+
}
|
|
46
|
+
while (numInt > 0) {
|
|
47
|
+
var section = numInt % 10000;
|
|
48
|
+
if (needZero) {
|
|
49
|
+
chnStr = numberChar[0] + chnStr;
|
|
50
|
+
}
|
|
51
|
+
strIns = sectionToChinese(section);
|
|
52
|
+
strIns += section !== 0 ? unitSection[unitPos] : unitSection[0];
|
|
53
|
+
chnStr = strIns + chnStr;
|
|
54
|
+
needZero = section < 1000 && section > 0;
|
|
55
|
+
numInt = Math.floor(numInt / 10000);
|
|
56
|
+
unitPos++;
|
|
94
57
|
}
|
|
95
|
-
|
|
96
|
-
strIns += section !== 0 ? unitSection[unitPos] : unitSection[0];
|
|
97
|
-
chnStr = strIns + chnStr;
|
|
98
|
-
needZero = section < 1000 && section > 0;
|
|
99
|
-
numInt = Math.floor(numInt / 10000);
|
|
100
|
-
unitPos++;
|
|
101
|
-
}
|
|
102
|
-
return chnStr;
|
|
58
|
+
return chnStr;
|
|
103
59
|
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* 转换小数
|
|
107
|
-
*
|
|
108
|
-
* @private
|
|
109
|
-
* @param {number} num 要转换的数字
|
|
110
|
-
*/
|
|
111
60
|
function convertDecimal(num) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
61
|
+
var strNum = num + '';
|
|
62
|
+
var index = strNum.indexOf('.');
|
|
63
|
+
var ret = '';
|
|
64
|
+
if (index > -1) {
|
|
65
|
+
var decimalStr = strNum.slice(index + 1);
|
|
66
|
+
ret = mapNumberChar(parseInt(decimalStr));
|
|
67
|
+
}
|
|
68
|
+
return ret;
|
|
120
69
|
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* 映射为中文数字
|
|
124
|
-
*
|
|
125
|
-
* @private
|
|
126
|
-
* @param {number} num 要处理的数字
|
|
127
|
-
* @returns {string} 返回中文数字的映射
|
|
128
|
-
*/
|
|
129
70
|
function mapNumberChar(num) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
71
|
+
var strNum = num + '';
|
|
72
|
+
var ret = '';
|
|
73
|
+
for (var i = 0, len = strNum.length; i < len; i++) {
|
|
74
|
+
ret += numberChar[parseInt(strNum[i])];
|
|
75
|
+
}
|
|
76
|
+
return ret;
|
|
136
77
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
*
|
|
175
|
-
*/
|
|
176
|
-
function numberToChinese(num) {
|
|
177
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
178
|
-
var _options$big = options.big5,
|
|
179
|
-
big5 = _options$big === void 0 ? false : _options$big,
|
|
180
|
-
_options$unit = options.unit,
|
|
181
|
-
unit = _options$unit === void 0 ? true : _options$unit,
|
|
182
|
-
_options$zero = options.zero,
|
|
183
|
-
zero = _options$zero === void 0 ? '' : _options$zero,
|
|
184
|
-
_options$negative = options.negative,
|
|
185
|
-
negative = _options$negative === void 0 ? '负' : _options$negative,
|
|
186
|
-
_options$unitConfig = options.unitConfig,
|
|
187
|
-
unitConfig = _options$unitConfig === void 0 ? {} : _options$unitConfig;
|
|
188
|
-
var _options$decimal = options.decimal,
|
|
189
|
-
decimal = _options$decimal === void 0 ? '' : _options$decimal;
|
|
190
|
-
|
|
191
|
-
// 非数字 或 NaN 不处理
|
|
192
|
-
if (typeof num !== 'number' || isNaN(num)) {
|
|
193
|
-
(0, _devWarn["default"])("\u53C2\u6570\u9519\u8BEF ".concat(num, "\uFF0C\u8BF7\u4F20\u5165\u6570\u5B57"));
|
|
194
|
-
return '';
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// 超过安全数字提示
|
|
198
|
-
(0, _math.checkBoundary)(num);
|
|
199
|
-
|
|
200
|
-
// 设置数字字符和计数单位
|
|
201
|
-
if (big5) {
|
|
202
|
-
numberChar = big5NumberChar.slice();
|
|
203
|
-
unitChar = big5UnitChar.slice();
|
|
204
|
-
decimal = decimal || '點';
|
|
205
|
-
} else {
|
|
206
|
-
numberChar = chnNumberChar.slice();
|
|
207
|
-
unitChar = chnUnitChar.slice();
|
|
208
|
-
decimal = decimal || '点';
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// 设置节点计数单位,万、亿、万亿
|
|
212
|
-
var unitWan = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.w) || '万';
|
|
213
|
-
var unitYi = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.y) || '亿';
|
|
214
|
-
var unitWanYi = unitWan + unitYi;
|
|
215
|
-
unitSection = ['', unitWan, unitYi, unitWanYi];
|
|
216
|
-
|
|
217
|
-
// 设置0
|
|
218
|
-
if (zero) {
|
|
219
|
-
numberChar[0] = zero;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// 前置字符,负数处理
|
|
223
|
-
var preStr = num < 0 ? negative : '';
|
|
224
|
-
|
|
225
|
-
// 整数和小数
|
|
226
|
-
var chnInteger, chnDecimal;
|
|
227
|
-
var numAbs = Math.abs(num);
|
|
228
|
-
|
|
229
|
-
// 处理整数
|
|
230
|
-
if (unit) {
|
|
231
|
-
chnInteger = convertInteger(numAbs);
|
|
232
|
-
} else {
|
|
233
|
-
chnInteger = mapNumberChar(Math.floor(numAbs));
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// 处理小数
|
|
237
|
-
chnDecimal = convertDecimal(numAbs);
|
|
238
|
-
return chnDecimal ? "".concat(preStr).concat(chnInteger).concat(decimal).concat(chnDecimal) : "".concat(preStr).concat(chnInteger);
|
|
78
|
+
function numberToChinese(num, options) {
|
|
79
|
+
if (options === void 0) { options = {}; }
|
|
80
|
+
var _a = options.big5, big5 = _a === void 0 ? false : _a, _b = options.unit, unit = _b === void 0 ? true : _b, _c = options.zero, zero = _c === void 0 ? '' : _c, _d = options.negative, negative = _d === void 0 ? '负' : _d, _e = options.unitConfig, unitConfig = _e === void 0 ? {} : _e;
|
|
81
|
+
var _f = options.decimal, decimal = _f === void 0 ? '' : _f;
|
|
82
|
+
if (typeof num !== 'number' || isNaN(num)) {
|
|
83
|
+
devWarn("\u53C2\u6570\u9519\u8BEF ".concat(num, "\uFF0C\u8BF7\u4F20\u5165\u6570\u5B57"));
|
|
84
|
+
return '';
|
|
85
|
+
}
|
|
86
|
+
math_util.checkBoundary(num);
|
|
87
|
+
if (big5) {
|
|
88
|
+
numberChar = big5NumberChar.slice();
|
|
89
|
+
unitChar = big5UnitChar.slice();
|
|
90
|
+
decimal = decimal || '點';
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
numberChar = chnNumberChar.slice();
|
|
94
|
+
unitChar = chnUnitChar.slice();
|
|
95
|
+
decimal = decimal || '点';
|
|
96
|
+
}
|
|
97
|
+
var unitWan = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.w) || '万';
|
|
98
|
+
var unitYi = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.y) || '亿';
|
|
99
|
+
var unitWanYi = unitWan + unitYi;
|
|
100
|
+
unitSection = ['', unitWan, unitYi, unitWanYi];
|
|
101
|
+
if (zero) {
|
|
102
|
+
numberChar[0] = zero;
|
|
103
|
+
}
|
|
104
|
+
var preStr = num < 0 ? negative : '';
|
|
105
|
+
var chnInteger;
|
|
106
|
+
var numAbs = Math.abs(num);
|
|
107
|
+
if (unit) {
|
|
108
|
+
chnInteger = convertInteger(numAbs);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
chnInteger = mapNumberChar(Math.floor(numAbs));
|
|
112
|
+
}
|
|
113
|
+
var chnDecimal = convertDecimal(numAbs);
|
|
114
|
+
return chnDecimal ? "".concat(preStr).concat(chnInteger).concat(decimal).concat(chnDecimal) : "".concat(preStr).concat(chnInteger);
|
|
239
115
|
}
|
|
240
|
-
|
|
241
|
-
exports
|
|
116
|
+
|
|
117
|
+
module.exports = numberToChinese;
|
package/lib/padZero.js
CHANGED
|
@@ -1,45 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* @param {number} [size=2] 指定字符串长度
|
|
17
|
-
* @returns {string} 用零填充数字到给定长度的字符串
|
|
18
|
-
* @example
|
|
19
|
-
* padZero(5); // 05
|
|
20
|
-
* padZero('5'); // 05
|
|
21
|
-
*
|
|
22
|
-
* padZero(12); // 12
|
|
23
|
-
* padZero('12'); // 12
|
|
24
|
-
*
|
|
25
|
-
* padZero(688); // 688
|
|
26
|
-
* padZero('688'); // 688
|
|
27
|
-
*
|
|
28
|
-
* padZero(688, 5); // 00688
|
|
29
|
-
* padZero('688', 5); // 00688
|
|
30
|
-
*
|
|
31
|
-
*/
|
|
32
|
-
function padZero(value) {
|
|
33
|
-
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
34
|
-
var str = (0, _normalizeString["default"])(value);
|
|
35
|
-
var len = str.length;
|
|
36
|
-
if (typeof size !== 'number' || size < 0) {
|
|
37
|
-
size = 0;
|
|
38
|
-
}
|
|
39
|
-
if (len < size) {
|
|
40
|
-
return '0'.repeat(size - len) + str;
|
|
41
|
-
}
|
|
42
|
-
return str;
|
|
3
|
+
var normalizeString = require('./normalizeString.js');
|
|
4
|
+
|
|
5
|
+
function padZero(value, size) {
|
|
6
|
+
if (size === void 0) { size = 2; }
|
|
7
|
+
var str = normalizeString(value);
|
|
8
|
+
var len = str.length;
|
|
9
|
+
if (typeof size !== 'number' || size < 0) {
|
|
10
|
+
size = 0;
|
|
11
|
+
}
|
|
12
|
+
if (len < size) {
|
|
13
|
+
return '0'.repeat(size - len) + str;
|
|
14
|
+
}
|
|
15
|
+
return str;
|
|
43
16
|
}
|
|
44
|
-
|
|
45
|
-
exports
|
|
17
|
+
|
|
18
|
+
module.exports = padZero;
|
package/lib/parseIdCard.js
CHANGED
|
@@ -1,142 +1,69 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports["default"] = void 0;
|
|
8
|
-
function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, void 0, groups); }; var _super = RegExp.prototype, _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); return _groups.set(_this, groups || _groups.get(re)), _setPrototypeOf(_this, BabelRegExp.prototype); } function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { var i = g[name]; if ("number" == typeof i) groups[name] = result[i];else { for (var k = 0; void 0 === result[i[k]] && k + 1 < i.length;) k++; groups[name] = result[i[k]]; } return groups; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) { result.groups = buildGroups(result, this); var indices = result.indices; indices && (indices.groups = buildGroups(indices, this)); } return result; }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if ("string" == typeof substitution) { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { var group = groups[name]; return "$" + (Array.isArray(group) ? group.join("$") : group); })); } if ("function" == typeof substitution) { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; return "object" != _typeof(args[args.length - 1]) && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); }); } return _super[Symbol.replace].call(this, str, substitution); }, _wrapRegExp.apply(this, arguments); }
|
|
9
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
10
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
11
|
-
var regIdCard = /*#__PURE__*/_wrapRegExp(/^(\d{2})(\d{2})(\d{2})((?:\d{2})?\d{2})(\d{2})(\d{2})\d{2}(\d)(?:\d|X)?$/i, {
|
|
12
|
-
province: 1,
|
|
13
|
-
city: 2,
|
|
14
|
-
area: 3,
|
|
15
|
-
year: 4,
|
|
16
|
-
month: 5,
|
|
17
|
-
day: 6,
|
|
18
|
-
gender: 7
|
|
19
|
-
});
|
|
3
|
+
var regIdCard = /^(?<province>\d{2})(?<city>\d{2})(?<area>\d{2})(?<year>(?:\d{2})?\d{2})(?<month>\d{2})(?<day>\d{2})\d{2}(?<gender>\d)(?:\d|X)?$/i;
|
|
20
4
|
var Provinces = [
|
|
21
|
-
|
|
22
|
-
['
|
|
23
|
-
|
|
24
|
-
['
|
|
25
|
-
|
|
26
|
-
['
|
|
27
|
-
|
|
28
|
-
['
|
|
29
|
-
|
|
30
|
-
['
|
|
31
|
-
|
|
32
|
-
['
|
|
33
|
-
|
|
34
|
-
['
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
['
|
|
38
|
-
|
|
39
|
-
['
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* @property {string} area - 地区编码
|
|
58
|
-
* @property {string} year - 出生年
|
|
59
|
-
* @property {string} month - 出生月
|
|
60
|
-
* @property {string} day - 出生日
|
|
61
|
-
* @property {string} gender - 性别 能整除2为女,否则为男
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @typedef {Object} IdCardInfo - 身份证信息
|
|
66
|
-
* @property {string} province - 省份
|
|
67
|
-
* @property {string} birthday - 生日
|
|
68
|
-
* @property {string} gender - 性别
|
|
69
|
-
* @property {IdCardOrigin} origin - 解析身份证原数据
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 解析身份证号码,支持15、18位身份证号码
|
|
74
|
-
*
|
|
75
|
-
* @static
|
|
76
|
-
* @alias module:Processor.parseIdCard
|
|
77
|
-
* @since 4.0.0
|
|
78
|
-
* @see {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
|
|
79
|
-
* @param {string} id 身份证号码,支持15位
|
|
80
|
-
* @returns {IdCardInfo | null} 省份、生日、性别,省/市/区/年/月/日/性别编码。如果解析失败将返回 null 。
|
|
81
|
-
* @example
|
|
82
|
-
*
|
|
83
|
-
* parseIdCard('123456789123456'); // null
|
|
84
|
-
*
|
|
85
|
-
* // 18位身份证号码
|
|
86
|
-
* parseIdCard('130701199310302288');
|
|
87
|
-
* // =>
|
|
88
|
-
* {
|
|
89
|
-
* birthday: "1993-10-30",
|
|
90
|
-
* gender: "女",
|
|
91
|
-
* origin: { province: "13", city: "07", area: "01", year: "1993", month: "10", day: "30", gender: "8" },
|
|
92
|
-
* province: "河北省"
|
|
93
|
-
* }
|
|
94
|
-
*
|
|
95
|
-
* // 15位身份证号码
|
|
96
|
-
* parseIdCard('130701931030228');
|
|
97
|
-
* // =>
|
|
98
|
-
* {
|
|
99
|
-
* birthday: "93-10-30",
|
|
100
|
-
* gender: "女",
|
|
101
|
-
* origin: { province: "13", city: "07", area: "01", year: "93", month: "10", day: "30", gender: "8" },
|
|
102
|
-
* province: "河北省"
|
|
103
|
-
* }
|
|
104
|
-
*
|
|
105
|
-
*/
|
|
5
|
+
['11', '北京市'],
|
|
6
|
+
['12', '天津市'],
|
|
7
|
+
['13', '河北省'],
|
|
8
|
+
['14', '山西省'],
|
|
9
|
+
['15', '内蒙古自治区'],
|
|
10
|
+
['21', '辽宁省'],
|
|
11
|
+
['22', '吉林省'],
|
|
12
|
+
['23', '黑龙江省'],
|
|
13
|
+
['31', '上海市'],
|
|
14
|
+
['32', '江苏省'],
|
|
15
|
+
['33', '浙江省'],
|
|
16
|
+
['34', '安徽省'],
|
|
17
|
+
['35', '福建省'],
|
|
18
|
+
['36', '江西省'],
|
|
19
|
+
['37', '山东省'],
|
|
20
|
+
['41', '河南省'],
|
|
21
|
+
['42', '湖北省'],
|
|
22
|
+
['43', '湖南省'],
|
|
23
|
+
['44', '广东省'],
|
|
24
|
+
['45', '广西壮族自治区'],
|
|
25
|
+
['46', '海南省'],
|
|
26
|
+
['50', '重庆市'],
|
|
27
|
+
['51', '四川省'],
|
|
28
|
+
['52', '贵州省'],
|
|
29
|
+
['53', '云南省'],
|
|
30
|
+
['54', '西藏自治区'],
|
|
31
|
+
['61', '陕西省'],
|
|
32
|
+
['62', '甘肃省'],
|
|
33
|
+
['63', '青海省'],
|
|
34
|
+
['64', '宁夏回族自治区'],
|
|
35
|
+
['65', '新疆维吾尔自治区'],
|
|
36
|
+
['71', '台湾省'],
|
|
37
|
+
['83', '台湾省'],
|
|
38
|
+
['81', '香港特别行政区'],
|
|
39
|
+
['82', '澳门特别行政区']
|
|
40
|
+
];
|
|
106
41
|
function parseIdCard(id) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
// region,
|
|
135
|
-
province: province[1],
|
|
136
|
-
birthday: birthday,
|
|
137
|
-
gender: gender,
|
|
138
|
-
origin: origin
|
|
139
|
-
};
|
|
42
|
+
var match = regIdCard.exec(id);
|
|
43
|
+
if (!match) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
var origin = match.groups || {
|
|
47
|
+
province: match[1],
|
|
48
|
+
city: match[2],
|
|
49
|
+
area: match[3],
|
|
50
|
+
year: match[4],
|
|
51
|
+
month: match[5],
|
|
52
|
+
day: match[6],
|
|
53
|
+
gender: match[7]
|
|
54
|
+
};
|
|
55
|
+
var province = Provinces.find(function (item) { return item[0] === origin.province; });
|
|
56
|
+
if (!province) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
var birthday = "".concat(origin.year, "-").concat(origin.month, "-").concat(origin.day);
|
|
60
|
+
var gender = Number(origin.gender) % 2 === 0 ? '女' : '男';
|
|
61
|
+
return {
|
|
62
|
+
province: province[1],
|
|
63
|
+
birthday: birthday,
|
|
64
|
+
gender: gender,
|
|
65
|
+
origin: origin
|
|
66
|
+
};
|
|
140
67
|
}
|
|
141
|
-
|
|
142
|
-
exports
|
|
68
|
+
|
|
69
|
+
module.exports = parseIdCard;
|