Skip to content

Commit 7bed76f

Browse files
committed
docs: update api doc
1 parent 2e51e7b commit 7bed76f

File tree

6 files changed

+316
-58
lines changed

6 files changed

+316
-58
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[![Node.js CI](https://github.com/chandq/sculp-js/actions/workflows/node.js.yml/badge.svg)](https://github.com/chandq/sculp-js/actions/workflows/node.js.yml)
22
[![sculp-js](https://img.shields.io/github/package-json/v/chandq/sculp-js?style=flat-square)](https://github.com/chandq/sculp-js)
3-
[![node](https://img.shields.io/badge/node-v12.0.0-blue)](https://nodejs.org/download/release/v12.0.0/)
3+
[![node](https://img.shields.io/badge/node-v16.0.0-blue)](https://nodejs.org/download/release/v16.0.0/)
44
[![node](https://img.shields.io/badge/language-typescript-orange.svg)](https://nodejs.org/download/release/v12.0.0/)
55
[![license:MIT](https://img.shields.io/npm/l/vue.svg?sanitize=true)](https://github.com/chandq/sculp-js/blob/main/LICENSE.md)
66
[![Downloads:?](https://img.shields.io/npm/dm/sculp-js.svg?sanitize=true)](https://npmcharts.com/compare/sculp-js?minimal=true)
7+
[![codecov](https://codecov.io/gh/chandq/sculp-js/graph/badge.svg?token=VZ6TERPGI9)](https://codecov.io/gh/chandq/sculp-js)
78

89
# sculp-js
910

docs/input/sculp-js.api.json

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,147 @@
925925
],
926926
"name": "asyncMap"
927927
},
928+
{
929+
"kind": "Function",
930+
"canonicalReference": "sculp-js!buildTree:function(1)",
931+
"docComment": "/**\n * 根据 idProp 与 parentIdProp 从对象数组中构建对应的树 当 A[parentIdProp] === B[idProp] 时,对象A会被移动到对象B的children。 当一个对象的 parentIdProp 不与其他对象的 idProp 字段相等时,该对象被作为树的顶层节点\n *\n * @param idProp - 元素ID\n *\n * @param parentIdProp - 父元素ID\n *\n * @param items - 一维数组\n *\n * @returns {WithChildren<T>[]} 树\n *\n * @example\n *\n * const array = [ { id: 'node-1', parent: 'root' }, { id: 'node-2', parent: 'root' }, { id: 'node-3', parent: 'node-2' }, { id: 'node-4', parent: 'node-2' }, { id: 'node-5', parent: 'node-4' }, ] const tree = buildTree('id', 'parent', array) expect(tree).toEqual([ { id: 'node-1', parent: 'root' }, { id: 'node-2', parent: 'root', children: [ { id: 'node-3', parent: 'node-2' }, { id: 'node-4', parent: 'node-2', children: [{ id: 'node-5', parent: 'node-4' }], }, ], }, ])\n */\n",
932+
"excerptTokens": [
933+
{
934+
"kind": "Content",
935+
"text": "declare function buildTree<ID extends "
936+
},
937+
{
938+
"kind": "Content",
939+
"text": "string"
940+
},
941+
{
942+
"kind": "Content",
943+
"text": ", PID extends "
944+
},
945+
{
946+
"kind": "Content",
947+
"text": "string"
948+
},
949+
{
950+
"kind": "Content",
951+
"text": ", T extends "
952+
},
953+
{
954+
"kind": "Content",
955+
"text": "{\n [key in ID | PID]: string;\n}"
956+
},
957+
{
958+
"kind": "Content",
959+
"text": ">(idProp: "
960+
},
961+
{
962+
"kind": "Content",
963+
"text": "ID"
964+
},
965+
{
966+
"kind": "Content",
967+
"text": ", parentIdProp: "
968+
},
969+
{
970+
"kind": "Content",
971+
"text": "PID"
972+
},
973+
{
974+
"kind": "Content",
975+
"text": ", items: "
976+
},
977+
{
978+
"kind": "Content",
979+
"text": "T[]"
980+
},
981+
{
982+
"kind": "Content",
983+
"text": "): "
984+
},
985+
{
986+
"kind": "Reference",
987+
"text": "WithChildren",
988+
"canonicalReference": "sculp-js!WithChildren:type"
989+
},
990+
{
991+
"kind": "Content",
992+
"text": "<T>[]"
993+
},
994+
{
995+
"kind": "Content",
996+
"text": ";"
997+
}
998+
],
999+
"fileUrlPath": "lib/index.d.ts",
1000+
"returnTypeTokenRange": {
1001+
"startIndex": 13,
1002+
"endIndex": 15
1003+
},
1004+
"releaseTag": "Public",
1005+
"overloadIndex": 1,
1006+
"parameters": [
1007+
{
1008+
"parameterName": "idProp",
1009+
"parameterTypeTokenRange": {
1010+
"startIndex": 7,
1011+
"endIndex": 8
1012+
},
1013+
"isOptional": false
1014+
},
1015+
{
1016+
"parameterName": "parentIdProp",
1017+
"parameterTypeTokenRange": {
1018+
"startIndex": 9,
1019+
"endIndex": 10
1020+
},
1021+
"isOptional": false
1022+
},
1023+
{
1024+
"parameterName": "items",
1025+
"parameterTypeTokenRange": {
1026+
"startIndex": 11,
1027+
"endIndex": 12
1028+
},
1029+
"isOptional": false
1030+
}
1031+
],
1032+
"typeParameters": [
1033+
{
1034+
"typeParameterName": "ID",
1035+
"constraintTokenRange": {
1036+
"startIndex": 1,
1037+
"endIndex": 2
1038+
},
1039+
"defaultTypeTokenRange": {
1040+
"startIndex": 0,
1041+
"endIndex": 0
1042+
}
1043+
},
1044+
{
1045+
"typeParameterName": "PID",
1046+
"constraintTokenRange": {
1047+
"startIndex": 3,
1048+
"endIndex": 4
1049+
},
1050+
"defaultTypeTokenRange": {
1051+
"startIndex": 0,
1052+
"endIndex": 0
1053+
}
1054+
},
1055+
{
1056+
"typeParameterName": "T",
1057+
"constraintTokenRange": {
1058+
"startIndex": 5,
1059+
"endIndex": 6
1060+
},
1061+
"defaultTypeTokenRange": {
1062+
"startIndex": 0,
1063+
"endIndex": 0
1064+
}
1065+
}
1066+
],
1067+
"name": "buildTree"
1068+
},
9281069
{
9291070
"kind": "Function",
9301071
"canonicalReference": "sculp-js!calculateDate:function(1)",
@@ -7846,6 +7987,54 @@
78467987
}
78477988
],
78487989
"name": "wait"
7990+
},
7991+
{
7992+
"kind": "TypeAlias",
7993+
"canonicalReference": "sculp-js!WithChildren:type",
7994+
"docComment": "",
7995+
"excerptTokens": [
7996+
{
7997+
"kind": "Content",
7998+
"text": "type WithChildren<T> = "
7999+
},
8000+
{
8001+
"kind": "Content",
8002+
"text": "T & {\n children?: "
8003+
},
8004+
{
8005+
"kind": "Reference",
8006+
"text": "WithChildren",
8007+
"canonicalReference": "sculp-js!WithChildren:type"
8008+
},
8009+
{
8010+
"kind": "Content",
8011+
"text": "<T>[];\n}"
8012+
},
8013+
{
8014+
"kind": "Content",
8015+
"text": ";"
8016+
}
8017+
],
8018+
"fileUrlPath": "lib/index.d.ts",
8019+
"releaseTag": "Public",
8020+
"name": "WithChildren",
8021+
"typeParameters": [
8022+
{
8023+
"typeParameterName": "T",
8024+
"constraintTokenRange": {
8025+
"startIndex": 0,
8026+
"endIndex": 0
8027+
},
8028+
"defaultTypeTokenRange": {
8029+
"startIndex": 0,
8030+
"endIndex": 0
8031+
}
8032+
}
8033+
],
8034+
"typeTokenRange": {
8035+
"startIndex": 1,
8036+
"endIndex": 4
8037+
}
78498038
}
78508039
]
78518040
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [sculp-js](./sculp-js.md) &gt; [buildTree](./sculp-js.buildtree.md)
4+
5+
## buildTree() function
6+
7+
根据 idProp 与 parentIdProp 从对象数组中构建对应的树 当 A\[parentIdProp\] === B\[idProp\] 时,对象A会被移动到对象B的children。 当一个对象的 parentIdProp 不与其他对象的 idProp 字段相等时,该对象被作为树的顶层节点
8+
9+
**Signature:**
10+
11+
```typescript
12+
declare function buildTree<
13+
ID extends string,
14+
PID extends string,
15+
T extends {
16+
[key in ID | PID]: string;
17+
}
18+
>(idProp: ID, parentIdProp: PID, items: T[]): WithChildren<T>[];
19+
```
20+
21+
## Parameters
22+
23+
| Parameter | Type | Description |
24+
| ------------ | ----- | ----------- |
25+
| idProp | ID | 元素ID |
26+
| parentIdProp | PID | 父元素ID |
27+
| items | T\[\] | 一维数组 |
28+
29+
**Returns:**
30+
31+
[WithChildren](./sculp-js.withchildren.md)<!-- -->&lt;T&gt;\[\]
32+
33+
{<!-- -->WithChildren<T>\[\]<!-- -->} 树
34+
35+
## Example
36+
37+
const array = \[ { id: 'node-1', parent: 'root' }<!-- -->, { id: 'node-2', parent: 'root' }<!-- -->, { id: 'node-3', parent: 'node-2' }<!-- -->, { id: 'node-4', parent: 'node-2' }<!-- -->, { id: 'node-5', parent: 'node-4' }<!-- -->, \] const tree = buildTree('id', 'parent', array) expect(tree).toEqual(\[ { id: 'node-1', parent: 'root' }<!-- -->, { id: 'node-2', parent: 'root', children: \[ { id: 'node-3', parent: 'node-2' }<!-- -->, { id: 'node-4', parent: 'node-2', children: \[{ id: 'node-5', parent: 'node-4' }<!-- -->\], }<!-- -->, \], }<!-- -->, \])

0 commit comments

Comments
 (0)