docs: Update docs for isFunction, negate, isArrayLike

This commit is contained in:
Sojin Park 2024-07-21 10:55:36 +09:00
parent bd7cb34cb7
commit d4081c0674
8 changed files with 76 additions and 7 deletions

View File

@ -147,8 +147,10 @@ function sidebar(): DefaultTheme.Sidebar {
text: '谓词', text: '谓词',
items: [ items: [
{ text: 'isArray (兼容性)', link: '/zh_hans/reference/compat/predicate/isArray' }, { 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: 'isEqual', link: '/zh_hans/reference/predicate/isEqual' },
{ text: 'isLength', link: '/zh_hans/reference/predicate/isLength' }, { 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: 'isPlainObject', link: '/zh_hans/reference/predicate/isPlainObject' },
{ text: 'isNil', link: '/zh_hans/reference/predicate/isNil' }, { text: 'isNil', link: '/zh_hans/reference/predicate/isNil' },
{ text: 'isNotNil', link: '/zh_hans/reference/predicate/isNotNil' }, { text: 'isNotNil', link: '/zh_hans/reference/predicate/isNotNil' },

View File

@ -5,7 +5,7 @@
## 인터페이스 ## 인터페이스
```typescript ```typescript
function negate<F extends (...args: unknown[]) => boolean>(func: F): F; function negate<F extends (...args: never[]) => boolean>(func: F): F;
``` ```
### 파라미터 ### 파라미터

View File

@ -4,12 +4,12 @@
`value`가 함수이면 `true`, 아니면 `false`를 반환해요. `value`가 함수이면 `true`, 아니면 `false`를 반환해요.
TypeScript의 타입 가드로 사용할 수 있어요. 파라미터로 주어진 값의 타입을 `(...args: unknown[]) => unknown`로 좁혀요. TypeScript의 타입 가드로 사용할 수 있어요. 파라미터로 주어진 값의 타입을 `(...args: never[]) => unknown`로 좁혀요.
## 인터페이스 ## 인터페이스
```typescript ```typescript
function isFunction(value: unknown): value is (...args: unknown[]) => unknown; function isFunction(value: unknown): value is (...args: never[]) => unknown;
``` ```
### 파라미터 ### 파라미터

View File

@ -5,7 +5,7 @@ Creates a function that negates the result of the predicate function.
## Signature ## Signature
```typescript ```typescript
function negate<F extends (...args: unknown[]) => boolean>(func: F): F; function negate<F extends (...args: never[]) => boolean>(func: F): F;
``` ```
### Parameters ### Parameters

View File

@ -9,7 +9,7 @@ This function can also serve as a type predicate in TypeScript, narrowing the ty
## Signature ## Signature
```typescript ```typescript
function isFunction(value: unknown): value is (...args: unknown[]) => unknown; function isFunction(value: unknown): value is (...args: never[]) => unknown;
``` ```
### Parameters ### Parameters
@ -18,7 +18,7 @@ function isFunction(value: unknown): value is (...args: unknown[]) => unknown;
### Returns ### 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 ## Examples

View File

@ -5,7 +5,7 @@
## 签名 ## 签名
```typescript ```typescript
function negate<F extends (...args: unknown[]) => boolean>(func: F): F; function negate<F extends (...args: never[]) => boolean>(func: F): F;
``` ```
### 参数 ### 参数

View File

@ -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
```

View File

@ -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
```