From d4081c0674940292f6b6a4f7f14dfb53c419b1f5 Mon Sep 17 00:00:00 2001 From: Sojin Park Date: Sun, 21 Jul 2024 10:55:36 +0900 Subject: [PATCH] docs: Update docs for isFunction, negate, isArrayLike --- docs/.vitepress/zh_hans.mts | 2 ++ docs/ko/reference/function/negate.md | 2 +- docs/ko/reference/predicate/isFunction.md | 4 +-- docs/reference/function/negate.md | 2 +- docs/reference/predicate/isFunction.md | 4 +-- docs/zh_hans/reference/function/negate.md | 2 +- .../reference/predicate/isArrayLike.md | 34 +++++++++++++++++++ .../zh_hans/reference/predicate/isFunction.md | 33 ++++++++++++++++++ 8 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 docs/zh_hans/reference/predicate/isArrayLike.md create mode 100644 docs/zh_hans/reference/predicate/isFunction.md diff --git a/docs/.vitepress/zh_hans.mts b/docs/.vitepress/zh_hans.mts index f6fb85b1..b967fd82 100644 --- a/docs/.vitepress/zh_hans.mts +++ b/docs/.vitepress/zh_hans.mts @@ -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' }, diff --git a/docs/ko/reference/function/negate.md b/docs/ko/reference/function/negate.md index 75354eaf..da4d97ba 100644 --- a/docs/ko/reference/function/negate.md +++ b/docs/ko/reference/function/negate.md @@ -5,7 +5,7 @@ ## 인터페이스 ```typescript -function negate boolean>(func: F): F; +function negate boolean>(func: F): F; ``` ### 파라미터 diff --git a/docs/ko/reference/predicate/isFunction.md b/docs/ko/reference/predicate/isFunction.md index 01d12c66..391c387b 100644 --- a/docs/ko/reference/predicate/isFunction.md +++ b/docs/ko/reference/predicate/isFunction.md @@ -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; ``` ### 파라미터 diff --git a/docs/reference/function/negate.md b/docs/reference/function/negate.md index 242a8300..decc85e2 100644 --- a/docs/reference/function/negate.md +++ b/docs/reference/function/negate.md @@ -5,7 +5,7 @@ Creates a function that negates the result of the predicate function. ## Signature ```typescript -function negate boolean>(func: F): F; +function negate boolean>(func: F): F; ``` ### Parameters diff --git a/docs/reference/predicate/isFunction.md b/docs/reference/predicate/isFunction.md index a9f6451a..6e3dda4c 100644 --- a/docs/reference/predicate/isFunction.md +++ b/docs/reference/predicate/isFunction.md @@ -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 @@ -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 diff --git a/docs/zh_hans/reference/function/negate.md b/docs/zh_hans/reference/function/negate.md index 86807a74..079e1ae2 100644 --- a/docs/zh_hans/reference/function/negate.md +++ b/docs/zh_hans/reference/function/negate.md @@ -5,7 +5,7 @@ ## 签名 ```typescript -function negate boolean>(func: F): F; +function negate boolean>(func: F): F; ``` ### 参数 diff --git a/docs/zh_hans/reference/predicate/isArrayLike.md b/docs/zh_hans/reference/predicate/isArrayLike.md new file mode 100644 index 00000000..81137e2a --- /dev/null +++ b/docs/zh_hans/reference/predicate/isArrayLike.md @@ -0,0 +1,34 @@ +# isArrayLike + +检查一个值是否是类似数组的对象。 + +类似数组的对象是一个既不是 `null` 或 `undefined` 也不是函数,并且具有有效 `length` 属性的对象。 + +这个函数也可以作为 TypeScript 中的类型断言,将参数的类型缩小到类似数组的对象。 + +## 签名 + +```typescript +function isArrayLike(value: unknown): value is ArrayLike; +``` + +### 参数 + +- `value` (`unknown`): 要检查是否为类似数组的对象的值。 + +### 返回值 + +(`value is ArrayLike`): 如果值是类似数组的对象则返回 `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 +``` diff --git a/docs/zh_hans/reference/predicate/isFunction.md b/docs/zh_hans/reference/predicate/isFunction.md new file mode 100644 index 00000000..ed0ea205 --- /dev/null +++ b/docs/zh_hans/reference/predicate/isFunction.md @@ -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 +```