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
|
@@ -1,105 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _type = require("./utils/type");
|
|
8
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } // 如果修改文档,请同步修改 interface.doc.js
|
|
14
|
-
/**
|
|
15
|
-
* 转换字段名,返回一个转换字段后的值,不改变原值。
|
|
16
|
-
*
|
|
17
|
-
* @static
|
|
18
|
-
* @alias module:Processor.transformFieldNames
|
|
19
|
-
* @since 4.14.0
|
|
20
|
-
* @template {*} D
|
|
21
|
-
* @template {Record<string, keyof D>} F
|
|
22
|
-
* @template {string} C
|
|
23
|
-
* @param {D[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenField
|
|
24
|
-
* @param {F} fieldNames 字段名映射
|
|
25
|
-
* @param {C} [childrenField] 子级数据字段名
|
|
26
|
-
* @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
27
|
-
* @returns {import('./interface.type.js').TransformFieldNames<D, F, C>}
|
|
28
|
-
* @example
|
|
29
|
-
*
|
|
30
|
-
* const options = [{code: '1', name: 'one'},{code:'2', name:'two'}];
|
|
31
|
-
* const newOptions = transformFieldNames(options, {label: 'name', value: 'code'});
|
|
32
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two'}]
|
|
33
|
-
*
|
|
34
|
-
* // 嵌套数据,指定子级字段名 children
|
|
35
|
-
* const options2 = [{code: '1', name: 'one'},{code:'2', name:'two', children: [{code:'2-1', name:'two-one', children: [{code: '2-1-1', name:'two-one-one'}]}]}];
|
|
36
|
-
* const newOptions2 = transformFieldNames(options2, {label: 'name', value: 'code'}, 'children');
|
|
37
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one', children: [{value: '2-1-1', label:'two-one-one'}]}]}]
|
|
38
|
-
*
|
|
39
|
-
* const options3 = [{code: '1', name: 'one'},{code:'2', name:'two', childs: [{code:'2-1', name:'two-one'}]}];
|
|
40
|
-
* const newOptions3 = transformFieldNames(options3, {label: 'name', value: 'code'}, 'childs');
|
|
41
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two', childs: [{value: '2-1', label:'two-one'}]}]
|
|
42
|
-
*
|
|
43
|
-
* // 嵌套数据,并替换子集字段名
|
|
44
|
-
* const newOptions4 = transformFieldNames(options3, {label: 'name', value: 'code', children: 'childs'}, 'childs');
|
|
45
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
|
|
46
|
-
*/
|
|
47
|
-
function transformFieldNames(data, fieldNames, childrenField) {
|
|
48
|
-
var nodeAssign = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'spread';
|
|
49
|
-
if (!Array.isArray(data)) {
|
|
50
|
-
return data;
|
|
51
|
-
}
|
|
52
|
-
if (data.length <= 0) {
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
return [];
|
|
55
|
-
}
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var isObject = require('./utils/type/isObject.js');
|
|
56
5
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return item
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// 删除旧字段
|
|
91
|
-
if (delKeys.length > 0) {
|
|
92
|
-
delKeys.forEach(function (delKey) {
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
delete newItem[delKey];
|
|
6
|
+
function transformFieldNames(data, fieldNames, childrenField, nodeAssign) {
|
|
7
|
+
if (nodeAssign === void 0) { nodeAssign = 'spread'; }
|
|
8
|
+
if (!Array.isArray(data)) {
|
|
9
|
+
return data;
|
|
10
|
+
}
|
|
11
|
+
if (data.length <= 0) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
function recusion(arr) {
|
|
15
|
+
return arr.map(function (item) {
|
|
16
|
+
if (!isObject(item)) {
|
|
17
|
+
return item;
|
|
18
|
+
}
|
|
19
|
+
var newItem = nodeAssign === 'spread' ? tslib.__assign({}, item) : item;
|
|
20
|
+
var delKeys = [];
|
|
21
|
+
if (childrenField && Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
22
|
+
newItem[childrenField] = recusion(newItem[childrenField].slice());
|
|
23
|
+
}
|
|
24
|
+
Object.keys(fieldNames).forEach(function (newKey) {
|
|
25
|
+
var oldKey = fieldNames[newKey];
|
|
26
|
+
if (oldKey in newItem) {
|
|
27
|
+
newItem[newKey] = newItem[oldKey];
|
|
28
|
+
delKeys.push(oldKey);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
if (delKeys.length > 0) {
|
|
32
|
+
delKeys.forEach(function (delKey) {
|
|
33
|
+
delete newItem[delKey];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return newItem;
|
|
95
37
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
return recusion(data.slice());
|
|
38
|
+
}
|
|
39
|
+
return recusion(data.slice());
|
|
103
40
|
}
|
|
104
|
-
|
|
105
|
-
exports
|
|
41
|
+
|
|
42
|
+
module.exports = transformFieldNames;
|
package/lib/treeToList.js
CHANGED
|
@@ -1,99 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var isObject = require('./utils/type/isObject.js');
|
|
2
5
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _type = require("./utils/type");
|
|
8
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
-
/**
|
|
15
|
-
* 树结构转列表数据
|
|
16
|
-
*
|
|
17
|
-
* @static
|
|
18
|
-
* @alias module:Tree.treeToList
|
|
19
|
-
* @since 4.14.0
|
|
20
|
-
* @template {Record<string,any>} T
|
|
21
|
-
* @template {keyof T} K
|
|
22
|
-
* @template {Omit<T, K>} R
|
|
23
|
-
* @param {T[]} tree 列表数据
|
|
24
|
-
* @param {K} childrenField 子级字段名称
|
|
25
|
-
* @returns {R[]} 列表数据
|
|
26
|
-
* @example
|
|
27
|
-
* 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" }] }];
|
|
28
|
-
*
|
|
29
|
-
* treeToList(menus, 'children'));
|
|
30
|
-
* // [{"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"}]
|
|
31
|
-
*/
|
|
32
6
|
function treeToList(tree, childrenField) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
7
|
+
var list = [];
|
|
8
|
+
if (!Array.isArray(tree)) {
|
|
9
|
+
return list;
|
|
10
|
+
}
|
|
11
|
+
function recusion(arr) {
|
|
12
|
+
arr.forEach(function (item) {
|
|
13
|
+
if (isObject(item)) {
|
|
14
|
+
var newItem = tslib.__assign({}, item);
|
|
15
|
+
list.push(newItem);
|
|
16
|
+
if (newItem[childrenField]) {
|
|
17
|
+
if (Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
18
|
+
recusion(newItem[childrenField]);
|
|
19
|
+
}
|
|
20
|
+
delete newItem[childrenField];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
list.push(item);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
recusion(tree);
|
|
36
29
|
return list;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 递归遍历
|
|
41
|
-
* @param {T[]} arr 列表数据
|
|
42
|
-
*/
|
|
43
|
-
function recusion(arr) {
|
|
44
|
-
arr.forEach(function (item) {
|
|
45
|
-
if ((0, _type.isObject)(item)) {
|
|
46
|
-
var newItem = _objectSpread({}, item);
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
list.push(newItem);
|
|
49
|
-
if (newItem[childrenField]) {
|
|
50
|
-
if (Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
51
|
-
recusion(newItem[childrenField]);
|
|
52
|
-
}
|
|
53
|
-
delete newItem[childrenField];
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
list.push(item);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
recusion(tree);
|
|
62
|
-
return list;
|
|
63
30
|
}
|
|
64
31
|
|
|
65
|
-
|
|
66
|
-
// /** @type {R[]} */
|
|
67
|
-
// const list = [];
|
|
68
|
-
|
|
69
|
-
// // 深度优先
|
|
70
|
-
// /** @type {T[]} */
|
|
71
|
-
// const stack = [];
|
|
72
|
-
// for (const item of tree) {
|
|
73
|
-
// if (isObject(item)) {
|
|
74
|
-
// stack.push(item);
|
|
75
|
-
|
|
76
|
-
// while (stack.length) {
|
|
77
|
-
// /** @type {T} */
|
|
78
|
-
// // @ts-ignore
|
|
79
|
-
// const temp = stack.shift();
|
|
80
|
-
|
|
81
|
-
// // @ts-ignore
|
|
82
|
-
// list.push(temp);
|
|
83
|
-
|
|
84
|
-
// if (temp[childrenField]) {
|
|
85
|
-
// if (Array.isArray(temp[childrenField]) && temp[childrenField].length > 0) {
|
|
86
|
-
// stack.push(...temp[childrenField]);
|
|
87
|
-
// }
|
|
88
|
-
// delete temp[childrenField];
|
|
89
|
-
// }
|
|
90
|
-
// }
|
|
91
|
-
// } else {
|
|
92
|
-
// // @ts-ignore
|
|
93
|
-
// list.push(item);
|
|
94
|
-
// }
|
|
95
|
-
// }
|
|
96
|
-
// return list;
|
|
97
|
-
// }
|
|
98
|
-
var _default = treeToList;
|
|
99
|
-
exports["default"] = _default;
|
|
32
|
+
module.exports = treeToList;
|
package/lib/utils/config.js
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.config = void 0;
|
|
7
|
-
exports.setDisableWarning = setDisableWarning;
|
|
8
|
-
exports.version = void 0;
|
|
9
|
-
var config = {
|
|
10
|
-
// 禁用warning提示
|
|
11
|
-
disableWarning: true
|
|
3
|
+
exports.config = {
|
|
4
|
+
disableWarning: true
|
|
12
5
|
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 设置禁止warning提示
|
|
16
|
-
* @static
|
|
17
|
-
* @alias module:Debug.formatBankCard
|
|
18
|
-
* @since 3.6.1
|
|
19
|
-
* @param {boolean} bool 是否禁止warning提示
|
|
20
|
-
*/
|
|
21
|
-
exports.config = config;
|
|
22
6
|
function setDisableWarning(bool) {
|
|
23
|
-
|
|
7
|
+
exports.config.disableWarning = !!bool;
|
|
24
8
|
}
|
|
9
|
+
exports.version = "4.17.1";
|
|
25
10
|
|
|
26
|
-
|
|
27
|
-
var version = "4.16.2";
|
|
28
|
-
exports.version = version;
|
|
11
|
+
exports.setDisableWarning = setDisableWarning;
|
package/lib/utils/constants.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.MIN_SAFE_INTEGER = exports.MAX_SAFE_INTEGER = void 0;
|
|
7
|
-
// 最大安全数字
|
|
8
|
-
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
|
|
9
|
-
// 最小安全数字
|
|
10
|
-
exports.MAX_SAFE_INTEGER = MAX_SAFE_INTEGER;
|
|
11
|
-
var MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
|
|
12
|
-
exports.MIN_SAFE_INTEGER = MIN_SAFE_INTEGER;
|
|
3
|
+
exports.MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
|
|
4
|
+
exports.MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var isString = require('./type/isString.js');
|
|
2
4
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _isString = _interopRequireDefault(require("./type/isString"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
9
|
-
/**
|
|
10
|
-
* 转换为字符串
|
|
11
|
-
*
|
|
12
|
-
* @param {*} value 值
|
|
13
|
-
* @returns {string} 字符串
|
|
14
|
-
*/
|
|
15
5
|
function convertToString(value) {
|
|
16
|
-
|
|
6
|
+
return isString(value) ? value : String(value);
|
|
17
7
|
}
|
|
18
|
-
|
|
19
|
-
exports
|
|
8
|
+
|
|
9
|
+
module.exports = convertToString;
|
package/lib/utils/devWarn.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var config = require('./config.js');
|
|
2
5
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _config = require("./config");
|
|
8
|
-
/**
|
|
9
|
-
* 打印警告信息
|
|
10
|
-
*
|
|
11
|
-
* @param {any[]} args 打印的信息
|
|
12
|
-
*/
|
|
13
6
|
function devWarn() {
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
var args = [];
|
|
8
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
9
|
+
args[_i] = arguments[_i];
|
|
10
|
+
}
|
|
11
|
+
if (!config.config.disableWarning) {
|
|
12
|
+
console.warn.apply(console, tslib.__spreadArray([], tslib.__read(args), false));
|
|
13
|
+
}
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
exports
|
|
15
|
+
|
|
16
|
+
module.exports = devWarn;
|