Skip to content

Commit

Permalink
docs: improve readme, update api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
chandq committed Dec 17, 2023
1 parent 1dd16d1 commit 069be6c
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@

- arrayLike 判断类数组
- arrayEachAsync 异步遍历数组,可中断,支持倒序
- forEachDeep 深度优先遍历函数, 支持continue、break,可定制id、children

- Tree

- forEachDeep 高性能的深度优先遍历函数, 支持continue、break,可定制id、children
- forEachMap 高性能的深度优先遍历的Map函数, 支持continue、break,可定制id、children
- searchTreeById 在树中找到 id 为某个值的节点,并返回上游的所有父级节点
- buildTree 根据 id 与 parentId 从对象数组中构建对应的树
- formatTree 高性能的数组转树函数

- Object

Expand Down
131 changes: 130 additions & 1 deletion docs/input/sculp-js.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@
{
"kind": "Function",
"canonicalReference": "sculp-js!forEachDeep:function(1)",
"docComment": "/**\n * 自定义深度优先遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item\n *\n * @param tree - 树形数据\n *\n * @param iterator - 迭代函数, 返回值为true时continue, 返回值为false时break\n *\n * @param children - 定制子元素的key\n *\n * @param isReverse - 是否反向遍历\n *\n * @returns {*}\n */\n",
"docComment": "/**\n * 深度优先遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item\n *\n * @param tree - 树形数据\n *\n * @param iterator - 迭代函数, 返回值为true时continue, 返回值为false时break\n *\n * @param children - 定制子元素的key\n *\n * @param isReverse - 是否反向遍历\n *\n * @returns {*}\n */\n",
"excerptTokens": [
{
"kind": "Content",
Expand Down Expand Up @@ -2392,6 +2392,135 @@
],
"name": "forEachDeep"
},
{
"kind": "Function",
"canonicalReference": "sculp-js!forEachMap:function(1)",
"docComment": "/**\n * 深度优先遍历的Map函数(支持continue和break操作), 可用于insert tree item 和 remove tree item\n *\n * @param tree - 树形数据\n *\n * @param iterator - 迭代函数, 返回值为true时continue, 返回值为false时break\n *\n * @param children - 定制子元素的key\n *\n * @param isReverse - 是否反向遍历\n *\n * @returns {any[]} 新的一棵树\n */\n",
"excerptTokens": [
{
"kind": "Content",
"text": "declare function forEachMap<V>(tree: "
},
{
"kind": "Reference",
"text": "ArrayLike",
"canonicalReference": "!ArrayLike:interface"
},
{
"kind": "Content",
"text": "<V>"
},
{
"kind": "Content",
"text": ", iterator: "
},
{
"kind": "Content",
"text": "(val: V, i: number, currentArr: "
},
{
"kind": "Reference",
"text": "ArrayLike",
"canonicalReference": "!ArrayLike:interface"
},
{
"kind": "Content",
"text": "<V>, tree: "
},
{
"kind": "Reference",
"text": "ArrayLike",
"canonicalReference": "!ArrayLike:interface"
},
{
"kind": "Content",
"text": "<V>, parent: V | null, level: number) => boolean | any"
},
{
"kind": "Content",
"text": ", children?: "
},
{
"kind": "Content",
"text": "string"
},
{
"kind": "Content",
"text": ", isReverse?: "
},
{
"kind": "Content",
"text": "boolean"
},
{
"kind": "Content",
"text": "): "
},
{
"kind": "Content",
"text": "any[]"
},
{
"kind": "Content",
"text": ";"
}
],
"fileUrlPath": "lib/index.d.ts",
"returnTypeTokenRange": {
"startIndex": 14,
"endIndex": 15
},
"releaseTag": "Public",
"overloadIndex": 1,
"parameters": [
{
"parameterName": "tree",
"parameterTypeTokenRange": {
"startIndex": 1,
"endIndex": 3
},
"isOptional": false
},
{
"parameterName": "iterator",
"parameterTypeTokenRange": {
"startIndex": 4,
"endIndex": 9
},
"isOptional": false
},
{
"parameterName": "children",
"parameterTypeTokenRange": {
"startIndex": 10,
"endIndex": 11
},
"isOptional": true
},
{
"parameterName": "isReverse",
"parameterTypeTokenRange": {
"startIndex": 12,
"endIndex": 13
},
"isOptional": true
}
],
"typeParameters": [
{
"typeParameterName": "V",
"constraintTokenRange": {
"startIndex": 0,
"endIndex": 0
},
"defaultTypeTokenRange": {
"startIndex": 0,
"endIndex": 0
}
}
],
"name": "forEachMap"
},
{
"kind": "Function",
"canonicalReference": "sculp-js!formatDate:function(1)",
Expand Down
2 changes: 1 addition & 1 deletion docs/markdown/sculp-js.foreachdeep.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## forEachDeep() function

自定义深度优先遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
深度优先遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item

**Signature:**

Expand Down
40 changes: 40 additions & 0 deletions docs/markdown/sculp-js.foreachmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [sculp-js](./sculp-js.md) &gt; [forEachMap](./sculp-js.foreachmap.md)

## forEachMap() function

深度优先遍历的Map函数(支持continue和break操作), 可用于insert tree item 和 remove tree item

**Signature:**

```typescript
declare function forEachMap<V>(
tree: ArrayLike<V>,
iterator: (
val: V,
i: number,
currentArr: ArrayLike<V>,
tree: ArrayLike<V>,
parent: V | null,
level: number
) => boolean | any,
children?: string,
isReverse?: boolean
): any[];
```

## Parameters

| Parameter | Type | Description |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------ |
| tree | ArrayLike&lt;V&gt; | 树形数据 |
| iterator | (val: V, i: number, currentArr: ArrayLike&lt;V&gt;, tree: ArrayLike&lt;V&gt;, parent: V \| null, level: number) =&gt; boolean \| any | 迭代函数, 返回值为true时continue, 返回值为false时break |
| children | string | _(Optional)_ 定制子元素的key |
| isReverse | boolean | _(Optional)_ 是否反向遍历 |

**Returns:**

any\[\]

{<!-- -->any\[\]<!-- -->} 新的一棵树
3 changes: 2 additions & 1 deletion docs/markdown/sculp-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
| [downloadData(data, fileType, filename, headers)](./sculp-js.downloaddata.md) | 将指定数据格式通过 A 链接的方式下载 |
| [downloadHref(href, filename)](./sculp-js.downloadhref.md) | 通过 A 链接的方式下载 |
| [downloadURL(url, params)](./sculp-js.downloadurl.md) | 通过打开新窗口的方式下载 |
| [forEachDeep(tree, iterator, children, isReverse)](./sculp-js.foreachdeep.md) | 自定义深度优先遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item |
| [forEachDeep(tree, iterator, children, isReverse)](./sculp-js.foreachdeep.md) | 深度优先遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item |
| [forEachMap(tree, iterator, children, isReverse)](./sculp-js.foreachmap.md) | 深度优先遍历的Map函数(支持continue和break操作), 可用于insert tree item 和 remove tree item |
| [formatDate(value, format)](./sculp-js.formatdate.md) | 格式化为日期对象(带自定义格式化模板) |
| [formatNumber(val, type)](./sculp-js.formatnumber.md) | 将数字格式化成千位分隔符显示的字符串 |
| [formatTree(list, options)](./sculp-js.formattree.md) | 扁平化数组转换成树(效率高于buildTree) |
Expand Down
15 changes: 15 additions & 0 deletions etc/sculp-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ export function forEachDeep<V>(
isReverse?: boolean
): void;

// @public
export function forEachMap<V>(
tree: ArrayLike<V>,
iterator: (
val: V,
i: number,
currentArr: ArrayLike<V>,
tree: ArrayLike<V>,
parent: V | null,
level: number
) => boolean | any,
children?: string,
isReverse?: boolean
): any[];

// @public
export function formatDate(value: DateValue, format?: string): string;

Expand Down

0 comments on commit 069be6c

Please sign in to comment.