Skip to content

Commit

Permalink
feat: added utils arr package fns docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vtrbo committed Nov 30, 2023
1 parent f7a250a commit 633491c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 9 deletions.
23 changes: 14 additions & 9 deletions docs/.vitepress/guides.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import type { DefaultTheme } from 'vitepress'

export const functions: DefaultTheme.NavItemChildren[] = [
{
text: 'utils-arr',
items: [
{
text: 'toArray',
link: '/functions/arr/toArray',
},
{
text: 'groupBy',
link: '/functions/arr/groupBy',
},
],
},
{
text: 'utils-is',
items: [
Expand All @@ -22,15 +35,7 @@ export const functions: DefaultTheme.NavItemChildren[] = [
},
],
},
{
text: 'utils-arr',
items: [
{
text: 'toArray',
link: '/functions/arr/toArray',
},
],
},

]

export const nav: DefaultTheme.Config['nav'] = [
Expand Down
18 changes: 18 additions & 0 deletions docs/examples/arr/groupBy/basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { groupBy } from '@vtrbo/utils-arr'

interface ListItem {
name: string
sex: string
age: number
}

const list: ListItem[] = [
{ name: '小赵', sex: '男', age: 15 },
{ name: '小钱', sex: '女', age: 14 },
{ name: '小孙', sex: '女', age: 16 },
{ name: '小李', sex: '男', age: 15 },
]

const fn = (single: ListItem) => single.name

console.log(groupBy(list, fn))
38 changes: 38 additions & 0 deletions docs/functions/arr/groupBy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: groupBy
lang: zh-CN
---

# groupBy

将数组根据条件函数分组

## 安装

::: code-group

```bash [pnpm]
pnpm add @vtrbo/utils-arr
```

```bash [yarn]
yarn add @vtrbo/utils-arr
```

```bash [npm]
npm install @vtrbo/utils-arr
```

:::

## 使用

<demo example="arr/groupBy/basic.ts"></demo>

## 参数

| 名称 | 描述 | 类型 | 必填 | 默认值 |
|------|--------|----------------------|-----|-----|
| list | 欲分组的数据 | `T[]` | `` | - |
| fn | 分组条件 | `(single: T) => any` | `` | - |

0 comments on commit 633491c

Please sign in to comment.