tree-processor 0.8.1 → 0.9.0
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/README.en.md +1307 -0
- package/README.md +333 -92
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/stats.html +1 -1
- package/dist/tree-processor.cjs.js +130 -95
- package/dist/tree-processor.esm.js +72 -37
- package/dist/tree-processor.umd.js +70 -35
- package/package.json +11 -10
package/README.md
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
# tree-processor
|
|
2
2
|
|
|
3
|
+
<div align="right">
|
|
4
|
+
|
|
5
|
+
[English](https://github.com/knott11/tree-processor/blob/main/README.en.md) | [中文](https://github.com/knott11/tree-processor/blob/main/README.md)
|
|
6
|
+
|
|
7
|
+
</div>
|
|
8
|
+
|
|
3
9
|
<div align="center">
|
|
4
10
|
|
|
5
11
|

|
|
6
|
-

|
|
12
|
+

|
|
13
|
+

|
|
9
14
|

|
|
10
|
-

|
|
11
16
|
|
|
12
|
-
一个轻量级的树结构数据处理工具库,使用 TypeScript 编写,支持 tree-shaking,每个格式打包体积约 **
|
|
17
|
+
一个轻量级的树结构数据处理工具库,使用 TypeScript 编写,支持 tree-shaking,每个格式打包体积约 **8.2-8.5 KB**(ESM: 8.24 KB,CJS: 8.51 KB,UMD: 8.52 KB)。
|
|
13
18
|
|
|
14
19
|
|
|
15
20
|
</div>
|
|
@@ -23,29 +28,26 @@
|
|
|
23
28
|
- [API 文档](#-api-文档)
|
|
24
29
|
- [遍历方法](#遍历方法)
|
|
25
30
|
- [查找方法](#查找方法)
|
|
31
|
+
- [访问方法](#访问方法)
|
|
26
32
|
- [修改方法](#修改方法)
|
|
27
|
-
- [
|
|
28
|
-
- [
|
|
33
|
+
- [转换方法](#转换方法)
|
|
34
|
+
- [查询方法](#查询方法)
|
|
35
|
+
- [验证方法](#验证方法)
|
|
29
36
|
- [自定义字段名](#自定义字段名)
|
|
30
37
|
- [测试](#测试)
|
|
31
38
|
- [开发](#开发)
|
|
32
|
-
- [技术栈](#技术栈)
|
|
33
|
-
- [贡献](#-贡献)
|
|
34
|
-
- [更新日志](#-更新日志)
|
|
35
|
-
- [许可证](#-许可证)
|
|
36
|
-
- [相关链接](#-相关链接)
|
|
37
39
|
|
|
38
40
|
## ✨ 特性
|
|
39
41
|
|
|
40
|
-
- **轻量级** - 每个格式打包体积仅
|
|
42
|
+
- **轻量级** - 每个格式打包体积仅 8.2-8.5 KB(ESM: 8.24 KB,CJS: 8.51 KB,UMD: 8.52 KB),对项目体积影响极小
|
|
41
43
|
- **支持 Tree-shaking** - 支持按需导入,只打包实际使用的代码,进一步减小打包体积
|
|
42
44
|
- **完整的 TypeScript 支持** - 提供完整的类型定义和智能提示,提升开发体验
|
|
43
45
|
- **灵活的自定义字段名** - 支持自定义 children 和 id 字段名,适配各种数据结构
|
|
44
46
|
- **零依赖** - 无任何外部依赖,开箱即用,无需担心依赖冲突
|
|
45
|
-
- **完善的测试覆盖** - 包含
|
|
46
|
-
- **丰富的 API** - 提供
|
|
47
|
+
- **完善的测试覆盖** - 包含 328 个测试用例,测试覆盖率达到 99%+(语句覆盖率 99%,分支覆盖率 98.41%,函数覆盖率 100%,行覆盖率 98.99%),覆盖基础功能、边界情况、异常处理、复杂场景等
|
|
48
|
+
- **丰富的 API** - 提供 32+ 个方法,包含类似数组的 API(map、filter、find、some、every等),以及树结构特有的操作(获取父子节点、深度计算、数据验证、格式转换等),涵盖遍历、查找、修改、转换、判断等完整场景
|
|
47
49
|
|
|
48
|
-
**已支持的方法:** mapTree、forEachTree、filterTree、findTree、pushTree、unshiftTree、popTree、shiftTree、someTree、everyTree、includesTree、atTree、indexOfTree、atIndexOfTree、dedupTree、removeTree、getParentTree、getChildrenTree、getSiblingsTree、getNodeDepthMap、getNodeDepth、isLeafNode、isRootNode、isEmptyTreeData、isEmptySingleTreeData、isTreeData、isSingleTreeData、isValidTreeNode、isTreeNodeWithCircularCheck、isSafeTreeDepth。每个方法的最后一个参数可以自定义 children 和 id 的属性名。
|
|
50
|
+
**已支持的方法:** mapTree、forEachTree、filterTree、findTree、pushTree、unshiftTree、popTree、shiftTree、someTree、everyTree、includesTree、atTree、indexOfTree、atIndexOfTree、dedupTree、removeTree、getParentTree、getChildrenTree、getSiblingsTree、getNodeDepthMap、getNodeDepth、isLeafNode、isRootNode、isEmptyTreeData、isEmptySingleTreeData、isTreeData、isSingleTreeData、isValidTreeNode、isTreeNodeWithCircularCheck、isSafeTreeDepth、convertToArrayTree、convertBackTree、convertToMapTree、convertToLevelArrayTree、convertToObjectTree。每个方法的最后一个参数可以自定义 children 和 id 的属性名。
|
|
49
51
|
|
|
50
52
|
### 💡 使用场景
|
|
51
53
|
|
|
@@ -100,8 +102,6 @@ console.log(filtered) // [{ id: 2, name: 'node2' }, { id: 3, name: 'node3' }]
|
|
|
100
102
|
|
|
101
103
|
#### 默认导入(推荐用于需要多个方法的场景)
|
|
102
104
|
|
|
103
|
-
#### 默认导入(推荐用于需要多个方法的场景)
|
|
104
|
-
|
|
105
105
|
```javascript
|
|
106
106
|
// ES Module
|
|
107
107
|
import t from 'tree-processor'
|
|
@@ -123,16 +123,6 @@ import type { TreeNode, TreeData, FieldNames } from 'tree-processor'
|
|
|
123
123
|
const { mapTree, filterTree } = require('tree-processor')
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
**按需导入的优势:**
|
|
127
|
-
- ✅ 支持 tree-shaking,只打包使用的代码,减小打包体积
|
|
128
|
-
- ✅ 更好的代码提示和类型检查
|
|
129
|
-
- ✅ 更清晰的依赖关系
|
|
130
|
-
|
|
131
|
-
**关于类型导入:**
|
|
132
|
-
- TypeScript 会自动从函数签名推断类型,**大多数情况下不需要显式引入类型**
|
|
133
|
-
- 只有在需要显式声明变量类型时才需要引入类型(如 `const treeData: TreeData = [...]`)
|
|
134
|
-
- 使用 `import type` 导入类型不会增加运行时体积(类型在编译时会被移除)
|
|
135
|
-
|
|
136
126
|
### 示例数据
|
|
137
127
|
|
|
138
128
|
以下示例数据将用于后续所有方法的演示:
|
|
@@ -210,6 +200,10 @@ t.forEachTree(treeData, () => {
|
|
|
210
200
|
console.log(nodeCount) // 节点总数
|
|
211
201
|
```
|
|
212
202
|
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 查找方法
|
|
206
|
+
|
|
213
207
|
### filterTree
|
|
214
208
|
|
|
215
209
|
过滤树结构数据,返回满足条件的节点。
|
|
@@ -232,10 +226,6 @@ const leafNodes = t.filterTree(treeData, (node) => {
|
|
|
232
226
|
console.log(leafNodes) // 返回所有叶子节点
|
|
233
227
|
```
|
|
234
228
|
|
|
235
|
-
---
|
|
236
|
-
|
|
237
|
-
## 查找方法
|
|
238
|
-
|
|
239
229
|
### findTree
|
|
240
230
|
|
|
241
231
|
查找树结构数据中满足条件的第一个节点。如果未找到,返回 null。
|
|
@@ -265,6 +255,38 @@ const hasNode = t.includesTree(treeData, nodeId)
|
|
|
265
255
|
console.log(hasNode) // true 表示包含该节点,false 表示不包含
|
|
266
256
|
```
|
|
267
257
|
|
|
258
|
+
### someTree
|
|
259
|
+
|
|
260
|
+
检查树结构数据中是否存在满足条件的节点。只要有一个节点满足条件就返回 true。
|
|
261
|
+
|
|
262
|
+
```javascript
|
|
263
|
+
// 检查是否存在名称为 'node2' 的节点
|
|
264
|
+
const hasNode2 = t.someTree(treeData, node => node.name === 'node2')
|
|
265
|
+
console.log(hasNode2) // true
|
|
266
|
+
|
|
267
|
+
// 检查是否存在ID大于10的节点
|
|
268
|
+
const hasLargeId = t.someTree(treeData, node => node.id > 10)
|
|
269
|
+
console.log(hasLargeId) // false
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### everyTree
|
|
273
|
+
|
|
274
|
+
检查树结构数据中是否所有节点都满足条件。只有所有节点都满足条件才返回 true。
|
|
275
|
+
|
|
276
|
+
```javascript
|
|
277
|
+
// 检查所有节点的ID是否都大于0
|
|
278
|
+
const allIdsPositive = t.everyTree(treeData, node => node.id > 0)
|
|
279
|
+
console.log(allIdsPositive) // true
|
|
280
|
+
|
|
281
|
+
// 检查所有节点是否都有 name 属性
|
|
282
|
+
const allHaveName = t.everyTree(treeData, node => node.name)
|
|
283
|
+
console.log(allHaveName) // 根据实际数据返回 true 或 false
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## 访问方法
|
|
289
|
+
|
|
268
290
|
### atTree
|
|
269
291
|
|
|
270
292
|
根据父节点ID和子节点索引获取节点。支持负数索引,和数组的 at 方法一样。未找到返回 null。
|
|
@@ -403,36 +425,282 @@ console.log(uniqueByNameTree) // 返回根据 name 去重后的数据
|
|
|
403
425
|
|
|
404
426
|
---
|
|
405
427
|
|
|
406
|
-
##
|
|
428
|
+
## 转换方法
|
|
407
429
|
|
|
408
|
-
###
|
|
430
|
+
### convertToArrayTree
|
|
409
431
|
|
|
410
|
-
|
|
432
|
+
将树结构数据扁平化为数组。返回的数组中每个节点都不包含 `children` 字段。
|
|
411
433
|
|
|
412
434
|
```javascript
|
|
413
|
-
//
|
|
414
|
-
const
|
|
415
|
-
console.log(
|
|
435
|
+
// 将树结构扁平化为数组
|
|
436
|
+
const array = t.convertToArrayTree(treeData)
|
|
437
|
+
console.log(array)
|
|
438
|
+
// [
|
|
439
|
+
// { id: 1, name: 'node1' },
|
|
440
|
+
// { id: 2, name: 'node2' },
|
|
441
|
+
// { id: 4, name: 'node4' },
|
|
442
|
+
// { id: 5, name: 'node5' },
|
|
443
|
+
// { id: 3, name: 'node3' },
|
|
444
|
+
// { id: 6, name: 'node6' }
|
|
445
|
+
// ]
|
|
446
|
+
|
|
447
|
+
// 注意:返回的节点不包含 children 字段
|
|
448
|
+
array.forEach(node => {
|
|
449
|
+
console.log(node.children) // undefined
|
|
450
|
+
})
|
|
416
451
|
|
|
417
|
-
//
|
|
418
|
-
const
|
|
419
|
-
|
|
452
|
+
// 支持自定义字段名
|
|
453
|
+
const customTree = [
|
|
454
|
+
{
|
|
455
|
+
nodeId: 1,
|
|
456
|
+
name: 'node1',
|
|
457
|
+
subNodes: [
|
|
458
|
+
{ nodeId: 2, name: 'node2' }
|
|
459
|
+
]
|
|
460
|
+
}
|
|
461
|
+
]
|
|
462
|
+
const customArray = t.convertToArrayTree(customTree, {
|
|
463
|
+
children: 'subNodes',
|
|
464
|
+
id: 'nodeId'
|
|
465
|
+
})
|
|
466
|
+
console.log(customArray) // 扁平化后的数组,不包含 subNodes 字段
|
|
420
467
|
```
|
|
421
468
|
|
|
422
|
-
###
|
|
469
|
+
### convertToMapTree
|
|
423
470
|
|
|
424
|
-
|
|
471
|
+
将树结构数据转换为 Map,key 为节点 ID,value 为节点对象(不包含 children 字段)。适用于需要快速通过 ID 查找节点的场景。
|
|
425
472
|
|
|
426
473
|
```javascript
|
|
427
|
-
//
|
|
428
|
-
const
|
|
429
|
-
console.log(
|
|
474
|
+
// 将树结构转换为 Map
|
|
475
|
+
const map = t.convertToMapTree(treeData)
|
|
476
|
+
console.log(map instanceof Map) // true
|
|
477
|
+
console.log(map.size) // 6
|
|
430
478
|
|
|
431
|
-
//
|
|
432
|
-
const
|
|
433
|
-
console.log(
|
|
479
|
+
// 通过 ID 快速查找节点
|
|
480
|
+
const node = map.get(2)
|
|
481
|
+
console.log(node) // { id: 2, name: 'node2' }
|
|
482
|
+
console.log(node.children) // undefined(不包含 children 字段)
|
|
483
|
+
|
|
484
|
+
// 支持自定义字段名
|
|
485
|
+
const customTree = [
|
|
486
|
+
{
|
|
487
|
+
nodeId: 1,
|
|
488
|
+
name: 'node1',
|
|
489
|
+
subNodes: [
|
|
490
|
+
{ nodeId: 2, name: 'node2' }
|
|
491
|
+
]
|
|
492
|
+
}
|
|
493
|
+
]
|
|
494
|
+
const customMap = t.convertToMapTree(customTree, {
|
|
495
|
+
children: 'subNodes',
|
|
496
|
+
id: 'nodeId'
|
|
497
|
+
})
|
|
498
|
+
console.log(customMap.get(1)) // { nodeId: 1, name: 'node1' }
|
|
434
499
|
```
|
|
435
500
|
|
|
501
|
+
### convertToLevelArrayTree
|
|
502
|
+
|
|
503
|
+
将树结构数据转换为层级数组(二维数组),按深度分组。外层数组按深度索引,内层数组包含该深度的所有节点。
|
|
504
|
+
|
|
505
|
+
```javascript
|
|
506
|
+
// 将树结构转换为层级数组
|
|
507
|
+
const levelArray = t.convertToLevelArrayTree(treeData)
|
|
508
|
+
console.log(levelArray)
|
|
509
|
+
// [
|
|
510
|
+
// [{ id: 1, name: 'node1' }], // 第 0 层
|
|
511
|
+
// [{ id: 2, name: 'node2' }, { id: 3, name: 'node3' }], // 第 1 层
|
|
512
|
+
// [{ id: 4, name: 'node4' }, { id: 5, name: 'node5' }, { id: 6, name: 'node6' }] // 第 2 层
|
|
513
|
+
// ]
|
|
514
|
+
|
|
515
|
+
// 遍历每一层
|
|
516
|
+
levelArray.forEach((level, depth) => {
|
|
517
|
+
console.log(`深度 ${depth}:`, level)
|
|
518
|
+
})
|
|
519
|
+
|
|
520
|
+
// 注意:返回的节点不包含 children 字段
|
|
521
|
+
levelArray[0][0].children // undefined
|
|
522
|
+
|
|
523
|
+
// 支持自定义字段名
|
|
524
|
+
const customTree = [
|
|
525
|
+
{
|
|
526
|
+
nodeId: 1,
|
|
527
|
+
name: 'node1',
|
|
528
|
+
subNodes: [
|
|
529
|
+
{ nodeId: 2, name: 'node2' }
|
|
530
|
+
]
|
|
531
|
+
}
|
|
532
|
+
]
|
|
533
|
+
const customLevelArray = t.convertToLevelArrayTree(customTree, {
|
|
534
|
+
children: 'subNodes',
|
|
535
|
+
id: 'nodeId'
|
|
536
|
+
})
|
|
537
|
+
console.log(customLevelArray) // 按层级分组的数组
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
### convertToObjectTree
|
|
541
|
+
|
|
542
|
+
将单根树结构数据转换为对象。如果树只有一个根节点,返回该节点对象;否则返回 `null`。
|
|
543
|
+
|
|
544
|
+
```javascript
|
|
545
|
+
// 单根树转换为对象
|
|
546
|
+
const singleRootTree = [
|
|
547
|
+
{
|
|
548
|
+
id: 1,
|
|
549
|
+
name: 'node1',
|
|
550
|
+
value: 100,
|
|
551
|
+
children: [
|
|
552
|
+
{ id: 2, name: 'node2' }
|
|
553
|
+
]
|
|
554
|
+
}
|
|
555
|
+
]
|
|
556
|
+
const rootNode = t.convertToObjectTree(singleRootTree)
|
|
557
|
+
console.log(rootNode)
|
|
558
|
+
// {
|
|
559
|
+
// id: 1,
|
|
560
|
+
// name: 'node1',
|
|
561
|
+
// value: 100,
|
|
562
|
+
// children: [{ id: 2, name: 'node2' }]
|
|
563
|
+
// }
|
|
564
|
+
|
|
565
|
+
// 多个根节点返回 null
|
|
566
|
+
const multiRootTree = [
|
|
567
|
+
{ id: 1, name: 'node1' },
|
|
568
|
+
{ id: 2, name: 'node2' }
|
|
569
|
+
]
|
|
570
|
+
const result = t.convertToObjectTree(multiRootTree)
|
|
571
|
+
console.log(result) // null
|
|
572
|
+
|
|
573
|
+
// 空树返回 null
|
|
574
|
+
const emptyTree = []
|
|
575
|
+
const emptyResult = t.convertToObjectTree(emptyTree)
|
|
576
|
+
console.log(emptyResult) // null
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
### convertBackTree
|
|
580
|
+
|
|
581
|
+
将各种数据结构转换为树结构数据。支持数组、Map、Record(对象)等格式。数组中的每个元素需要包含 `id` 和 `parentId` 字段。
|
|
582
|
+
|
|
583
|
+
```javascript
|
|
584
|
+
// 将扁平数组转换为树结构
|
|
585
|
+
const array = [
|
|
586
|
+
{ id: 1, name: 'node1', parentId: null },
|
|
587
|
+
{ id: 2, name: 'node2', parentId: 1 },
|
|
588
|
+
{ id: 3, name: 'node3', parentId: 1 },
|
|
589
|
+
{ id: 4, name: 'node4', parentId: 2 },
|
|
590
|
+
{ id: 5, name: 'node5', parentId: 2 },
|
|
591
|
+
{ id: 6, name: 'node6', parentId: 3 }
|
|
592
|
+
]
|
|
593
|
+
const tree = t.convertBackTree(array)
|
|
594
|
+
console.log(tree)
|
|
595
|
+
// [
|
|
596
|
+
// {
|
|
597
|
+
// id: 1,
|
|
598
|
+
// name: 'node1',
|
|
599
|
+
// children: [
|
|
600
|
+
// {
|
|
601
|
+
// id: 2,
|
|
602
|
+
// name: 'node2',
|
|
603
|
+
// children: [
|
|
604
|
+
// { id: 4, name: 'node4', children: [] },
|
|
605
|
+
// { id: 5, name: 'node5', children: [] }
|
|
606
|
+
// ]
|
|
607
|
+
// },
|
|
608
|
+
// {
|
|
609
|
+
// id: 3,
|
|
610
|
+
// name: 'node3',
|
|
611
|
+
// children: [
|
|
612
|
+
// { id: 6, name: 'node6', children: [] }
|
|
613
|
+
// ]
|
|
614
|
+
// }
|
|
615
|
+
// ]
|
|
616
|
+
// }
|
|
617
|
+
// ]
|
|
618
|
+
|
|
619
|
+
// 自定义根节点的 parentId 值
|
|
620
|
+
const arrayWithZero = [
|
|
621
|
+
{ id: 1, name: 'node1', parentId: 0 },
|
|
622
|
+
{ id: 2, name: 'node2', parentId: 1 }
|
|
623
|
+
]
|
|
624
|
+
const treeWithZero = t.convertBackTree(arrayWithZero, { rootParentId: 0 })
|
|
625
|
+
console.log(treeWithZero) // 正确转换
|
|
626
|
+
|
|
627
|
+
// 自定义 parentId 字段名
|
|
628
|
+
const arrayWithPid = [
|
|
629
|
+
{ id: 1, name: 'node1', pid: null },
|
|
630
|
+
{ id: 2, name: 'node2', pid: 1 }
|
|
631
|
+
]
|
|
632
|
+
const treeWithPid = t.convertBackTree(arrayWithPid, { parentIdField: 'pid' })
|
|
633
|
+
console.log(treeWithPid) // 正确转换
|
|
634
|
+
|
|
635
|
+
// 支持自定义字段名
|
|
636
|
+
const customArray = [
|
|
637
|
+
{ nodeId: 1, name: 'node1', parentId: null },
|
|
638
|
+
{ nodeId: 2, name: 'node2', parentId: 1 }
|
|
639
|
+
]
|
|
640
|
+
const customTree = t.convertBackTree(customArray, {
|
|
641
|
+
fieldNames: { id: 'nodeId', children: 'subNodes' }
|
|
642
|
+
})
|
|
643
|
+
console.log(customTree)
|
|
644
|
+
// [
|
|
645
|
+
// {
|
|
646
|
+
// nodeId: 1,
|
|
647
|
+
// name: 'node1',
|
|
648
|
+
// subNodes: [
|
|
649
|
+
// { nodeId: 2, name: 'node2', subNodes: [] }
|
|
650
|
+
// ]
|
|
651
|
+
// }
|
|
652
|
+
// ]
|
|
653
|
+
|
|
654
|
+
// 处理多个根节点
|
|
655
|
+
const multiRootArray = [
|
|
656
|
+
{ id: 1, name: 'root1', parentId: null },
|
|
657
|
+
{ id: 2, name: 'root2', parentId: null },
|
|
658
|
+
{ id: 3, name: 'child1', parentId: 1 }
|
|
659
|
+
]
|
|
660
|
+
const multiRootTree = t.convertBackTree(multiRootArray)
|
|
661
|
+
console.log(multiRootTree) // 包含两个根节点
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
**参数说明:**
|
|
665
|
+
- `data` - 支持多种数据格式:
|
|
666
|
+
- 数组:扁平数组,每个元素需要包含 `id` 和 `parentId` 字段
|
|
667
|
+
- Map:key 为节点 ID,value 为节点对象
|
|
668
|
+
- Record(对象):key 为节点 ID,value 为节点对象
|
|
669
|
+
- 单个对象:单个树节点对象
|
|
670
|
+
- `options.rootParentId` - 根节点的 parentId 值,默认为 `null`
|
|
671
|
+
- `options.parentIdField` - 父节点ID字段名,默认为 `'parentId'`
|
|
672
|
+
- `options.fieldNames` - 自定义字段名配置,支持自定义 `id` 和 `children` 字段名
|
|
673
|
+
|
|
674
|
+
**注意事项:**
|
|
675
|
+
- 如果节点的 `parentId` 找不到对应的父节点,该节点会被作为根节点处理
|
|
676
|
+
- 没有 `id` 的节点会被跳过
|
|
677
|
+
- `parentId` 为 `null`、`undefined` 或等于 `rootParentId` 的节点会被视为根节点
|
|
678
|
+
- Map 和 Record 格式转换时,key 会被设置为节点的 `id`
|
|
679
|
+
|
|
680
|
+
**示例:支持 Map 和 Record 格式**
|
|
681
|
+
|
|
682
|
+
```javascript
|
|
683
|
+
// Map 格式
|
|
684
|
+
const map = new Map([
|
|
685
|
+
[1, { name: 'node1', parentId: null }],
|
|
686
|
+
[2, { name: 'node2', parentId: 1 }]
|
|
687
|
+
])
|
|
688
|
+
const treeFromMap = t.convertBackTree(map)
|
|
689
|
+
console.log(treeFromMap) // 正确转换为树结构
|
|
690
|
+
|
|
691
|
+
// Record 格式
|
|
692
|
+
const record = {
|
|
693
|
+
1: { name: 'node1', parentId: null },
|
|
694
|
+
2: { name: 'node2', parentId: 1 }
|
|
695
|
+
}
|
|
696
|
+
const treeFromRecord = t.convertBackTree(record)
|
|
697
|
+
console.log(treeFromRecord) // 正确转换为树结构
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
---
|
|
701
|
+
|
|
702
|
+
## 查询方法
|
|
703
|
+
|
|
436
704
|
### getParentTree
|
|
437
705
|
|
|
438
706
|
获取指定节点的父节点。如果节点是根节点或未找到,返回 null。
|
|
@@ -522,10 +790,6 @@ const customSiblings = t.getSiblingsTree(customTree, 2, fieldNames)
|
|
|
522
790
|
console.log(customSiblings) // 返回兄弟节点数组(包括自己)
|
|
523
791
|
```
|
|
524
792
|
|
|
525
|
-
---
|
|
526
|
-
|
|
527
|
-
## 工具方法
|
|
528
|
-
|
|
529
793
|
### getNodeDepthMap
|
|
530
794
|
|
|
531
795
|
返回一个字典,键代表节点的 id,值代表该节点在数据的第几层。深度从1开始,根节点深度为1。
|
|
@@ -584,6 +848,10 @@ console.log(depth) // 2
|
|
|
584
848
|
- `getNodeDepthMap` - 批量获取所有节点的深度(一次性计算所有节点)
|
|
585
849
|
- `getNodeDepth` - 只获取单个节点的深度(只计算目标节点,效率更高)
|
|
586
850
|
|
|
851
|
+
---
|
|
852
|
+
|
|
853
|
+
## 验证方法
|
|
854
|
+
|
|
587
855
|
### isLeafNode
|
|
588
856
|
|
|
589
857
|
检查节点是否是叶子节点(没有子节点)。轻量级方法,只检查节点本身,不遍历树。
|
|
@@ -1001,14 +1269,20 @@ const foundNode2 = t.findTree(customTreeData, (node) => node.nodeId === 2, field
|
|
|
1001
1269
|
### 运行测试
|
|
1002
1270
|
|
|
1003
1271
|
```bash
|
|
1004
|
-
#
|
|
1272
|
+
# 运行所有测试(自动打包后测试源码 + 打包文件,656 个测试用例)
|
|
1005
1273
|
npm test
|
|
1006
1274
|
|
|
1275
|
+
# 运行所有测试(单次,不监听文件变化)
|
|
1276
|
+
npm test -- --run
|
|
1277
|
+
|
|
1278
|
+
# 仅测试源代码(328 个测试用例)
|
|
1279
|
+
npm run test:src
|
|
1280
|
+
|
|
1281
|
+
# 仅测试打包后的文件(328 个测试用例,需要先运行 npm run build)
|
|
1282
|
+
npm run test:dist
|
|
1283
|
+
|
|
1007
1284
|
# 运行测试并生成覆盖率报告
|
|
1008
1285
|
npm run test:coverage
|
|
1009
|
-
|
|
1010
|
-
# 运行测试(单次,不监听文件变化)
|
|
1011
|
-
npm test -- --run
|
|
1012
1286
|
```
|
|
1013
1287
|
|
|
1014
1288
|
## 开发
|
|
@@ -1020,47 +1294,14 @@ npm install
|
|
|
1020
1294
|
# 运行测试
|
|
1021
1295
|
npm test
|
|
1022
1296
|
|
|
1023
|
-
#
|
|
1297
|
+
# 构建项目(先删除 dist 目录,然后重新打包)
|
|
1024
1298
|
npm run build
|
|
1025
1299
|
```
|
|
1026
1300
|
|
|
1027
|
-
## 技术栈
|
|
1028
|
-
|
|
1029
|
-
- **Rollup** - 模块打包工具
|
|
1030
|
-
- **Vitest** - 单元测试框架
|
|
1031
|
-
- **Terser** - JavaScript 压缩工具
|
|
1032
|
-
- **TypeScript** - 类型支持
|
|
1033
|
-
|
|
1034
|
-
## 🤝 贡献
|
|
1035
|
-
|
|
1036
|
-
欢迎贡献!如果你有任何想法或发现问题,请:
|
|
1037
|
-
|
|
1038
|
-
1. Fork 本仓库
|
|
1039
|
-
2. 创建你的特性分支 (`git checkout -b feature/AmazingFeature`)
|
|
1040
|
-
3. 提交你的更改 (`git commit -m 'Add some AmazingFeature'`)
|
|
1041
|
-
4. 推送到分支 (`git push origin feature/AmazingFeature`)
|
|
1042
|
-
5. 开启一个 Pull Request
|
|
1043
|
-
|
|
1044
|
-
## 📝 更新日志
|
|
1045
|
-
|
|
1046
|
-
查看 [CHANGELOG.md](./CHANGELOG.md) 了解详细的版本更新记录。
|
|
1047
|
-
|
|
1048
|
-
## 📄 许可证
|
|
1049
|
-
|
|
1050
|
-
本项目采用 [MIT](./LICENSE) 许可证。
|
|
1051
|
-
|
|
1052
|
-
## 🔗 相关链接
|
|
1053
|
-
|
|
1054
|
-
- [GitHub 仓库](https://github.com/knott11/tree-processor)
|
|
1055
|
-
- [npm 包](https://www.npmjs.com/package/tree-processor)
|
|
1056
|
-
- [问题反馈](https://github.com/knott11/tree-processor/issues)
|
|
1057
|
-
|
|
1058
|
-
---
|
|
1059
|
-
|
|
1060
1301
|
<div align="center">
|
|
1061
1302
|
|
|
1062
1303
|
如果这个项目对你有帮助,请给它一个 ⭐️
|
|
1063
1304
|
|
|
1064
|
-
Made with
|
|
1305
|
+
Made with by [knott11]
|
|
1065
1306
|
|
|
1066
1307
|
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2016.intl.d.ts","../node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../node_modules/typescript/lib/lib.es2017.date.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../node_modules/tslib/tslib.d.ts","../src/index.ts","../node_modules/@types/deep-eql/index.d.ts","../node_modules/assertion-error/index.d.ts","../node_modules/@types/chai/index.d.ts","../node_modules/@types/estree/index.d.ts","../node_modules/@types/node/compatibility/disposable.d.ts","../node_modules/@types/node/compatibility/indexable.d.ts","../node_modules/@types/node/compatibility/iterators.d.ts","../node_modules/@types/node/compatibility/index.d.ts","../node_modules/@types/node/globals.typedarray.d.ts","../node_modules/@types/node/buffer.buffer.d.ts","../node_modules/@types/node/globals.d.ts","../node_modules/@types/node/web-globals/abortcontroller.d.ts","../node_modules/@types/node/web-globals/domexception.d.ts","../node_modules/@types/node/web-globals/events.d.ts","../node_modules/undici-types/header.d.ts","../node_modules/undici-types/readable.d.ts","../node_modules/undici-types/file.d.ts","../node_modules/undici-types/fetch.d.ts","../node_modules/undici-types/formdata.d.ts","../node_modules/undici-types/connector.d.ts","../node_modules/undici-types/client.d.ts","../node_modules/undici-types/errors.d.ts","../node_modules/undici-types/dispatcher.d.ts","../node_modules/undici-types/global-dispatcher.d.ts","../node_modules/undici-types/global-origin.d.ts","../node_modules/undici-types/pool-stats.d.ts","../node_modules/undici-types/pool.d.ts","../node_modules/undici-types/handlers.d.ts","../node_modules/undici-types/balanced-pool.d.ts","../node_modules/undici-types/agent.d.ts","../node_modules/undici-types/mock-interceptor.d.ts","../node_modules/undici-types/mock-agent.d.ts","../node_modules/undici-types/mock-client.d.ts","../node_modules/undici-types/mock-pool.d.ts","../node_modules/undici-types/mock-errors.d.ts","../node_modules/undici-types/proxy-agent.d.ts","../node_modules/undici-types/env-http-proxy-agent.d.ts","../node_modules/undici-types/retry-handler.d.ts","../node_modules/undici-types/retry-agent.d.ts","../node_modules/undici-types/api.d.ts","../node_modules/undici-types/interceptors.d.ts","../node_modules/undici-types/util.d.ts","../node_modules/undici-types/cookies.d.ts","../node_modules/undici-types/patch.d.ts","../node_modules/undici-types/websocket.d.ts","../node_modules/undici-types/eventsource.d.ts","../node_modules/undici-types/filereader.d.ts","../node_modules/undici-types/diagnostics-channel.d.ts","../node_modules/undici-types/content-type.d.ts","../node_modules/undici-types/cache.d.ts","../node_modules/undici-types/index.d.ts","../node_modules/@types/node/web-globals/fetch.d.ts","../node_modules/@types/node/web-globals/navigator.d.ts","../node_modules/@types/node/web-globals/storage.d.ts","../node_modules/@types/node/assert.d.ts","../node_modules/@types/node/assert/strict.d.ts","../node_modules/@types/node/async_hooks.d.ts","../node_modules/@types/node/buffer.d.ts","../node_modules/@types/node/child_process.d.ts","../node_modules/@types/node/cluster.d.ts","../node_modules/@types/node/console.d.ts","../node_modules/@types/node/constants.d.ts","../node_modules/@types/node/crypto.d.ts","../node_modules/@types/node/dgram.d.ts","../node_modules/@types/node/diagnostics_channel.d.ts","../node_modules/@types/node/dns.d.ts","../node_modules/@types/node/dns/promises.d.ts","../node_modules/@types/node/domain.d.ts","../node_modules/@types/node/events.d.ts","../node_modules/@types/node/fs.d.ts","../node_modules/@types/node/fs/promises.d.ts","../node_modules/@types/node/http.d.ts","../node_modules/@types/node/http2.d.ts","../node_modules/@types/node/https.d.ts","../node_modules/@types/node/inspector.d.ts","../node_modules/@types/node/inspector.generated.d.ts","../node_modules/@types/node/module.d.ts","../node_modules/@types/node/net.d.ts","../node_modules/@types/node/os.d.ts","../node_modules/@types/node/path.d.ts","../node_modules/@types/node/perf_hooks.d.ts","../node_modules/@types/node/process.d.ts","../node_modules/@types/node/punycode.d.ts","../node_modules/@types/node/querystring.d.ts","../node_modules/@types/node/readline.d.ts","../node_modules/@types/node/readline/promises.d.ts","../node_modules/@types/node/repl.d.ts","../node_modules/@types/node/sea.d.ts","../node_modules/@types/node/sqlite.d.ts","../node_modules/@types/node/stream.d.ts","../node_modules/@types/node/stream/promises.d.ts","../node_modules/@types/node/stream/consumers.d.ts","../node_modules/@types/node/stream/web.d.ts","../node_modules/@types/node/string_decoder.d.ts","../node_modules/@types/node/test.d.ts","../node_modules/@types/node/timers.d.ts","../node_modules/@types/node/timers/promises.d.ts","../node_modules/@types/node/tls.d.ts","../node_modules/@types/node/trace_events.d.ts","../node_modules/@types/node/tty.d.ts","../node_modules/@types/node/url.d.ts","../node_modules/@types/node/util.d.ts","../node_modules/@types/node/v8.d.ts","../node_modules/@types/node/vm.d.ts","../node_modules/@types/node/wasi.d.ts","../node_modules/@types/node/worker_threads.d.ts","../node_modules/@types/node/zlib.d.ts","../node_modules/@types/node/index.d.ts","../node_modules/@types/resolve/index.d.ts"],"fileIdsList":[[48,49,57,105,122,123],[57,105,122,123],[57,102,103,105,122,123],[57,104,105,122,123],[105,122,123],[57,105,110,122,123,140],[57,105,106,111,116,122,123,125,137,148],[57,105,106,107,116,122,123,125],[52,53,54,57,105,122,123],[57,105,108,122,123,149],[57,105,109,110,117,122,123,126],[57,105,110,122,123,137,145],[57,105,111,113,116,122,123,125],[57,104,105,112,122,123],[57,105,113,114,122,123],[57,105,115,116,122,123],[57,104,105,116,122,123],[57,105,116,117,118,122,123,137,148],[57,105,116,117,118,122,123,132,137,140],[57,98,105,113,116,119,122,123,125,137,148],[57,105,116,117,119,120,122,123,125,137,145,148],[57,105,119,121,122,123,137,145,148],[55,56,57,58,59,60,61,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154],[57,105,116,122,123],[57,105,122,123,124,148],[57,105,113,116,122,123,125,137],[57,105,122,123,126],[57,105,122,123,127],[57,104,105,122,123,128],[57,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154],[57,105,122,123,130],[57,105,122,123,131],[57,105,116,122,123,132,133],[57,105,122,123,132,134,149,151],[57,105,117,122,123],[57,105,116,122,123,137,138,140],[57,105,122,123,139,140],[57,105,122,123,137,138],[57,105,122,123,140],[57,105,122,123,141],[57,102,105,122,123,137,142],[57,105,116,122,123,143,144],[57,105,122,123,143,144],[57,105,110,122,123,125,137,145],[57,105,122,123,146],[57,105,122,123,125,147],[57,105,119,122,123,131,148],[57,105,110,122,123,149],[57,105,122,123,137,150],[57,105,122,123,124,151],[57,105,122,123,152],[57,98,105,122,123],[57,98,105,116,118,122,123,128,137,140,148,150,151,153],[57,105,122,123,137,154],[57,70,74,105,122,123,148],[57,70,105,122,123,137,148],[57,65,105,122,123],[57,67,70,105,122,123,145,148],[57,105,122,123,125,145],[57,105,122,123,155],[57,65,105,122,123,155],[57,67,70,105,122,123,125,148],[57,62,63,66,69,105,116,122,123,137,148],[57,70,77,105,122,123],[57,62,68,105,122,123],[57,70,91,92,105,122,123],[57,66,70,105,122,123,140,148,155],[57,91,105,122,123,155],[57,64,65,105,122,123,155],[57,70,105,122,123],[57,64,65,66,67,68,69,70,71,72,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,92,93,94,95,96,97,105,122,123],[57,70,85,105,122,123],[57,70,77,78,105,122,123],[57,68,70,78,79,105,122,123],[57,69,105,122,123],[57,62,65,70,105,122,123],[57,70,74,78,79,105,122,123],[57,74,105,122,123],[57,68,70,73,105,122,123,148],[57,62,67,70,77,105,122,123],[57,105,122,123,137],[57,65,70,91,105,122,123,153,155],[46,57,105,122,123]],"fileInfos":[{"version":"c430d44666289dae81f30fa7b2edebf186ecc91a2d4c71266ea6ae76388792e1","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","impliedFormat":1},{"version":"e44bb8bbac7f10ecc786703fe0a6a4b952189f908707980ba8f3c8975a760962","impliedFormat":1},{"version":"5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","impliedFormat":1},{"version":"68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","impliedFormat":1},{"version":"5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"fb0f136d372979348d59b3f5020b4cdb81b5504192b1cacff5d1fbba29378aa1","affectsGlobalScope":true,"impliedFormat":1},{"version":"d15bea3d62cbbdb9797079416b8ac375ae99162a7fba5de2c6c505446486ac0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"68d18b664c9d32a7336a70235958b8997ebc1c3b8505f4f1ae2b7e7753b87618","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb3d66c8327153d8fa7dd03f9c58d351107fe824c79e9b56b462935176cdf12a","affectsGlobalScope":true,"impliedFormat":1},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true,"impliedFormat":1},{"version":"69ab18c3b76cd9b1be3d188eaf8bba06112ebbe2f47f6c322b5105a6fbc45a2e","affectsGlobalScope":true,"impliedFormat":1},{"version":"a680117f487a4d2f30ea46f1b4b7f58bef1480456e18ba53ee85c2746eeca012","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true,"impliedFormat":1},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true,"impliedFormat":1},{"version":"954296b30da6d508a104a3a0b5d96b76495c709785c1d11610908e63481ee667","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac9538681b19688c8eae65811b329d3744af679e0bdfa5d842d0e32524c73e1c","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a969edff4bd52585473d24995c5ef223f6652d6ef46193309b3921d65dd4376","affectsGlobalScope":true,"impliedFormat":1},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true,"impliedFormat":1},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true,"impliedFormat":1},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true,"impliedFormat":1},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true,"impliedFormat":1},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true,"impliedFormat":1},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true,"impliedFormat":1},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"d6d7ae4d1f1f3772e2a3cde568ed08991a8ae34a080ff1151af28b7f798e22ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true,"impliedFormat":1},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true,"impliedFormat":1},{"version":"52ada8e0b6e0482b728070b7639ee42e83a9b1c22d205992756fe020fd9f4a47","affectsGlobalScope":true,"impliedFormat":1},{"version":"3bdefe1bfd4d6dee0e26f928f93ccc128f1b64d5d501ff4a8cf3c6371200e5e6","affectsGlobalScope":true,"impliedFormat":1},{"version":"59fb2c069260b4ba00b5643b907ef5d5341b167e7d1dbf58dfd895658bda2867","affectsGlobalScope":true,"impliedFormat":1},{"version":"639e512c0dfc3fad96a84caad71b8834d66329a1f28dc95e3946c9b58176c73a","affectsGlobalScope":true,"impliedFormat":1},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"a6a5253138c5432c68a1510c70fe78a644fe2e632111ba778e1978010d6edfec","impliedFormat":1},"2eb36fddaa302034d69f077bb6419df5cdfb1d17faaab6782f135e248056f21a",{"version":"427fe2004642504828c1476d0af4270e6ad4db6de78c0b5da3e4c5ca95052a99","impliedFormat":1},{"version":"2eeffcee5c1661ddca53353929558037b8cf305ffb86a803512982f99bcab50d","impliedFormat":99},{"version":"9afb4cb864d297e4092a79ee2871b5d3143ea14153f62ef0bb04ede25f432030","affectsGlobalScope":true,"impliedFormat":99},{"version":"151ff381ef9ff8da2da9b9663ebf657eac35c4c9a19183420c05728f31a6761d","impliedFormat":1},{"version":"6c7176368037af28cb72f2392010fa1cef295d6d6744bca8cfb54985f3a18c3e","affectsGlobalScope":true,"impliedFormat":1},{"version":"ab41ef1f2cdafb8df48be20cd969d875602483859dc194e9c97c8a576892c052","affectsGlobalScope":true,"impliedFormat":1},{"version":"437e20f2ba32abaeb7985e0afe0002de1917bc74e949ba585e49feba65da6ca1","affectsGlobalScope":true,"impliedFormat":1},{"version":"21d819c173c0cf7cc3ce57c3276e77fd9a8a01d35a06ad87158781515c9a438a","impliedFormat":1},{"version":"98cffbf06d6bab333473c70a893770dbe990783904002c4f1a960447b4b53dca","affectsGlobalScope":true,"impliedFormat":1},{"version":"3af97acf03cc97de58a3a4bc91f8f616408099bc4233f6d0852e72a8ffb91ac9","affectsGlobalScope":true,"impliedFormat":1},{"version":"808069bba06b6768b62fd22429b53362e7af342da4a236ed2d2e1c89fcca3b4a","affectsGlobalScope":true,"impliedFormat":1},{"version":"1db0b7dca579049ca4193d034d835f6bfe73096c73663e5ef9a0b5779939f3d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"9798340ffb0d067d69b1ae5b32faa17ab31b82466a3fc00d8f2f2df0c8554aaa","affectsGlobalScope":true,"impliedFormat":1},{"version":"f26b11d8d8e4b8028f1c7d618b22274c892e4b0ef5b3678a8ccbad85419aef43","affectsGlobalScope":true,"impliedFormat":1},{"version":"5929864ce17fba74232584d90cb721a89b7ad277220627cc97054ba15a98ea8f","impliedFormat":1},{"version":"763fe0f42b3d79b440a9b6e51e9ba3f3f91352469c1e4b3b67bfa4ff6352f3f4","impliedFormat":1},{"version":"25c8056edf4314820382a5fdb4bb7816999acdcb929c8f75e3f39473b87e85bc","impliedFormat":1},{"version":"c464d66b20788266e5353b48dc4aa6bc0dc4a707276df1e7152ab0c9ae21fad8","impliedFormat":1},{"version":"78d0d27c130d35c60b5e5566c9f1e5be77caf39804636bc1a40133919a949f21","impliedFormat":1},{"version":"c6fd2c5a395f2432786c9cb8deb870b9b0e8ff7e22c029954fabdd692bff6195","impliedFormat":1},{"version":"1d6e127068ea8e104a912e42fc0a110e2aa5a66a356a917a163e8cf9a65e4a75","impliedFormat":1},{"version":"5ded6427296cdf3b9542de4471d2aa8d3983671d4cac0f4bf9c637208d1ced43","impliedFormat":1},{"version":"7f182617db458e98fc18dfb272d40aa2fff3a353c44a89b2c0ccb3937709bfb5","impliedFormat":1},{"version":"cadc8aced301244057c4e7e73fbcae534b0f5b12a37b150d80e5a45aa4bebcbd","impliedFormat":1},{"version":"385aab901643aa54e1c36f5ef3107913b10d1b5bb8cbcd933d4263b80a0d7f20","impliedFormat":1},{"version":"9670d44354bab9d9982eca21945686b5c24a3f893db73c0dae0fd74217a4c219","impliedFormat":1},{"version":"0b8a9268adaf4da35e7fa830c8981cfa22adbbe5b3f6f5ab91f6658899e657a7","impliedFormat":1},{"version":"11396ed8a44c02ab9798b7dca436009f866e8dae3c9c25e8c1fbc396880bf1bb","impliedFormat":1},{"version":"ba7bc87d01492633cb5a0e5da8a4a42a1c86270e7b3d2dea5d156828a84e4882","impliedFormat":1},{"version":"4893a895ea92c85345017a04ed427cbd6a1710453338df26881a6019432febdd","impliedFormat":1},{"version":"c21dc52e277bcfc75fac0436ccb75c204f9e1b3fa5e12729670910639f27343e","impliedFormat":1},{"version":"13f6f39e12b1518c6650bbb220c8985999020fe0f21d818e28f512b7771d00f9","impliedFormat":1},{"version":"9b5369969f6e7175740bf51223112ff209f94ba43ecd3bb09eefff9fd675624a","impliedFormat":1},{"version":"4fe9e626e7164748e8769bbf74b538e09607f07ed17c2f20af8d680ee49fc1da","impliedFormat":1},{"version":"24515859bc0b836719105bb6cc3d68255042a9f02a6022b3187948b204946bd2","impliedFormat":1},{"version":"ea0148f897b45a76544ae179784c95af1bd6721b8610af9ffa467a518a086a43","impliedFormat":1},{"version":"24c6a117721e606c9984335f71711877293a9651e44f59f3d21c1ea0856f9cc9","impliedFormat":1},{"version":"dd3273ead9fbde62a72949c97dbec2247ea08e0c6952e701a483d74ef92d6a17","impliedFormat":1},{"version":"405822be75ad3e4d162e07439bac80c6bcc6dbae1929e179cf467ec0b9ee4e2e","impliedFormat":1},{"version":"0db18c6e78ea846316c012478888f33c11ffadab9efd1cc8bcc12daded7a60b6","impliedFormat":1},{"version":"e61be3f894b41b7baa1fbd6a66893f2579bfad01d208b4ff61daef21493ef0a8","impliedFormat":1},{"version":"bd0532fd6556073727d28da0edfd1736417a3f9f394877b6d5ef6ad88fba1d1a","impliedFormat":1},{"version":"89167d696a849fce5ca508032aabfe901c0868f833a8625d5a9c6e861ef935d2","impliedFormat":1},{"version":"615ba88d0128ed16bf83ef8ccbb6aff05c3ee2db1cc0f89ab50a4939bfc1943f","impliedFormat":1},{"version":"a4d551dbf8746780194d550c88f26cf937caf8d56f102969a110cfaed4b06656","impliedFormat":1},{"version":"8bd86b8e8f6a6aa6c49b71e14c4ffe1211a0e97c80f08d2c8cc98838006e4b88","impliedFormat":1},{"version":"317e63deeb21ac07f3992f5b50cdca8338f10acd4fbb7257ebf56735bf52ab00","impliedFormat":1},{"version":"4732aec92b20fb28c5fe9ad99521fb59974289ed1e45aecb282616202184064f","impliedFormat":1},{"version":"2e85db9e6fd73cfa3d7f28e0ab6b55417ea18931423bd47b409a96e4a169e8e6","impliedFormat":1},{"version":"c46e079fe54c76f95c67fb89081b3e399da2c7d109e7dca8e4b58d83e332e605","impliedFormat":1},{"version":"bf67d53d168abc1298888693338cb82854bdb2e69ef83f8a0092093c2d562107","impliedFormat":1},{"version":"2cbe0621042e2a68c7cbce5dfed3906a1862a16a7d496010636cdbdb91341c0f","affectsGlobalScope":true,"impliedFormat":1},{"version":"f9501cc13ce624c72b61f12b3963e84fad210fbdf0ffbc4590e08460a3f04eba","affectsGlobalScope":true,"impliedFormat":1},{"version":"e7721c4f69f93c91360c26a0a84ee885997d748237ef78ef665b153e622b36c1","affectsGlobalScope":true,"impliedFormat":1},{"version":"0fa06ada475b910e2106c98c68b10483dc8811d0c14a8a8dd36efb2672485b29","impliedFormat":1},{"version":"33e5e9aba62c3193d10d1d33ae1fa75c46a1171cf76fef750777377d53b0303f","impliedFormat":1},{"version":"2b06b93fd01bcd49d1a6bd1f9b65ddcae6480b9a86e9061634d6f8e354c1468f","impliedFormat":1},{"version":"6a0cd27e5dc2cfbe039e731cf879d12b0e2dded06d1b1dedad07f7712de0d7f4","affectsGlobalScope":true,"impliedFormat":1},{"version":"13f5c844119c43e51ce777c509267f14d6aaf31eafb2c2b002ca35584cd13b29","impliedFormat":1},{"version":"e60477649d6ad21542bd2dc7e3d9ff6853d0797ba9f689ba2f6653818999c264","impliedFormat":1},{"version":"c2510f124c0293ab80b1777c44d80f812b75612f297b9857406468c0f4dafe29","affectsGlobalScope":true,"impliedFormat":1},{"version":"5524481e56c48ff486f42926778c0a3cce1cc85dc46683b92b1271865bcf015a","impliedFormat":1},{"version":"4c829ab315f57c5442c6667b53769975acbf92003a66aef19bce151987675bd1","affectsGlobalScope":true,"impliedFormat":1},{"version":"b2ade7657e2db96d18315694789eff2ddd3d8aea7215b181f8a0b303277cc579","impliedFormat":1},{"version":"9855e02d837744303391e5623a531734443a5f8e6e8755e018c41d63ad797db2","impliedFormat":1},{"version":"4d631b81fa2f07a0e63a9a143d6a82c25c5f051298651a9b69176ba28930756d","impliedFormat":1},{"version":"836a356aae992ff3c28a0212e3eabcb76dd4b0cc06bcb9607aeef560661b860d","impliedFormat":1},{"version":"1e0d1f8b0adfa0b0330e028c7941b5a98c08b600efe7f14d2d2a00854fb2f393","impliedFormat":1},{"version":"41670ee38943d9cbb4924e436f56fc19ee94232bc96108562de1a734af20dc2c","affectsGlobalScope":true,"impliedFormat":1},{"version":"c906fb15bd2aabc9ed1e3f44eb6a8661199d6c320b3aa196b826121552cb3695","impliedFormat":1},{"version":"22295e8103f1d6d8ea4b5d6211e43421fe4564e34d0dd8e09e520e452d89e659","impliedFormat":1},{"version":"bb45cd435da536500f1d9692a9b49d0c570b763ccbf00473248b777f5c1f353b","impliedFormat":1},{"version":"6b4e081d55ac24fc8a4631d5dd77fe249fa25900abd7d046abb87d90e3b45645","impliedFormat":1},{"version":"a10f0e1854f3316d7ee437b79649e5a6ae3ae14ffe6322b02d4987071a95362e","impliedFormat":1},{"version":"e208f73ef6a980104304b0d2ca5f6bf1b85de6009d2c7e404028b875020fa8f2","impliedFormat":1},{"version":"d163b6bc2372b4f07260747cbc6c0a6405ab3fbcea3852305e98ac43ca59f5bc","impliedFormat":1},{"version":"e6fa9ad47c5f71ff733744a029d1dc472c618de53804eae08ffc243b936f87ff","affectsGlobalScope":true,"impliedFormat":1},{"version":"83e63d6ccf8ec004a3bb6d58b9bb0104f60e002754b1e968024b320730cc5311","impliedFormat":1},{"version":"24826ed94a78d5c64bd857570fdbd96229ad41b5cb654c08d75a9845e3ab7dde","impliedFormat":1},{"version":"8b479a130ccb62e98f11f136d3ac80f2984fdc07616516d29881f3061f2dd472","impliedFormat":1},{"version":"928af3d90454bf656a52a48679f199f64c1435247d6189d1caf4c68f2eaf921f","affectsGlobalScope":true,"impliedFormat":1},{"version":"d2bc7425ef40526650d6db7e072c1ff4a51101c3ac2cc4b666623b19496a6e27","affectsGlobalScope":true,"impliedFormat":1},{"version":"3f16a7e4deafa527ed9995a772bb380eb7d3c2c0fd4ae178c5263ed18394db2c","impliedFormat":1},{"version":"933921f0bb0ec12ef45d1062a1fc0f27635318f4d294e4d99de9a5493e618ca2","impliedFormat":1},{"version":"71a0f3ad612c123b57239a7749770017ecfe6b66411488000aba83e4546fde25","impliedFormat":1},{"version":"77fbe5eecb6fac4b6242bbf6eebfc43e98ce5ccba8fa44e0ef6a95c945ff4d98","impliedFormat":1},{"version":"4f9d8ca0c417b67b69eeb54c7ca1bedd7b56034bb9bfd27c5d4f3bc4692daca7","impliedFormat":1},{"version":"814118df420c4e38fe5ae1b9a3bafb6e9c2aa40838e528cde908381867be6466","impliedFormat":1},{"version":"a3fc63c0d7b031693f665f5494412ba4b551fe644ededccc0ab5922401079c95","impliedFormat":1},{"version":"f27524f4bef4b6519c604bdb23bf4465bddcccbf3f003abb901acbd0d7404d99","impliedFormat":1},{"version":"37ba7b45141a45ce6e80e66f2a96c8a5ab1bcef0fc2d0f56bb58df96ec67e972","impliedFormat":1},{"version":"45650f47bfb376c8a8ed39d4bcda5902ab899a3150029684ee4c10676d9fbaee","impliedFormat":1},{"version":"dba28a419aec76ed864ef43e5f577a5c99a010c32e5949fe4e17a4d57c58dd11","affectsGlobalScope":true,"impliedFormat":1},{"version":"18fd40412d102c5564136f29735e5d1c3b455b8a37f920da79561f1fde068208","impliedFormat":1},{"version":"c959a391a75be9789b43c8468f71e3fa06488b4d691d5729dde1416dcd38225b","impliedFormat":1},{"version":"f0be1b8078cd549d91f37c30c222c2a187ac1cf981d994fb476a1adc61387b14","affectsGlobalScope":true,"impliedFormat":1},{"version":"0aaed1d72199b01234152f7a60046bc947f1f37d78d182e9ae09c4289e06a592","impliedFormat":1},{"version":"0dba70b3fb0dcd713fda33c2df64fa6751fff6460e536971cee917260fb17882","impliedFormat":1},{"version":"66ba1b2c3e3a3644a1011cd530fb444a96b1b2dfe2f5e837a002d41a1a799e60","impliedFormat":1},{"version":"7e514f5b852fdbc166b539fdd1f4e9114f29911592a5eb10a94bb3a13ccac3c4","impliedFormat":1},{"version":"5b7aa3c4c1a5d81b411e8cb302b45507fea9358d3569196b27eb1a27ae3a90ef","affectsGlobalScope":true,"impliedFormat":1},{"version":"5987a903da92c7462e0b35704ce7da94d7fdc4b89a984871c0e2b87a8aae9e69","affectsGlobalScope":true,"impliedFormat":1},{"version":"ea08a0345023ade2b47fbff5a76d0d0ed8bff10bc9d22b83f40858a8e941501c","impliedFormat":1},{"version":"47613031a5a31510831304405af561b0ffaedb734437c595256bb61a90f9311b","impliedFormat":1},{"version":"ae062ce7d9510060c5d7e7952ae379224fb3f8f2dd74e88959878af2057c143b","impliedFormat":1},{"version":"8a1a0d0a4a06a8d278947fcb66bf684f117bf147f89b06e50662d79a53be3e9f","affectsGlobalScope":true,"impliedFormat":1},{"version":"9f663c2f91127ef7024e8ca4b3b4383ff2770e5f826696005de382282794b127","impliedFormat":1},{"version":"9f55299850d4f0921e79b6bf344b47c420ce0f507b9dcf593e532b09ea7eeea1","impliedFormat":1},{"version":"8baa5d0febc68db886c40bf341e5c90dc215a90cd64552e47e8184be6b7e3358","impliedFormat":1}],"root":[47],"options":{"declaration":true,"declarationDir":"./","declarationMap":true,"emitDeclarationOnly":false,"esModuleInterop":true,"importHelpers":true,"inlineSources":true,"module":99,"noEmitHelpers":true,"outDir":"./","removeComments":true,"rootDir":"../src","skipLibCheck":true,"sourceMap":true,"strict":true,"target":7,"tsBuildInfoFile":"./.tsbuildinfo"},"referencedMap":[[50,1],[48,2],[51,2],[102,3],[103,3],[104,4],[57,5],[105,6],[106,7],[107,8],[52,2],[55,9],[53,2],[54,2],[108,10],[109,11],[110,12],[111,13],[112,14],[113,15],[114,15],[115,16],[116,17],[117,18],[118,19],[58,2],[56,2],[119,20],[120,21],[121,22],[155,23],[122,24],[123,2],[124,25],[125,26],[126,27],[127,28],[128,29],[129,30],[130,31],[131,32],[132,33],[133,33],[134,34],[135,2],[136,35],[137,36],[139,37],[138,38],[140,39],[141,40],[142,41],[143,42],[144,43],[145,44],[146,45],[147,46],[148,47],[149,48],[150,49],[151,50],[152,51],[59,2],[60,2],[61,2],[99,52],[100,2],[101,2],[153,53],[154,54],[156,2],[49,2],[46,2],[44,2],[45,2],[9,2],[8,2],[2,2],[10,2],[11,2],[12,2],[13,2],[14,2],[15,2],[16,2],[17,2],[3,2],[18,2],[19,2],[4,2],[20,2],[24,2],[21,2],[22,2],[23,2],[25,2],[26,2],[27,2],[5,2],[28,2],[29,2],[30,2],[31,2],[6,2],[35,2],[32,2],[33,2],[34,2],[36,2],[7,2],[37,2],[42,2],[43,2],[38,2],[39,2],[40,2],[41,2],[1,2],[77,55],[87,56],[76,55],[97,57],[68,58],[67,59],[96,60],[90,61],[95,62],[70,63],[84,64],[69,65],[93,66],[65,67],[64,60],[94,68],[66,69],[71,70],[72,2],[75,70],[62,2],[98,71],[88,72],[79,73],[80,74],[82,75],[78,76],[81,77],[91,60],[73,78],[74,79],[83,80],[63,81],[86,72],[85,70],[89,2],[92,82],[47,83]],"version":"5.9.3"}
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,15 @@ export declare function isTreeNodeWithCircularCheck(value: unknown, fieldNames?:
|
|
|
34
34
|
export declare function isSafeTreeDepth(tree: TreeData, maxDepth: number, fieldNames?: FieldNames): boolean;
|
|
35
35
|
export declare function isLeafNode(node: TreeNode, fieldNames?: FieldNames): boolean;
|
|
36
36
|
export declare function isRootNode(tree: TreeData, nodeId: any, fieldNames?: FieldNames): boolean;
|
|
37
|
+
export declare function convertToArrayTree(tree: TreeData, fieldNames?: FieldNames): TreeNode[];
|
|
38
|
+
export declare function convertBackTree(data: TreeNode[] | Map<any, TreeNode> | Record<string | number, TreeNode> | TreeNode, options?: {
|
|
39
|
+
rootParentId?: any;
|
|
40
|
+
parentIdField?: string;
|
|
41
|
+
fieldNames?: FieldNames;
|
|
42
|
+
}): TreeData;
|
|
43
|
+
export declare function convertToMapTree(tree: TreeData, fieldNames?: FieldNames): Map<any, TreeNode>;
|
|
44
|
+
export declare function convertToLevelArrayTree(tree: TreeData, fieldNames?: FieldNames): TreeNode[][];
|
|
45
|
+
export declare function convertToObjectTree(tree: TreeData, fieldNames?: FieldNames): TreeNode | null;
|
|
37
46
|
declare const treeProcessor: {
|
|
38
47
|
mapTree: typeof mapTree;
|
|
39
48
|
filterTree: typeof filterTree;
|
|
@@ -65,6 +74,11 @@ declare const treeProcessor: {
|
|
|
65
74
|
isSafeTreeDepth: typeof isSafeTreeDepth;
|
|
66
75
|
isLeafNode: typeof isLeafNode;
|
|
67
76
|
isRootNode: typeof isRootNode;
|
|
77
|
+
convertToArrayTree: typeof convertToArrayTree;
|
|
78
|
+
convertBackTree: typeof convertBackTree;
|
|
79
|
+
convertToMapTree: typeof convertToMapTree;
|
|
80
|
+
convertToLevelArrayTree: typeof convertToLevelArrayTree;
|
|
81
|
+
convertToObjectTree: typeof convertToObjectTree;
|
|
68
82
|
};
|
|
69
83
|
export default treeProcessor;
|
|
70
84
|
//# sourceMappingURL=index.d.ts.map
|