qmwts 1.1.47 → 1.1.49
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.
|
@@ -6,6 +6,6 @@ declare const _default: {
|
|
|
6
6
|
* @param parentKey 关联上级字段
|
|
7
7
|
* @param childrenKey 下级字段
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
treeify<T>(array?: any[], idKey?: string, parentKey?: string, childrenKey?: string): T[];
|
|
10
10
|
};
|
|
11
11
|
export default _default;
|
|
@@ -19,24 +19,26 @@ exports.default = {
|
|
|
19
19
|
* @param parentKey 关联上级字段
|
|
20
20
|
* @param childrenKey 下级字段
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
treeify: function (array, idKey, parentKey, childrenKey) {
|
|
23
23
|
if (array === void 0) { array = []; }
|
|
24
24
|
if (idKey === void 0) { idKey = 'id'; }
|
|
25
25
|
if (parentKey === void 0) { parentKey = 'parentId'; }
|
|
26
26
|
if (childrenKey === void 0) { childrenKey = 'children'; }
|
|
27
27
|
var map = new Map(); // 先根据每项的parentId将该项放入Map
|
|
28
|
+
var ids = []; // 记录所有的id,parentId不在这个集合内则说明是最上级
|
|
28
29
|
for (var i = array.length - 1; i >= 0; i--) {
|
|
29
|
-
var _a = array, _b = i, e = _a[_b], _c = e, _d = parentKey, pid = _c[
|
|
30
|
+
var _a = array, _b = i, e = _a[_b], _c = e, _d = idKey, id = _c[_d], _e = parentKey, pid = _c[_e];
|
|
30
31
|
var children = map.get(pid) || [];
|
|
31
32
|
children.unshift(__assign({}, e));
|
|
32
33
|
map.set(pid, children);
|
|
34
|
+
ids.push(id);
|
|
33
35
|
}
|
|
34
36
|
var o = [];
|
|
35
37
|
var values = Array.from(map.values()).flat();
|
|
36
38
|
for (var i = values.length - 1; i >= 0; i--) {
|
|
37
|
-
var
|
|
39
|
+
var _f = values, _g = i, e = _f[_g], _h = e, _j = idKey, id = _h[_j], _k = parentKey, pid = _h[_k];
|
|
38
40
|
e[childrenKey] = map.get(id); // 赋值children
|
|
39
|
-
if (!pid) // 只返回最上级
|
|
41
|
+
if (!ids.includes(pid)) // 只返回最上级
|
|
40
42
|
o.unshift(e);
|
|
41
43
|
}
|
|
42
44
|
return o;
|
|
@@ -3,7 +3,7 @@ declare const _default: {
|
|
|
3
3
|
isArray(o: any): boolean;
|
|
4
4
|
parseObject<T>(o: any): T;
|
|
5
5
|
parseArray<T>(o: any): T[];
|
|
6
|
-
optionalChaining(o: any, chain: string, substitute?: any): any;
|
|
6
|
+
optionalChaining(o: any | undefined, chain: string, substitute?: any): any;
|
|
7
7
|
setNull(o?: any, exclusions?: any): void;
|
|
8
8
|
};
|
|
9
9
|
export default _default;
|
|
@@ -10,10 +10,12 @@ exports.default = {
|
|
|
10
10
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
11
11
|
number[_i] = arguments[_i];
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
e = String(
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
for (var i = number.length - 1; i >= 0; i--) {
|
|
14
|
+
var e = String(number[i]).trim();
|
|
15
|
+
if (e === '' || !isFinite(+e) || isNaN(+e))
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
17
19
|
},
|
|
18
20
|
// 增加千分位分隔符
|
|
19
21
|
thousandths: function (number, fixed) {
|
|
@@ -29,8 +31,13 @@ exports.default = {
|
|
|
29
31
|
return number;
|
|
30
32
|
},
|
|
31
33
|
summation: function (array) {
|
|
32
|
-
var _this = this;
|
|
33
34
|
if (array === void 0) { array = []; }
|
|
34
|
-
|
|
35
|
+
var sum = 0;
|
|
36
|
+
for (var i = array.length - 1; i >= 0; i--) {
|
|
37
|
+
var e = +array[i];
|
|
38
|
+
if (this.isNumber(e))
|
|
39
|
+
sum += e;
|
|
40
|
+
}
|
|
41
|
+
return sum;
|
|
35
42
|
},
|
|
36
43
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qmwts",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.49",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"jest": "^29.7.0",
|
|
15
15
|
"ts-jest": "^29.2.5",
|
|
16
|
-
"typescript": "^5.
|
|
16
|
+
"typescript": "^5.8.2"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|