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/strlen.js
CHANGED
|
@@ -1,34 +1,18 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* 获取字符长度。中文汉字占2个字符,英文占1个字符,特殊如emoji占4个字符。
|
|
5
|
-
*
|
|
6
|
-
* @static
|
|
7
|
-
* @alias module:Other.strlen
|
|
8
|
-
* @since 4.10.0
|
|
9
|
-
* @param {string} str 字符串
|
|
10
|
-
* @returns {number} 字符长度
|
|
11
|
-
* @example
|
|
12
|
-
*
|
|
13
|
-
* strlen('你好a'); // 5
|
|
14
|
-
* strlen('你好,世界!'); // 12
|
|
15
|
-
* strlen('严両丞丽'); // 8
|
|
16
|
-
* strlen('abcde'); // 5
|
|
17
|
-
* strlen('𠮷'); // 4
|
|
18
|
-
* strlen('🍎'); // 4
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
3
|
function strlen(str) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
4
|
+
var realStr = normalizeString(str);
|
|
5
|
+
var len = 0;
|
|
6
|
+
for (var i = 0; i < realStr.length; i++) {
|
|
7
|
+
var c = realStr.charCodeAt(i);
|
|
8
|
+
if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
|
|
9
|
+
len++;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
len += 2;
|
|
13
|
+
}
|
|
30
14
|
}
|
|
31
|
-
|
|
32
|
-
return len;
|
|
15
|
+
return len;
|
|
33
16
|
}
|
|
34
|
-
|
|
17
|
+
|
|
18
|
+
export { strlen as default };
|
package/esm/times.js
CHANGED
|
@@ -1,45 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { __read, __spreadArray } from 'tslib';
|
|
2
|
+
import { transformEffectiveNumber, float2Fixed, digitLength, checkBoundary } from './utils/math.util.js';
|
|
3
|
+
import _isNaN from './utils/type/isNaN.js';
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
* 精确乘法,支持多个数相乘,乘数默认为 1 。
|
|
6
|
-
*
|
|
7
|
-
* @static
|
|
8
|
-
* @alias module:Math.times
|
|
9
|
-
* @since 3.1.0
|
|
10
|
-
* @param {...number|string} nums 相乘的数
|
|
11
|
-
* @returns {number} 乘积
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* times(3, 0.6); // 1.8
|
|
15
|
-
* times(3, 0.6, 2); // 3.6
|
|
16
|
-
* times(3, 0.6, 2, 10); // 36
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
5
|
function times() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var num2Changed = float2Fixed(num2);
|
|
40
|
-
var baseNum = digitLength(num1) + digitLength(num2);
|
|
41
|
-
var leftValue = num1Changed * num2Changed;
|
|
42
|
-
checkBoundary(leftValue);
|
|
43
|
-
return leftValue / Math.pow(10, baseNum);
|
|
6
|
+
var nums = [];
|
|
7
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
8
|
+
nums[_i] = arguments[_i];
|
|
9
|
+
}
|
|
10
|
+
var _a = __read(nums), num1 = _a[0], _b = _a[1], num2 = _b === void 0 ? 1 : _b, rest = _a.slice(2);
|
|
11
|
+
if (rest.length > 0) {
|
|
12
|
+
return times.apply(void 0, __spreadArray([times(num1, num2)], __read(rest), false));
|
|
13
|
+
}
|
|
14
|
+
num1 = transformEffectiveNumber(num1);
|
|
15
|
+
num2 = transformEffectiveNumber(num2);
|
|
16
|
+
if (_isNaN(num1) || _isNaN(num2)) {
|
|
17
|
+
return Number.NaN;
|
|
18
|
+
}
|
|
19
|
+
var num1Changed = float2Fixed(num1);
|
|
20
|
+
var num2Changed = float2Fixed(num2);
|
|
21
|
+
var baseNum = digitLength(num1) + digitLength(num2);
|
|
22
|
+
var leftValue = num1Changed * num2Changed;
|
|
23
|
+
checkBoundary(leftValue);
|
|
24
|
+
return leftValue / Math.pow(10, baseNum);
|
|
44
25
|
}
|
|
45
|
-
|
|
26
|
+
|
|
27
|
+
export { times as default };
|
|
@@ -1,96 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import isObject from './utils/type/isObject.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* // 嵌套数据,并替换子集字段名
|
|
36
|
-
* const newOptions4 = transformFieldNames(options3, {label: 'name', value: 'code', children: 'childs'}, 'childs');
|
|
37
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
|
|
38
|
-
*/
|
|
39
|
-
function transformFieldNames(data, fieldNames, childrenField) {
|
|
40
|
-
var nodeAssign = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'spread';
|
|
41
|
-
if (!Array.isArray(data)) {
|
|
42
|
-
return data;
|
|
43
|
-
}
|
|
44
|
-
if (data.length <= 0) {
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 递归处理字段名
|
|
51
|
-
*
|
|
52
|
-
* @param {Array.<object>} arr 列表数据
|
|
53
|
-
* @returns {*}
|
|
54
|
-
*/
|
|
55
|
-
function recusion(arr) {
|
|
56
|
-
return arr.map(function (item) {
|
|
57
|
-
if (!isObject(item)) {
|
|
58
|
-
return item;
|
|
59
|
-
}
|
|
60
|
-
var newItem = nodeAssign === 'spread' ? _objectSpread({}, item) : item;
|
|
61
|
-
/** @type {Array.<string>} */
|
|
62
|
-
var delKeys = [];
|
|
63
|
-
|
|
64
|
-
// 树形数据子节点
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
if (childrenField && Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
newItem[childrenField] = recusion(newItem[childrenField].slice());
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 替换字段名
|
|
72
|
-
Object.keys(fieldNames).forEach(function (newKey) {
|
|
73
|
-
var oldKey = fieldNames[newKey];
|
|
74
|
-
if (oldKey in newItem) {
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
newItem[newKey] = newItem[oldKey];
|
|
77
|
-
// @ts-ignore
|
|
78
|
-
delKeys.push(oldKey);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// 删除旧字段
|
|
83
|
-
if (delKeys.length > 0) {
|
|
84
|
-
delKeys.forEach(function (delKey) {
|
|
85
|
-
// @ts-ignore
|
|
86
|
-
delete newItem[delKey];
|
|
4
|
+
function transformFieldNames(data, fieldNames, childrenField, nodeAssign) {
|
|
5
|
+
if (nodeAssign === void 0) { nodeAssign = 'spread'; }
|
|
6
|
+
if (!Array.isArray(data)) {
|
|
7
|
+
return data;
|
|
8
|
+
}
|
|
9
|
+
if (data.length <= 0) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
function recusion(arr) {
|
|
13
|
+
return arr.map(function (item) {
|
|
14
|
+
if (!isObject(item)) {
|
|
15
|
+
return item;
|
|
16
|
+
}
|
|
17
|
+
var newItem = nodeAssign === 'spread' ? __assign({}, item) : item;
|
|
18
|
+
var delKeys = [];
|
|
19
|
+
if (childrenField && Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
20
|
+
newItem[childrenField] = recusion(newItem[childrenField].slice());
|
|
21
|
+
}
|
|
22
|
+
Object.keys(fieldNames).forEach(function (newKey) {
|
|
23
|
+
var oldKey = fieldNames[newKey];
|
|
24
|
+
if (oldKey in newItem) {
|
|
25
|
+
newItem[newKey] = newItem[oldKey];
|
|
26
|
+
delKeys.push(oldKey);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
if (delKeys.length > 0) {
|
|
30
|
+
delKeys.forEach(function (delKey) {
|
|
31
|
+
delete newItem[delKey];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return newItem;
|
|
87
35
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
return recusion(data.slice());
|
|
36
|
+
}
|
|
37
|
+
return recusion(data.slice());
|
|
95
38
|
}
|
|
96
|
-
|
|
39
|
+
|
|
40
|
+
export { transformFieldNames as default };
|
package/esm/treeToList.js
CHANGED
|
@@ -1,89 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import isObject from './utils/type/isObject.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* 树结构转列表数据
|
|
6
|
-
*
|
|
7
|
-
* @static
|
|
8
|
-
* @alias module:Tree.treeToList
|
|
9
|
-
* @since 4.14.0
|
|
10
|
-
* @template {Record<string,any>} T
|
|
11
|
-
* @template {keyof T} K
|
|
12
|
-
* @template {Omit<T, K>} R
|
|
13
|
-
* @param {T[]} tree 列表数据
|
|
14
|
-
* @param {K} childrenField 子级字段名称
|
|
15
|
-
* @returns {R[]} 列表数据
|
|
16
|
-
* @example
|
|
17
|
-
* const menus = [{ "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" }] }];
|
|
18
|
-
*
|
|
19
|
-
* treeToList(menus, 'children'));
|
|
20
|
-
* // [{"id":"1","name":"首页","code":"trade","pid":null},{"id":"2","name":"交易管理","code":"trade","pid":null},{"id":"3","name":"交易查询","code":"trade-1","pid":"2"},{"id":"4","name":"交易查询-查询操作","code":"trade-1-1","pid":"3"},{"id":"5","name":"权限管理","code":"authorization","pid":null},{"id":"6","name":"角色管理","code":"authorization-1","pid":"5"},{"id":"7","name":"用户管理","code":"authorization-2","pid":"5"}]
|
|
21
|
-
*/
|
|
22
4
|
function treeToList(tree, childrenField) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
var list = [];
|
|
6
|
+
if (!Array.isArray(tree)) {
|
|
7
|
+
return list;
|
|
8
|
+
}
|
|
9
|
+
function recusion(arr) {
|
|
10
|
+
arr.forEach(function (item) {
|
|
11
|
+
if (isObject(item)) {
|
|
12
|
+
var newItem = __assign({}, item);
|
|
13
|
+
list.push(newItem);
|
|
14
|
+
if (newItem[childrenField]) {
|
|
15
|
+
if (Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
16
|
+
recusion(newItem[childrenField]);
|
|
17
|
+
}
|
|
18
|
+
delete newItem[childrenField];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
list.push(item);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
recusion(tree);
|
|
26
27
|
return list;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 递归遍历
|
|
31
|
-
* @param {T[]} arr 列表数据
|
|
32
|
-
*/
|
|
33
|
-
function recusion(arr) {
|
|
34
|
-
arr.forEach(function (item) {
|
|
35
|
-
if (isObject(item)) {
|
|
36
|
-
var newItem = _objectSpread({}, item);
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
list.push(newItem);
|
|
39
|
-
if (newItem[childrenField]) {
|
|
40
|
-
if (Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
41
|
-
recusion(newItem[childrenField]);
|
|
42
|
-
}
|
|
43
|
-
delete newItem[childrenField];
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
list.push(item);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
recusion(tree);
|
|
52
|
-
return list;
|
|
53
28
|
}
|
|
54
29
|
|
|
55
|
-
|
|
56
|
-
// /** @type {R[]} */
|
|
57
|
-
// const list = [];
|
|
58
|
-
|
|
59
|
-
// // 深度优先
|
|
60
|
-
// /** @type {T[]} */
|
|
61
|
-
// const stack = [];
|
|
62
|
-
// for (const item of tree) {
|
|
63
|
-
// if (isObject(item)) {
|
|
64
|
-
// stack.push(item);
|
|
65
|
-
|
|
66
|
-
// while (stack.length) {
|
|
67
|
-
// /** @type {T} */
|
|
68
|
-
// // @ts-ignore
|
|
69
|
-
// const temp = stack.shift();
|
|
70
|
-
|
|
71
|
-
// // @ts-ignore
|
|
72
|
-
// list.push(temp);
|
|
73
|
-
|
|
74
|
-
// if (temp[childrenField]) {
|
|
75
|
-
// if (Array.isArray(temp[childrenField]) && temp[childrenField].length > 0) {
|
|
76
|
-
// stack.push(...temp[childrenField]);
|
|
77
|
-
// }
|
|
78
|
-
// delete temp[childrenField];
|
|
79
|
-
// }
|
|
80
|
-
// }
|
|
81
|
-
// } else {
|
|
82
|
-
// // @ts-ignore
|
|
83
|
-
// list.push(item);
|
|
84
|
-
// }
|
|
85
|
-
// }
|
|
86
|
-
// return list;
|
|
87
|
-
// }
|
|
88
|
-
|
|
89
|
-
export default treeToList;
|
|
30
|
+
export { treeToList as default };
|
package/esm/utils/config.js
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
var config = {
|
|
2
|
-
|
|
3
|
-
disableWarning: true
|
|
2
|
+
disableWarning: true
|
|
4
3
|
};
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 设置禁止warning提示
|
|
8
|
-
* @static
|
|
9
|
-
* @alias module:Debug.formatBankCard
|
|
10
|
-
* @since 3.6.1
|
|
11
|
-
* @param {boolean} bool 是否禁止warning提示
|
|
12
|
-
*/
|
|
13
4
|
function setDisableWarning(bool) {
|
|
14
|
-
|
|
5
|
+
config.disableWarning = !!bool;
|
|
15
6
|
}
|
|
7
|
+
var version = "4.17.1";
|
|
16
8
|
|
|
17
|
-
|
|
18
|
-
var version = "4.16.2";
|
|
19
|
-
export { config, setDisableWarning, version };
|
|
9
|
+
export { config, setDisableWarning, version };
|
package/esm/utils/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
1
|
+
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
|
|
2
|
+
var MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
|
|
3
|
+
|
|
4
|
+
export { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER };
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import isString from './type/isString';
|
|
1
|
+
import isString from './type/isString.js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* 转换为字符串
|
|
5
|
-
*
|
|
6
|
-
* @param {*} value 值
|
|
7
|
-
* @returns {string} 字符串
|
|
8
|
-
*/
|
|
9
3
|
function convertToString(value) {
|
|
10
|
-
|
|
4
|
+
return isString(value) ? value : String(value);
|
|
11
5
|
}
|
|
12
|
-
|
|
6
|
+
|
|
7
|
+
export { convertToString as default };
|
package/esm/utils/devWarn.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __spreadArray, __read } from 'tslib';
|
|
2
|
+
import { config } from './config.js';
|
|
2
3
|
|
|
3
|
-
/**
|
|
4
|
-
* 打印警告信息
|
|
5
|
-
*
|
|
6
|
-
* @param {any[]} args 打印的信息
|
|
7
|
-
*/
|
|
8
4
|
function devWarn() {
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
var args = [];
|
|
6
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
7
|
+
args[_i] = arguments[_i];
|
|
8
|
+
}
|
|
9
|
+
if (!config.disableWarning) {
|
|
10
|
+
console.warn.apply(console, __spreadArray([], __read(args), false));
|
|
11
|
+
}
|
|
13
12
|
}
|
|
14
|
-
|
|
13
|
+
|
|
14
|
+
export { devWarn as default };
|