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/isWX.js
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
// 微信号 6至20位,以字母开头,字母,数字,减号(连接符),下划线
|
|
4
3
|
var reg = /^[a-z]([-_a-z0-9]{5,19})+$/i;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 检测值是否为微信号
|
|
8
|
-
*
|
|
9
|
-
* @static
|
|
10
|
-
* @alias module:Validator.isWX
|
|
11
|
-
* @since 1.1.0
|
|
12
|
-
* @param {*} value 要检测的值
|
|
13
|
-
* @returns {boolean} 值是否为微信号
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* isWX('a12345'); // true
|
|
17
|
-
* isWX('123'); // false
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
4
|
function isWX(value) {
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
var valueStr = normalizeString(value);
|
|
6
|
+
return reg.test(valueStr);
|
|
23
7
|
}
|
|
24
|
-
|
|
8
|
+
|
|
9
|
+
export { isWX as default };
|
package/esm/listToTree.js
CHANGED
|
@@ -1,127 +1,58 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import isObject from './utils/type/isObject.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* 递归处理空子级
|
|
6
|
-
*
|
|
7
|
-
* @private
|
|
8
|
-
* @template {Record<string,any>} [T=Record<string,any>]
|
|
9
|
-
* @param {T[]} arr 列表数据
|
|
10
|
-
* @param {object} [options] 配置项
|
|
11
|
-
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
12
|
-
* @param {'none'|'null'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
|
|
13
|
-
*/
|
|
14
4
|
function processEmptyChildren(arr, options) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
processEmptyChildren(item[childrenField], options);
|
|
32
|
-
}
|
|
33
|
-
// }
|
|
34
|
-
});
|
|
5
|
+
var _a = options.childrenField, childrenField = _a === void 0 ? 'children' : _a, _b = options.emptyChildrenValue, emptyChildrenValue = _b === void 0 ? 'none' : _b;
|
|
6
|
+
arr.forEach(function (item) {
|
|
7
|
+
if (item[childrenField].length <= 0) {
|
|
8
|
+
if (emptyChildrenValue === 'null') {
|
|
9
|
+
item[childrenField] = null;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
delete item[childrenField];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
processEmptyChildren(item[childrenField], options);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
35
19
|
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 列表数据转树结构
|
|
39
|
-
*
|
|
40
|
-
* @static
|
|
41
|
-
* @alias module:Tree.listToTree
|
|
42
|
-
* @since 4.14.0
|
|
43
|
-
* @template {Record<string,any>} [T=Record<string,any>]
|
|
44
|
-
* @template {*} [R=T&Record<string,any>]
|
|
45
|
-
* @param {T[]} list 列表数据
|
|
46
|
-
* @param {object} [options] 配置项
|
|
47
|
-
* @param {string} [options.keyField='id'] 当前数据的键值字段名称
|
|
48
|
-
* @param {string} [options.parentField='pid'] 当前数据的父级字段名称
|
|
49
|
-
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
50
|
-
* @param {'none'|'null'|'array'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
|
|
51
|
-
* @param {'spread'|'self'} [options.nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
52
|
-
* @returns {R[]} 树结构
|
|
53
|
-
* @example
|
|
54
|
-
*
|
|
55
|
-
* const menus = [
|
|
56
|
-
* { id: '1', name: '首页', code: 'trade', pid: null },
|
|
57
|
-
* { id: '2', name: '交易管理', code: 'trade', pid: null },
|
|
58
|
-
* { id: '3', name: '交易查询', code: 'trade-1', pid: '2' },
|
|
59
|
-
* { id: '4', name: '交易查询-查询操作', code: 'trade-1-1', pid: '3' },
|
|
60
|
-
* { id: '5', name: '权限管理', code: 'authorization', pid: null },
|
|
61
|
-
* { id: '6', name: '角色管理', code: 'authorization-1', pid: '5' },
|
|
62
|
-
* { id: '7', name: '用户管理', code: 'authorization-2', pid: '5' }
|
|
63
|
-
* ];
|
|
64
|
-
* listToTree(menus);
|
|
65
|
-
* // [{"id":"1","name":"首页","code":"trade","pid":null},{"id":"2","name":"交易管理","code":"trade","pid":null,"children":[{"id":"3","name":"交易查询","code":"trade-1","pid":"2","children":[{"id":"4","name":"交易查询-查询操作","code":"trade-1-1","pid":"3"}]}]},{"id":"5","name":"权限管理","code":"authorization","pid":null,"children":[{"id":"6","name":"角色管理","code":"authorization-1","pid":"5"},{"id":"7","name":"用户管理","code":"authorization-2","pid":"5"}]}]
|
|
66
|
-
*
|
|
67
|
-
* // 自定义子级字段名
|
|
68
|
-
* listToTree(basicMenus, { childrenField: 'childs' });
|
|
69
|
-
* // [{"id":"1","name":"首页","code":"trade","pid":null},{"id":"2","name":"交易管理","code":"trade","pid":null,"childs":[{"id":"3","name":"交易查询","code":"trade-1","pid":"2","childs":[{"id":"4","name":"交易查询-查询操作","code":"trade-1-1","pid":"3"}]}]},{"id":"5","name":"权限管理","code":"authorization","pid":null,"childs":[{"id":"6","name":"角色管理","code":"authorization-1","pid":"5"},{"id":"7","name":"用户管理","code":"authorization-2","pid":"5"}]}]
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
20
|
function listToTree(list, options) {
|
|
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
|
-
if (record[id]) {
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
newItem[childrenField] = record[id];
|
|
105
|
-
} else {
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
newItem[childrenField] = record[id] = [];
|
|
108
|
-
}
|
|
109
|
-
if (pid) {
|
|
110
|
-
if (!record[pid]) {
|
|
111
|
-
record[pid] = [newItem];
|
|
112
|
-
} else {
|
|
113
|
-
record[pid].push(newItem);
|
|
21
|
+
if (options === void 0) { options = {}; }
|
|
22
|
+
var _a = options.keyField, keyField = _a === void 0 ? 'id' : _a, _b = options.parentField, parentField = _b === void 0 ? 'pid' : _b, _c = options.childrenField, childrenField = _c === void 0 ? 'children' : _c, _d = options.emptyChildrenValue, emptyChildrenValue = _d === void 0 ? 'none' : _d, _e = options.nodeAssign, nodeAssign = _e === void 0 ? 'spread' : _e;
|
|
23
|
+
var tree = [];
|
|
24
|
+
var record = {};
|
|
25
|
+
if (!Array.isArray(list)) {
|
|
26
|
+
return tree;
|
|
27
|
+
}
|
|
28
|
+
list.forEach(function (item) {
|
|
29
|
+
if (isObject(item)) {
|
|
30
|
+
var newItem = nodeAssign === 'spread' ? __assign({}, item) : item;
|
|
31
|
+
var id = newItem[keyField];
|
|
32
|
+
var pid = newItem[parentField];
|
|
33
|
+
if (record[id]) {
|
|
34
|
+
newItem[childrenField] = record[id];
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
newItem[childrenField] = record[id] = [];
|
|
38
|
+
}
|
|
39
|
+
if (pid) {
|
|
40
|
+
if (!record[pid]) {
|
|
41
|
+
record[pid] = [newItem];
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
record[pid].push(newItem);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
tree.push(newItem);
|
|
49
|
+
}
|
|
114
50
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
tree
|
|
118
|
-
}
|
|
51
|
+
});
|
|
52
|
+
if (emptyChildrenValue !== 'array') {
|
|
53
|
+
processEmptyChildren(tree, options);
|
|
119
54
|
}
|
|
120
|
-
|
|
121
|
-
if (emptyChildrenValue !== 'array') {
|
|
122
|
-
// @ts-ignore
|
|
123
|
-
processEmptyChildren(tree, options);
|
|
124
|
-
}
|
|
125
|
-
return tree;
|
|
55
|
+
return tree;
|
|
126
56
|
}
|
|
127
|
-
|
|
57
|
+
|
|
58
|
+
export { listToTree as default };
|
package/esm/minus.js
CHANGED
|
@@ -1,42 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import times from './times';
|
|
1
|
+
import { __read, __spreadArray } from 'tslib';
|
|
2
|
+
import { transformEffectiveNumber, digitLength } from './utils/math.util.js';
|
|
3
|
+
import times from './times.js';
|
|
4
|
+
import _isNaN from './utils/type/isNaN.js';
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
-
* 精确减法,支持多个数相减,减数默认为 0 。
|
|
7
|
-
*
|
|
8
|
-
* @static
|
|
9
|
-
* @alias module:Math.minus
|
|
10
|
-
* @since 3.1.0
|
|
11
|
-
* @param {...number|string} nums 相减的数
|
|
12
|
-
* @returns {number} 差
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* minus(1, 0.9); // 0.1
|
|
16
|
-
* minus(1, 0.9, 0.02); // 0.08
|
|
17
|
-
* minus(1, 0.9, 0.02, 0.08); // 0
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
6
|
function minus() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (isNaN(num1) || isNaN(num2)) {
|
|
37
|
-
return Number.NaN;
|
|
38
|
-
}
|
|
39
|
-
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
40
|
-
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
|
|
7
|
+
var nums = [];
|
|
8
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
9
|
+
nums[_i] = arguments[_i];
|
|
10
|
+
}
|
|
11
|
+
var _a = __read(nums), num1 = _a[0], _b = _a[1], num2 = _b === void 0 ? 0 : _b, rest = _a.slice(2);
|
|
12
|
+
if (rest.length > 0) {
|
|
13
|
+
return minus.apply(void 0, __spreadArray([minus(num1, num2)], __read(rest), false));
|
|
14
|
+
}
|
|
15
|
+
num1 = transformEffectiveNumber(num1);
|
|
16
|
+
num2 = transformEffectiveNumber(num2);
|
|
17
|
+
if (_isNaN(num1) || _isNaN(num2)) {
|
|
18
|
+
return Number.NaN;
|
|
19
|
+
}
|
|
20
|
+
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
21
|
+
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
|
|
41
22
|
}
|
|
42
|
-
|
|
23
|
+
|
|
24
|
+
export { minus as default };
|
package/esm/normalizeString.js
CHANGED
|
@@ -1,32 +1,11 @@
|
|
|
1
|
-
import isNil from './utils/type/isNil';
|
|
2
|
-
import convertToString from './utils/convertToString';
|
|
1
|
+
import isNil from './utils/type/isNil.js';
|
|
2
|
+
import convertToString from './utils/convertToString.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* 规整化字符串。如果值为 undefined 或 null 将转为空字符串,如果值不是字符串类型将转为字符串。
|
|
6
|
-
*
|
|
7
|
-
* @static
|
|
8
|
-
* @alias module:Processor.normalizeString
|
|
9
|
-
* @since 4.3.0
|
|
10
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
|
|
11
|
-
* @param {*} value 待处理的值
|
|
12
|
-
* @returns {string} 规整化的值
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* normalizeString(); // ''
|
|
16
|
-
* normalizeString(undefined); // ''
|
|
17
|
-
* normalizeString(void 0); // ''
|
|
18
|
-
* normalizeString(null); // ''
|
|
19
|
-
*
|
|
20
|
-
* normalizeString(true); // 'true'
|
|
21
|
-
* normalizeString(NaN); // 'NaN'
|
|
22
|
-
* normalizeString(1); // '1'
|
|
23
|
-
* normalizeString('a'); // 'a'
|
|
24
|
-
*
|
|
25
|
-
*/
|
|
26
4
|
function normalizeString(value) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
if (isNil(value)) {
|
|
6
|
+
return '';
|
|
7
|
+
}
|
|
8
|
+
return convertToString(value);
|
|
31
9
|
}
|
|
32
|
-
|
|
10
|
+
|
|
11
|
+
export { normalizeString as default };
|
package/esm/numberToChinese.js
CHANGED
|
@@ -1,234 +1,115 @@
|
|
|
1
|
-
import { checkBoundary } from './utils/math.util';
|
|
2
|
-
import devWarn from './utils/devWarn';
|
|
1
|
+
import { checkBoundary } from './utils/math.util.js';
|
|
2
|
+
import devWarn from './utils/devWarn.js';
|
|
3
3
|
|
|
4
|
-
// 简体
|
|
5
4
|
var chnNumberChar = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
|
|
6
5
|
var chnUnitChar = ['', '十', '百', '千'];
|
|
7
|
-
|
|
8
|
-
// 繁体
|
|
9
6
|
var big5NumberChar = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
10
7
|
var big5UnitChar = ['', '拾', '佰', '仟'];
|
|
11
|
-
|
|
12
|
-
// 数字字符、计数单位
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @type {string[]}
|
|
16
|
-
* @private
|
|
17
|
-
*/
|
|
18
8
|
var numberChar;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @type {string[]}
|
|
22
|
-
* @private
|
|
23
|
-
*/
|
|
24
9
|
var unitChar;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @type {string[]}
|
|
28
|
-
* @private
|
|
29
|
-
*/
|
|
30
10
|
var unitSection;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 每个小节的内部进行转化
|
|
34
|
-
*
|
|
35
|
-
* @private
|
|
36
|
-
* @param {number} section 数字
|
|
37
|
-
* @returns {string} 转化的数字
|
|
38
|
-
*/
|
|
39
11
|
function sectionToChinese(section) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
chnstr = str + chnstr;
|
|
12
|
+
var str = '';
|
|
13
|
+
var chnstr = '';
|
|
14
|
+
var zero = false;
|
|
15
|
+
var unitPos = 0;
|
|
16
|
+
while (section > 0) {
|
|
17
|
+
var v = section % 10;
|
|
18
|
+
if (v == 0) {
|
|
19
|
+
if (zero) {
|
|
20
|
+
zero = false;
|
|
21
|
+
chnstr = numberChar[v] + chnstr;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
zero = true;
|
|
26
|
+
str = numberChar[v];
|
|
27
|
+
str += unitChar[unitPos];
|
|
28
|
+
chnstr = str + chnstr;
|
|
29
|
+
}
|
|
30
|
+
unitPos++;
|
|
31
|
+
section = Math.floor(section / 10);
|
|
61
32
|
}
|
|
62
|
-
|
|
63
|
-
section = Math.floor(section / 10);
|
|
64
|
-
}
|
|
65
|
-
return chnstr;
|
|
33
|
+
return chnstr;
|
|
66
34
|
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 转换整数
|
|
70
|
-
*
|
|
71
|
-
* @private
|
|
72
|
-
* @param {number} num 要转换的数字
|
|
73
|
-
* @returns {string} 中文数字
|
|
74
|
-
*/
|
|
75
35
|
function convertInteger(num) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
while (numInt > 0) {
|
|
85
|
-
var section = numInt % 10000;
|
|
86
|
-
if (needZero) {
|
|
87
|
-
chnStr = numberChar[0] + chnStr;
|
|
36
|
+
var numInt = Math.floor(num);
|
|
37
|
+
var unitPos = 0;
|
|
38
|
+
var strIns = '';
|
|
39
|
+
var chnStr = '';
|
|
40
|
+
var needZero = false;
|
|
41
|
+
if (numInt === 0) {
|
|
42
|
+
return numberChar[0];
|
|
88
43
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
44
|
+
while (numInt > 0) {
|
|
45
|
+
var section = numInt % 10000;
|
|
46
|
+
if (needZero) {
|
|
47
|
+
chnStr = numberChar[0] + chnStr;
|
|
48
|
+
}
|
|
49
|
+
strIns = sectionToChinese(section);
|
|
50
|
+
strIns += section !== 0 ? unitSection[unitPos] : unitSection[0];
|
|
51
|
+
chnStr = strIns + chnStr;
|
|
52
|
+
needZero = section < 1000 && section > 0;
|
|
53
|
+
numInt = Math.floor(numInt / 10000);
|
|
54
|
+
unitPos++;
|
|
55
|
+
}
|
|
56
|
+
return chnStr;
|
|
97
57
|
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* 转换小数
|
|
101
|
-
*
|
|
102
|
-
* @private
|
|
103
|
-
* @param {number} num 要转换的数字
|
|
104
|
-
*/
|
|
105
58
|
function convertDecimal(num) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
59
|
+
var strNum = num + '';
|
|
60
|
+
var index = strNum.indexOf('.');
|
|
61
|
+
var ret = '';
|
|
62
|
+
if (index > -1) {
|
|
63
|
+
var decimalStr = strNum.slice(index + 1);
|
|
64
|
+
ret = mapNumberChar(parseInt(decimalStr));
|
|
65
|
+
}
|
|
66
|
+
return ret;
|
|
114
67
|
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 映射为中文数字
|
|
118
|
-
*
|
|
119
|
-
* @private
|
|
120
|
-
* @param {number} num 要处理的数字
|
|
121
|
-
* @returns {string} 返回中文数字的映射
|
|
122
|
-
*/
|
|
123
68
|
function mapNumberChar(num) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
69
|
+
var strNum = num + '';
|
|
70
|
+
var ret = '';
|
|
71
|
+
for (var i = 0, len = strNum.length; i < len; i++) {
|
|
72
|
+
ret += numberChar[parseInt(strNum[i])];
|
|
73
|
+
}
|
|
74
|
+
return ret;
|
|
130
75
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
function numberToChinese(num) {
|
|
171
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
172
|
-
var _options$big = options.big5,
|
|
173
|
-
big5 = _options$big === void 0 ? false : _options$big,
|
|
174
|
-
_options$unit = options.unit,
|
|
175
|
-
unit = _options$unit === void 0 ? true : _options$unit,
|
|
176
|
-
_options$zero = options.zero,
|
|
177
|
-
zero = _options$zero === void 0 ? '' : _options$zero,
|
|
178
|
-
_options$negative = options.negative,
|
|
179
|
-
negative = _options$negative === void 0 ? '负' : _options$negative,
|
|
180
|
-
_options$unitConfig = options.unitConfig,
|
|
181
|
-
unitConfig = _options$unitConfig === void 0 ? {} : _options$unitConfig;
|
|
182
|
-
var _options$decimal = options.decimal,
|
|
183
|
-
decimal = _options$decimal === void 0 ? '' : _options$decimal;
|
|
184
|
-
|
|
185
|
-
// 非数字 或 NaN 不处理
|
|
186
|
-
if (typeof num !== 'number' || isNaN(num)) {
|
|
187
|
-
devWarn("\u53C2\u6570\u9519\u8BEF ".concat(num, "\uFF0C\u8BF7\u4F20\u5165\u6570\u5B57"));
|
|
188
|
-
return '';
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// 超过安全数字提示
|
|
192
|
-
checkBoundary(num);
|
|
193
|
-
|
|
194
|
-
// 设置数字字符和计数单位
|
|
195
|
-
if (big5) {
|
|
196
|
-
numberChar = big5NumberChar.slice();
|
|
197
|
-
unitChar = big5UnitChar.slice();
|
|
198
|
-
decimal = decimal || '點';
|
|
199
|
-
} else {
|
|
200
|
-
numberChar = chnNumberChar.slice();
|
|
201
|
-
unitChar = chnUnitChar.slice();
|
|
202
|
-
decimal = decimal || '点';
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// 设置节点计数单位,万、亿、万亿
|
|
206
|
-
var unitWan = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.w) || '万';
|
|
207
|
-
var unitYi = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.y) || '亿';
|
|
208
|
-
var unitWanYi = unitWan + unitYi;
|
|
209
|
-
unitSection = ['', unitWan, unitYi, unitWanYi];
|
|
210
|
-
|
|
211
|
-
// 设置0
|
|
212
|
-
if (zero) {
|
|
213
|
-
numberChar[0] = zero;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// 前置字符,负数处理
|
|
217
|
-
var preStr = num < 0 ? negative : '';
|
|
218
|
-
|
|
219
|
-
// 整数和小数
|
|
220
|
-
var chnInteger, chnDecimal;
|
|
221
|
-
var numAbs = Math.abs(num);
|
|
222
|
-
|
|
223
|
-
// 处理整数
|
|
224
|
-
if (unit) {
|
|
225
|
-
chnInteger = convertInteger(numAbs);
|
|
226
|
-
} else {
|
|
227
|
-
chnInteger = mapNumberChar(Math.floor(numAbs));
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// 处理小数
|
|
231
|
-
chnDecimal = convertDecimal(numAbs);
|
|
232
|
-
return chnDecimal ? "".concat(preStr).concat(chnInteger).concat(decimal).concat(chnDecimal) : "".concat(preStr).concat(chnInteger);
|
|
76
|
+
function numberToChinese(num, options) {
|
|
77
|
+
if (options === void 0) { options = {}; }
|
|
78
|
+
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;
|
|
79
|
+
var _f = options.decimal, decimal = _f === void 0 ? '' : _f;
|
|
80
|
+
if (typeof num !== 'number' || isNaN(num)) {
|
|
81
|
+
devWarn("\u53C2\u6570\u9519\u8BEF ".concat(num, "\uFF0C\u8BF7\u4F20\u5165\u6570\u5B57"));
|
|
82
|
+
return '';
|
|
83
|
+
}
|
|
84
|
+
checkBoundary(num);
|
|
85
|
+
if (big5) {
|
|
86
|
+
numberChar = big5NumberChar.slice();
|
|
87
|
+
unitChar = big5UnitChar.slice();
|
|
88
|
+
decimal = decimal || '點';
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
numberChar = chnNumberChar.slice();
|
|
92
|
+
unitChar = chnUnitChar.slice();
|
|
93
|
+
decimal = decimal || '点';
|
|
94
|
+
}
|
|
95
|
+
var unitWan = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.w) || '万';
|
|
96
|
+
var unitYi = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.y) || '亿';
|
|
97
|
+
var unitWanYi = unitWan + unitYi;
|
|
98
|
+
unitSection = ['', unitWan, unitYi, unitWanYi];
|
|
99
|
+
if (zero) {
|
|
100
|
+
numberChar[0] = zero;
|
|
101
|
+
}
|
|
102
|
+
var preStr = num < 0 ? negative : '';
|
|
103
|
+
var chnInteger;
|
|
104
|
+
var numAbs = Math.abs(num);
|
|
105
|
+
if (unit) {
|
|
106
|
+
chnInteger = convertInteger(numAbs);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
chnInteger = mapNumberChar(Math.floor(numAbs));
|
|
110
|
+
}
|
|
111
|
+
var chnDecimal = convertDecimal(numAbs);
|
|
112
|
+
return chnDecimal ? "".concat(preStr).concat(chnInteger).concat(decimal).concat(chnDecimal) : "".concat(preStr).concat(chnInteger);
|
|
233
113
|
}
|
|
234
|
-
|
|
114
|
+
|
|
115
|
+
export { numberToChinese as default };
|