From 633491cf1572aeaba99d46c974537724990300dd Mon Sep 17 00:00:00 2001 From: Victor Bo <10667379@qq.com> Date: Thu, 30 Nov 2023 16:34:04 +0800 Subject: [PATCH] feat: added utils arr package fns docs --- docs/.vitepress/guides.ts | 23 +++++++++++------- docs/examples/arr/groupBy/basic.ts | 18 ++++++++++++++ docs/functions/arr/groupBy.md | 38 ++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 docs/examples/arr/groupBy/basic.ts create mode 100644 docs/functions/arr/groupBy.md diff --git a/docs/.vitepress/guides.ts b/docs/.vitepress/guides.ts index ad9a497..b246314 100644 --- a/docs/.vitepress/guides.ts +++ b/docs/.vitepress/guides.ts @@ -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: [ @@ -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'] = [ diff --git a/docs/examples/arr/groupBy/basic.ts b/docs/examples/arr/groupBy/basic.ts new file mode 100644 index 0000000..8d89fa9 --- /dev/null +++ b/docs/examples/arr/groupBy/basic.ts @@ -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)) diff --git a/docs/functions/arr/groupBy.md b/docs/functions/arr/groupBy.md new file mode 100644 index 0000000..c0e627b --- /dev/null +++ b/docs/functions/arr/groupBy.md @@ -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 +``` + +::: + +## 使用 + + + +## 参数 + +| 名称 | 描述 | 类型 | 必填 | 默认值 | +|------|--------|----------------------|-----|-----| +| list | 欲分组的数据 | `T[]` | `是` | - | +| fn | 分组条件 | `(single: T) => any` | `是` | - | +