@soratani-code/samtools 1.5.6 → 1.5.7
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/lib/tree.d.ts +10 -0
- package/lib/tree.js +37 -1
- package/package.json +7 -7
package/lib/tree.d.ts
CHANGED
|
@@ -3,3 +3,13 @@ export declare function updateNodeFormKey<D = any>(key: string, nodes: D[], id:
|
|
|
3
3
|
export declare function deleteNodeFormKey<D = any>(key: string, nodes: D[], id: string): D[];
|
|
4
4
|
export declare function toList<D = any>(nodes: D[]): any[];
|
|
5
5
|
export declare function slice<T extends Record<string, any>>(tree: T[] | T, level: number, childrenKey?: string): T | T[] | undefined;
|
|
6
|
+
type ToTreeOptions = {
|
|
7
|
+
idKey?: string;
|
|
8
|
+
parentKey?: string;
|
|
9
|
+
clone?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type ArrayTree<T extends Record<string, any>> = T & {
|
|
12
|
+
children?: ArrayTree<T>[];
|
|
13
|
+
};
|
|
14
|
+
export declare function toTree<T extends Record<string, any>>(items: T[] | null | undefined, rootValue: any, options?: ToTreeOptions): ArrayTree<T>[];
|
|
15
|
+
export {};
|
package/lib/tree.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.slice = exports.toList = exports.deleteNodeFormKey = exports.updateNodeFormKey = exports.findNodeFormKey = void 0;
|
|
3
|
+
exports.toTree = exports.slice = exports.toList = exports.deleteNodeFormKey = exports.updateNodeFormKey = exports.findNodeFormKey = void 0;
|
|
4
4
|
const tools_1 = require("./tools");
|
|
5
5
|
function findNodeFormKey(key, nodes, id) {
|
|
6
6
|
if (!id)
|
|
@@ -113,3 +113,39 @@ function slice(tree, level, childrenKey = 'children') {
|
|
|
113
113
|
return process([tree], level)[0];
|
|
114
114
|
}
|
|
115
115
|
exports.slice = slice;
|
|
116
|
+
function toTree(items, rootValue, options) {
|
|
117
|
+
var _a, _b;
|
|
118
|
+
if (!items || !items.length)
|
|
119
|
+
return [];
|
|
120
|
+
const idKey = (_a = options === null || options === void 0 ? void 0 : options.idKey) !== null && _a !== void 0 ? _a : 'id';
|
|
121
|
+
const parentKey = (_b = options === null || options === void 0 ? void 0 : options.parentKey) !== null && _b !== void 0 ? _b : 'parentId';
|
|
122
|
+
const childrenKey = 'children';
|
|
123
|
+
const rootParentValue = rootValue !== null && rootValue !== void 0 ? rootValue : null;
|
|
124
|
+
const doClone = (options === null || options === void 0 ? void 0 : options.clone) !== false;
|
|
125
|
+
const source = doClone ? (0, tools_1.cloneDeep)(items) : items;
|
|
126
|
+
const map = new Map();
|
|
127
|
+
for (const it of source) {
|
|
128
|
+
const id = it[idKey];
|
|
129
|
+
const node = Object.assign({}, it);
|
|
130
|
+
map.set(id, node);
|
|
131
|
+
}
|
|
132
|
+
const roots = [];
|
|
133
|
+
for (const it of source) {
|
|
134
|
+
const id = it[idKey];
|
|
135
|
+
const pid = it[parentKey];
|
|
136
|
+
const node = map.get(id);
|
|
137
|
+
if (pid === rootParentValue || pid == null || !map.has(pid)) {
|
|
138
|
+
roots.push(node);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const parent = map.get(pid);
|
|
142
|
+
if (node) {
|
|
143
|
+
if (!parent[childrenKey])
|
|
144
|
+
parent[childrenKey] = [];
|
|
145
|
+
parent[childrenKey].push(node);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return roots;
|
|
150
|
+
}
|
|
151
|
+
exports.toTree = toTree;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soratani-code/samtools",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -31,16 +31,16 @@
|
|
|
31
31
|
"homepage": "https://github.com/soratani/samtools#readme",
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@changesets/cli": "^2.26.1",
|
|
34
|
-
"@rollup/plugin-commonjs": "^
|
|
35
|
-
"@rollup/plugin-node-resolve": "^
|
|
34
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
35
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
36
36
|
"@rollup/plugin-terser": "^0.4.4",
|
|
37
|
-
"@rollup/plugin-typescript": "^
|
|
37
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
38
38
|
"@types/enzyme": "^3.10.13",
|
|
39
|
-
"@types/jest": "^
|
|
40
|
-
"@types/node": "^
|
|
39
|
+
"@types/jest": "^30.0.0",
|
|
40
|
+
"@types/node": "^25.0.1",
|
|
41
41
|
"@types/platform": "^1.3.3",
|
|
42
42
|
"enzyme": "^3.11.0",
|
|
43
|
-
"jest": "^
|
|
43
|
+
"jest": "^30.2.0",
|
|
44
44
|
"jest-enzyme": "^7.1.2",
|
|
45
45
|
"rollup": "^4.14.2",
|
|
46
46
|
"ts-jest": "^29.1.0",
|