Skip to content

Commit

Permalink
docs: Update docs for isFunction, negate, isArrayLike
Browse files Browse the repository at this point in the history
  • Loading branch information
raon0211 committed Jul 21, 2024
1 parent bd7cb34 commit d4081c0
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/.vitepress/zh_hans.mts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ function sidebar(): DefaultTheme.Sidebar {
text: '谓词',
items: [
{ text: 'isArray (兼容性)', link: '/zh_hans/reference/compat/predicate/isArray' },
{ text: 'isArrayLike', link: '/zh_hans/reference/predicate/isArrayLike' },
{ text: 'isEqual', link: '/zh_hans/reference/predicate/isEqual' },
{ text: 'isLength', link: '/zh_hans/reference/predicate/isLength' },
{ text: 'isFunction', link: '/zh_hans/reference/predicate/isFunction' },
{ text: 'isPlainObject', link: '/zh_hans/reference/predicate/isPlainObject' },
{ text: 'isNil', link: '/zh_hans/reference/predicate/isNil' },
{ text: 'isNotNil', link: '/zh_hans/reference/predicate/isNotNil' },
Expand Down
2 changes: 1 addition & 1 deletion docs/ko/reference/function/negate.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## 인터페이스

```typescript
function negate<F extends (...args: unknown[]) => boolean>(func: F): F;
function negate<F extends (...args: never[]) => boolean>(func: F): F;
```

### 파라미터
Expand Down
4 changes: 2 additions & 2 deletions docs/ko/reference/predicate/isFunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

`value`가 함수이면 `true`, 아니면 `false`를 반환해요.

TypeScript의 타입 가드로 사용할 수 있어요. 파라미터로 주어진 값의 타입을 `(...args: unknown[]) => unknown`로 좁혀요.
TypeScript의 타입 가드로 사용할 수 있어요. 파라미터로 주어진 값의 타입을 `(...args: never[]) => unknown`로 좁혀요.

## 인터페이스

```typescript
function isFunction(value: unknown): value is (...args: unknown[]) => unknown;
function isFunction(value: unknown): value is (...args: never[]) => unknown;
```

### 파라미터
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/function/negate.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Creates a function that negates the result of the predicate function.
## Signature

```typescript
function negate<F extends (...args: unknown[]) => boolean>(func: F): F;
function negate<F extends (...args: never[]) => boolean>(func: F): F;
```

### Parameters
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/predicate/isFunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This function can also serve as a type predicate in TypeScript, narrowing the ty
## Signature

```typescript
function isFunction(value: unknown): value is (...args: unknown[]) => unknown;
function isFunction(value: unknown): value is (...args: never[]) => unknown;
```

### Parameters
Expand All @@ -18,7 +18,7 @@ function isFunction(value: unknown): value is (...args: unknown[]) => unknown;

### Returns

(`value is (...args: unknown[]) => unknown`): Returns `true` if the value is a function, otherwise `false`.
(`value is (...args: never[]) => unknown`): Returns `true` if the value is a function, otherwise `false`.

## Examples

Expand Down
2 changes: 1 addition & 1 deletion docs/zh_hans/reference/function/negate.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## 签名

```typescript
function negate<F extends (...args: unknown[]) => boolean>(func: F): F;
function negate<F extends (...args: never[]) => boolean>(func: F): F;
```

### 参数
Expand Down
34 changes: 34 additions & 0 deletions docs/zh_hans/reference/predicate/isArrayLike.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# isArrayLike

检查一个值是否是类似数组的对象。

类似数组的对象是一个既不是 `null``undefined` 也不是函数,并且具有有效 `length` 属性的对象。

这个函数也可以作为 TypeScript 中的类型断言,将参数的类型缩小到类似数组的对象。

## 签名

```typescript
function isArrayLike(value: unknown): value is ArrayLike<unknown>;
```

### 参数

- `value` (`unknown`): 要检查是否为类似数组的对象的值。

### 返回值

(`value is ArrayLike<unknown>`): 如果值是类似数组的对象则返回 `true`,否则返回 `false`

## 示例

```typescript
import { isArrayLike } from 'es-toolkit/predicate';

console.log(isArrayLike([1, 2, 3])); // true
console.log(isArrayLike('abc')); // true
console.log(isArrayLike({ 0: 'a', length: 1 })); // true
console.log(isArrayLike({})); // false
console.log(isArrayLike(null)); // false
console.log(isArrayLike(undefined)); // false
```
33 changes: 33 additions & 0 deletions docs/zh_hans/reference/predicate/isFunction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# isFunction

检查 `value` 是否是一个函数。

如果 `value` 是一个函数,则返回 `true`,否则返回 `false`

这个函数也可以作为 TypeScript 中的类型断言,将参数的类型缩小到函数类型。

## 签名

```typescript
function isFunction(value: unknown): value is (...args: never[]) => unknown;
```

### 参数

- `value` (`unknown`): 要检查是否为函数的值。

### 返回值

(`value is (...args: never[]) => unknown`): 如果值是一个函数则返回 `true`,否则返回 `false`

## 示例

```typescript
import { isFunction } from 'es-toolkit/predicate';

console.log(isFunction(Array.prototype.slice)); // true
console.log(isFunction(async function () {})); // true
console.log(isFunction(function* () {})); // true
console.log(isFunction(Proxy)); // true
console.log(isFunction(Int8Array)); // true
```

0 comments on commit d4081c0

Please sign in to comment.