Skip to content

Commit

Permalink
refactor: cleanup pick pickBy omit omitBy and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Nov 7, 2024
1 parent ee83029 commit b12097a
Show file tree
Hide file tree
Showing 30 changed files with 260 additions and 278 deletions.
9 changes: 9 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
numberItems,
stringItems,
arrayItems,
objectItems,
functionItems,
collectionItems,
mathItems,
Expand Down Expand Up @@ -57,6 +58,10 @@ export default defineConfig({
text: '数学',
items: withI18n(mathItems, 'zh'),
},
{
text: '对象',
items: withI18n(objectItems, 'zh'),
},
{
text: '数组',
items: withI18n(arrayItems, 'zh'),
Expand Down Expand Up @@ -119,6 +124,10 @@ export default defineConfig({
text: 'Math',
items: mathItems,
},
{
text: 'Object',
items: objectItems,
},
{
text: 'Array',
items: arrayItems,
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/items/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './general'
export * from './string'
export * from './number'
export * from './object'
export * from './array'
export * from './collection'
export * from './function'
Expand Down
6 changes: 6 additions & 0 deletions docs/.vitepress/items/object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const objectItems = [
{ text: 'pick', link: '/object/pick' },
{ text: 'pickBy', link: '/object/pick-by' },
{ text: 'omit', link: '/object/omit' },
{ text: 'omitBy', link: '/object/omit-by' },
]
8 changes: 4 additions & 4 deletions docs/array/uniq-by.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ uniqBy([{ id: 1 }, { id: 2 }, { id: 1 }], (a, b) => a.id === b.id)

### Arguments

| Arg | Type | Defaults |
| ----- | ----------------------------- | -------- |
| `arr` | `Array` | |
| `fn` | `(a: any, b: any) => boolean` | |
| Arg | Type | Defaults |
| ----- | ------------------------- | -------- |
| `arr` | `Array` | |
| `fn` | `(a: any, b: any) => any` | |

### Return

Expand Down
25 changes: 0 additions & 25 deletions docs/collection/omit-by.md

This file was deleted.

25 changes: 0 additions & 25 deletions docs/collection/pick-by.md

This file was deleted.

27 changes: 27 additions & 0 deletions docs/object/omit-by.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# omitBy

Excludes an object property by providing a function that constructs a new object. Returns a `truthy` value to indicate that the property should be excluded.

### Usage

```ts
import { omitBy } from 'rattail'

omitBy({ a: 1, b: 2, c: 3 }, (value) => value > 1)
// return { a: 1 }
omitBy({ a: 1, b: 2, c: 3 }, (value, key) => key !== 'a')
// return { a: 1 }
```

### Arguments

| Arg | Type | Defaults |
| -------- | ---------------------------------- | -------- |
| `object` | `object` | |
| `fn` | `(value: any, key: string) => any` | |

### Return

| Type |
| -------- |
| `object` |
2 changes: 1 addition & 1 deletion docs/collection/omit.md → docs/object/omit.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# omit

Creates a new object by omitting specified keys from an existing object.
Excludes object properties and constructs a new object.

### Usage

Expand Down
27 changes: 27 additions & 0 deletions docs/object/pick-by.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# pickBy

By providing a function to extract object properties and construct a new object, returning a `truthy` value indicates that the property needs to be extracted.

### Usage

```ts
import { pickBy } from 'rattail'

pickBy({ a: 1, b: 2, c: 3 }, (value) => value > 1)
// return { b: 2, c: 3 }
pickBy({ a: 1, b: 2, c: 3 }, (value, key) => key !== 'a')
// return { b: 2, c: 3 }
```

### Arguments

| Arg | Type | Defaults |
| -------- | ---------------------------------- | -------- |
| `object` | `object` | |
| `fn` | `(value: any, key: string) => any` | |

### Return

| Type |
| -------- |
| `object` |
2 changes: 1 addition & 1 deletion docs/collection/pick.md → docs/object/pick.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pick

Creates a new object by selecting specified keys from an existing object.
Pick object properties and construct a new object.

### Usage

Expand Down
8 changes: 4 additions & 4 deletions docs/zh/array/uniq-by.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ uniqBy([{ id: 1 }, { id: 2 }, { id: 1 }], (a, b) => a.id === b.id)

### 参数

| 参数 | 类型 | 默认值 |
| ----- | ----------------------------- | ------ |
| `arr` | `Array` | |
| `fn` | `(a: any, b: any) => boolean` | |
| 参数 | 类型 | 默认值 |
| ----- | ------------------------- | ------ |
| `arr` | `Array` | |
| `fn` | `(a: any, b: any) => any` | |

### 返回值

Expand Down
25 changes: 0 additions & 25 deletions docs/zh/collection/omit-by.md

This file was deleted.

25 changes: 0 additions & 25 deletions docs/zh/collection/pick-by.md

This file was deleted.

6 changes: 3 additions & 3 deletions docs/zh/math/max-by.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ maxBy([{ n: 5 }, { n: 10 }, { n: 8 }], ({ n }) => n)

### 返回值

| 类型 |
| :--: | ---------- |
| `T | undefined` |
| 类型 |
| :---------------: |
| `T \| undefined` |
27 changes: 27 additions & 0 deletions docs/zh/object/omit-by.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# omitBy

通过提供一个函数来排除对象属性并构造成一个新的对象, 返回 `真值` 表示需要排除该属性。

### 使用

```ts
import { omitBy } from 'rattail'

omitBy({ a: 1, b: 2, c: 3 }, (value) => value > 1)
// return { a: 1 }
omitBy({ a: 1, b: 2, c: 3 }, (value, key) => key !== 'a')
// return { a: 1 }
```

### 参数

| 参数 | 类型 | 默认值 |
| -------- | ---------------------------------- | ------ |
| `object` | `object` | |
| `fn` | `(value: any, key: string) => any` | |

### 返回值

| 类型 |
| -------- |
| `object` |
2 changes: 1 addition & 1 deletion docs/zh/collection/omit.md → docs/zh/object/omit.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# omit

通过从现有对象中排除指定键来创建新对象
排除对象属性并构造成一个新的对象

### 使用

Expand Down
27 changes: 27 additions & 0 deletions docs/zh/object/pick-by.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# pickBy

通过提供一个函数来提取对象属性并构造成一个新的对象, 返回 `真值` 表示需要提取该属性。

### 使用

```ts
import { pickBy } from 'rattail'

pickBy({ a: 1, b: 2, c: 3 }, (value) => value > 1)
// return { b: 2, c: 3 }
pickBy({ a: 1, b: 2, c: 3 }, (value, key) => key !== 'a')
// return { b: 2, c: 3 }
```

### 参数

| 参数 | 类型 | 默认值 |
| -------- | ---------------------------------- | ------ |
| `object` | `object` | |
| `fn` | `(value: any, key: string) => any` | |

### 返回值

| 类型 |
| -------- |
| `object` |
2 changes: 1 addition & 1 deletion docs/zh/collection/pick.md → docs/zh/object/pick.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pick

通过从现有对象中选择指定键来创建新对象
提取对象属性并构造成一个新的对象

### 使用

Expand Down
2 changes: 1 addition & 1 deletion src/array/uniqBy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function uniqBy<T>(arr: T[], fn: (a: T, b: T) => boolean): T[] {
export function uniqBy<T>(arr: T[], fn: (a: T, b: T) => any): T[] {
return arr.reduce((ret: T[], i: T) => {
const index = ret.findIndex((j: T) => fn(i, j))

Expand Down
19 changes: 0 additions & 19 deletions src/collection/omit-by.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/collection/omit.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/collection/pick-by.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './array'
export * from './object'
export * from './util'
export * from './function'
export * from './general'
Expand Down
4 changes: 4 additions & 0 deletions src/object/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './pick'
export * from './pickBy'
export * from './omit'
export * from './omitBy'
Loading

0 comments on commit b12097a

Please sign in to comment.