Skip to content

Commit

Permalink
docs: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Nov 4, 2024
1 parent b2699ff commit 6b71b92
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/.vitepress/items/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const generalItems = [
{ text: 'isArray', link: '/general/is-array' },
{ text: 'isNullish', link: '/general/is-nullish' },
{ text: 'isPromise', link: '/general/is-promise' },
{ text: 'isRegExp', link: '/general/is-reg-exp' },
{ text: 'isFunction', link: '/general/is-function' },
{ text: 'isDate', link: '/general/is-date' },
{ text: 'isSet', link: '/general/is-set' },
Expand All @@ -19,9 +20,12 @@ export const generalItems = [
{ text: 'isArrayBuffer', link: '/general/is-array-buffer' },
{ text: 'isTypedArray', link: '/general/is-typed-array' },
{ text: 'isDataView', link: '/general/is-data-view' },
{ text: 'isError', link: '/general/is-error' },
{ text: 'isDOMException', link: '/general/is-dom-exception' },
{ text: 'isWindow', link: '/general/is-window' },
{ text: 'isRegExp', link: '/general/is-reg-exp' },
{ text: 'isEmpty', link: '/general/is-empty' },
{ text: 'isEqual', link: '/general/is-equal' },
{ text: 'isEqualWith', link: '/general/is-equal-with' },
{ text: 'isNonEmptyArray', link: '/general/is-non-empty-array' },
{ text: 'inBrowser', link: '/general/in-browser' },
{ text: 'inMobile', link: '/general/in-mobile' },
Expand Down
24 changes: 24 additions & 0 deletions docs/general/is-dom-exception.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# isDOMException

Determine whether the input value is a `DOMException` object.

### Usage

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

isDOMException(new DOMException('An error occurred')) // return true
isDOMException(new Error('An error occurred')) // return false
```

### Arguments

| Arg | Type | Defaults |
| ----- | :---: | -------: |
| `val` | `any` | |

### Return

| Type |
| :-------: |
| `boolean` |
30 changes: 30 additions & 0 deletions docs/general/is-equal-with.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# isEqualWith

Deeply compare two values. Supports passing a comparison method, and returns `true` if the two values ​​are equal.

### Usage

```ts
import { isEqualWith, isObject } from 'rattail'

isEqualWith([1, 2], ['1', '2'], (v1, v2) => {
if (!isObject(v1) && !isObject(v2)) {
return String(v1) === String(v2)
}
})
// return true
```

### Arguments

| Arg | Type | Defaults |
| ------- | :---------------------: | -------: |
| `value` | `any` | |
| `other` | `any` | |
| `fn` | `(value, other) => any` | |

### Return

| Type |
| :-------: |
| `boolean` |
27 changes: 27 additions & 0 deletions docs/general/is-equal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# isEqual

Deeply compare two values.

### Usage

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

isEqual({ n: 1 }, { n: 1 })
// return true
isEqual([1, 2, 3], [1, 2, 3])
// return true
```

### Arguments

| Arg | Type | Defaults |
| ------- | :---: | -------: |
| `value` | `any` | |
| `other` | `any` | |

### Return

| Type |
| :-------: |
| `boolean` |
23 changes: 23 additions & 0 deletions docs/general/is-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# isError

Determine whether the input value is an `Error` object.

### Usage

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

isError(new Error('message')) // return true
```

### Arguments

| Arg | Type | Defaults |
| ----- | :---: | -------: |
| `val` | `any` | |

### Return

| Type |
| :-------: |
| `boolean` |
24 changes: 24 additions & 0 deletions docs/zh/general/is-dom-exception.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# isDOMException

判断输入值是否为 `DOMException` 对象。

### 使用

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

isDOMException(new DOMException('An error occurred')) // return true
isDOMException(new Error('An error occurred')) // return false
```

### 参数列表

| 参数 | 类型 | 默认值 |
| ----- | :---: | -----: |
| `val` | `any` | |

### 返回值

| 类型 |
| :-------: |
| `boolean` |
30 changes: 30 additions & 0 deletions docs/zh/general/is-equal-with.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# isEqualWith

深度比较两个值。支持传入一个比较方法,返回 `true` 时表示两个值相等。

### 使用

```ts
import { isEqualWith, isObject } from 'rattail'

isEqualWith([1, 2], ['1', '2'], (v1, v2) => {
if (!isObject(v1) && !isObject(v2)) {
return String(v1) === String(v2)
}
})
// return true
```

### 参数列表

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

### 返回值

| 类型 |
| :-------: |
| `boolean` |
27 changes: 27 additions & 0 deletions docs/zh/general/is-equal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# isEqual

深度比较两个值。

### 使用

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

isEqual({ n: 1 }, { n: 1 })
// return true
isEqual([1, 2, 3], [1, 2, 3])
// return true
```

### 参数列表

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
| `value` | `any` | |
| `other` | `any` | |

### 返回值

| 类型 |
| :-------: |
| `boolean` |
23 changes: 23 additions & 0 deletions docs/zh/general/is-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# isError

判断输入值是否为 `Error` 对象。

### 使用

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

isError(new Error('message')) // return true
```

### 参数列表

| 参数 | 类型 | 默认值 |
| ----- | :---: | -----: |
| `val` | `any` | |

### 返回值

| 类型 |
| :-------: |
| `boolean` |
16 changes: 16 additions & 0 deletions tests/general.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ it('isEqual', () => {
expect(isEqual(new TextEncoder().encode('123').buffer, new TextEncoder().encode('1234').buffer)).toBe(false)

expect(isEqual({ n: 1 }, { n: 1 })).toBe(true)
expect(isEqual([1, 2, 3], [1, 2, 3])).toBe(true)
expect(isEqual([1, 2, 3], { 0: 1, 1: 2, 2: 3 })).toBe(false)
expect(isEqual({ a: 1, b: 2 }, { b: 2, a: 1 })).toBe(true)
expect(isEqual({ n: 1 }, { n: 2 })).toBe(false)
expect(isEqual({ n: 1, x: [1] }, { n: 1, x: [1] })).toBe(true)
Expand All @@ -379,8 +381,14 @@ it('isEqual', () => {
const c = [a, b]
const d = [b, a]

const x: Record<string, any> = { n: 1 }
const y: Record<string, any> = { n: 1 }
x.self = x
y.self = y

expect(isEqual(a, b)).toBe(true)
expect(isEqual(c, d)).toBe(true)
expect(isEqual(x, y)).toBe(true)
})

it('isEqualWith', () => {
Expand All @@ -393,4 +401,12 @@ it('isEqualWith', () => {
(a, b) => isFunction(a) === isFunction(b),
),
).toBe(true)

expect(
isEqualWith([1, 2], ['1', '2'], (v1, v2) => {
if (!isObject(v1) && !isObject(v2)) {
return String(v1) === String(v2)
}
}),
).toBe(true)
})

0 comments on commit 6b71b92

Please sign in to comment.