@soratani-code/samtools 1.3.6 → 1.3.8

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 CHANGED
@@ -1,3 +1,4 @@
1
1
  export declare function findNodeFormKey<D = any>(key: string, nodes: D[], id: string): D;
2
2
  export declare function updateNodeFormKey<D = any>(key: string, nodes: D[], id: string, value: any): D[];
3
+ export declare function deleteNodeFormKey<D = any>(key: string, nodes: D[], id: string): D[];
3
4
  export declare function toList<D = any>(nodes: D[]): any[];
package/lib/tree.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toList = exports.updateNodeFormKey = exports.findNodeFormKey = void 0;
3
+ exports.toList = exports.deleteNodeFormKey = exports.updateNodeFormKey = exports.findNodeFormKey = void 0;
4
4
  const lodash_1 = require("lodash");
5
5
  function findNodeFormKey(key, nodes, id) {
6
6
  if (!id)
@@ -37,6 +37,29 @@ function updateNodeFormKey(key, nodes, id, value) {
37
37
  return null;
38
38
  }
39
39
  exports.updateNodeFormKey = updateNodeFormKey;
40
+ function deleteNodeFormKey(key, nodes, id) {
41
+ const tree = (0, lodash_1.cloneDeep)(nodes);
42
+ const queue = [...tree];
43
+ while (queue.length > 0) {
44
+ const node = queue.shift();
45
+ if (node[key] === id) {
46
+ return null;
47
+ }
48
+ if ((0, lodash_1.isArray)(node.children)) {
49
+ const newChildren = [];
50
+ const result = deleteNodeFormKey(key, node.children, id);
51
+ if (result) {
52
+ newChildren.push(...result);
53
+ }
54
+ node.children = newChildren;
55
+ }
56
+ if ((0, lodash_1.isArray)(node.children)) {
57
+ queue.push(...node.children);
58
+ }
59
+ }
60
+ return tree;
61
+ }
62
+ exports.deleteNodeFormKey = deleteNodeFormKey;
40
63
  function toList(nodes) {
41
64
  const tree = (0, lodash_1.cloneDeep)(nodes);
42
65
  const result = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soratani-code/samtools",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "",
5
5
  "typings": "lib/index.d.ts",
6
6
  "main": "lib/index.js",