-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Update docs for isFunction, negate, isArrayLike
- Loading branch information
Showing
8 changed files
with
76 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |