mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 03:32:58 +03:00
docs: improve document (#324)
This commit is contained in:
parent
28ddb499e6
commit
c0b3af2fe1
@ -107,6 +107,7 @@ function sidebar(): DefaultTheme.Sidebar {
|
||||
{
|
||||
text: '函数工具',
|
||||
items: [
|
||||
{ text: 'before', link: '/zh_hans/reference/function/before' },
|
||||
{ text: 'after', link: '/zh_hans/reference/function/after' },
|
||||
{ text: 'debounce', link: '/zh_hans/reference/function/debounce' },
|
||||
{ text: 'throttle', link: '/zh_hans/reference/function/throttle' },
|
||||
@ -151,6 +152,7 @@ function sidebar(): DefaultTheme.Sidebar {
|
||||
{
|
||||
text: '谓词',
|
||||
items: [
|
||||
{ text: 'isArguments', link: '/zh_hans/reference/predicate/isArguments' },
|
||||
{ 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' },
|
||||
@ -163,6 +165,7 @@ function sidebar(): DefaultTheme.Sidebar {
|
||||
{ text: 'isNil', link: '/zh_hans/reference/predicate/isNil' },
|
||||
{ text: 'isNotNil', link: '/zh_hans/reference/predicate/isNotNil' },
|
||||
{ text: 'isNull', link: '/zh_hans/reference/predicate/isNull' },
|
||||
{ text: 'isObjectLike', link: '/zh_hans/reference/predicate/isObjectLike' },
|
||||
{ text: 'isTypedArray', link: '/zh_hans/reference/predicate/isTypedArray' },
|
||||
{ text: 'isUndefined', link: '/zh_hans/reference/predicate/isUndefined' },
|
||||
],
|
||||
|
@ -38,5 +38,5 @@ const value = [1, 2, 3];
|
||||
|
||||
console.log(isArguments(args)); // true
|
||||
console.log(isArguments(strictArgs)); // true
|
||||
onsole.log(isArguments(value)); // false
|
||||
console.log(isArguments(value)); // false
|
||||
```
|
||||
|
@ -35,4 +35,5 @@ console.log(isObjectLike(value1)); // true
|
||||
console.log(isObjectLike(value2)); // true
|
||||
console.log(isObjectLike(value3)); // false
|
||||
console.log(isObjectLike(value4)); // false
|
||||
console.log(isObjectLike(value5)); // false
|
||||
```
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
Removes elements from the end of an array until the predicate returns false.
|
||||
|
||||
This function iterates over an array and drops elements from the start until the provided
|
||||
This function iterates over an array and drops elements from the end until the provided
|
||||
predicate function returns false. It then returns a new array with the remaining elements.
|
||||
|
||||
## Signature
|
||||
|
@ -36,5 +36,5 @@ const value = [1, 2, 3];
|
||||
|
||||
console.log(isArguments(args)); // true
|
||||
console.log(isArguments(strictArgs)); // true
|
||||
onsole.log(isArguments(value)); // false
|
||||
console.log(isArguments(value)); // false
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
# isObjectLike
|
||||
|
||||
Check if a value is an object-like array.
|
||||
Check if a value is an object-like.
|
||||
|
||||
It returns `true` if the value is an object-like, and `false` otherwise.
|
||||
|
||||
@ -35,4 +35,5 @@ console.log(isObjectLike(value1)); // true
|
||||
console.log(isObjectLike(value2)); // true
|
||||
console.log(isObjectLike(value3)); // false
|
||||
console.log(isObjectLike(value4)); // false
|
||||
console.log(isObjectLike(value5)); // false
|
||||
```
|
||||
|
47
docs/zh_hans/reference/function/before.md
Normal file
47
docs/zh_hans/reference/function/before.md
Normal file
@ -0,0 +1,47 @@
|
||||
# before
|
||||
|
||||
创建一个新函数,该函数限制给定函数 (`func`) 被调用的次数。
|
||||
|
||||
## 签名
|
||||
|
||||
```typescript
|
||||
function before<F extends (...args: any[]) => any>(n: number, func: F): F;
|
||||
```
|
||||
|
||||
### 参数
|
||||
|
||||
- `n` (`number`): 返回的函数在停止之前允许调用 func 的次数。
|
||||
- 如果 `n` 为 0,则不会调用 ·。
|
||||
- 如果 `n` 是正整数,则 `func` 最多被调用 `n-1` 次。
|
||||
- `func` (`F`): 需要应用调用限制的函数。
|
||||
|
||||
### 返回值
|
||||
|
||||
(`F`): 一个新函数,该函数:
|
||||
|
||||
- 追踪调用次数。
|
||||
- 在调用次数达到 `n-1` 次之前调用 `func`。
|
||||
- 如果调用次数达到或超过 `n`,返回 `undefined`,并停止进一步调用。
|
||||
|
||||
### 抛出异常
|
||||
|
||||
如果 `n` 不是非负整数,则抛出错误。
|
||||
|
||||
## 示例
|
||||
|
||||
```typescript
|
||||
import { before } from 'es-toolkit/function';
|
||||
|
||||
const beforeFn = before(3, () => {
|
||||
console.log('called');
|
||||
});
|
||||
|
||||
// 将会打印 'called'.
|
||||
beforeFn();
|
||||
|
||||
// 将会打印 'called'.
|
||||
beforeFn();
|
||||
|
||||
// 不会打印 anything.
|
||||
beforeFn();
|
||||
```
|
40
docs/zh_hans/reference/predicate/isArguments.md
Normal file
40
docs/zh_hans/reference/predicate/isArguments.md
Normal file
@ -0,0 +1,40 @@
|
||||
# isArguments
|
||||
|
||||
检查一个值是否是 `arguments` 对象。
|
||||
|
||||
如果该值是 `arguments` 对象,则返回 `true`,否则返回 `false`。
|
||||
|
||||
这个函数也可以在 TypeScript 中作为类型断言使用,将参数的类型缩小为 `arguments` 对象。
|
||||
|
||||
## 签名
|
||||
|
||||
```typescript
|
||||
function isArguments(value?: unknown): value is IArguments;
|
||||
```
|
||||
|
||||
### 参数
|
||||
|
||||
- `value` (`unknown`): 要检查是否为 `arguments` 对象的值。
|
||||
|
||||
### 返回值
|
||||
|
||||
(`value is IArguments`): 如果该值是 `arguments` 对象,则返回 `true`,否则返回 `false`。
|
||||
|
||||
## 示例
|
||||
|
||||
```typescript
|
||||
import { isArguments } from 'es-toolkit/predicate';
|
||||
|
||||
const args = (function () {
|
||||
return arguments;
|
||||
})();
|
||||
const strictArgs = (function () {
|
||||
'use strict';
|
||||
return arguments;
|
||||
})();
|
||||
const value = [1, 2, 3];
|
||||
|
||||
console.log(isArguments(args)); // true
|
||||
console.log(isArguments(strictArgs)); // true
|
||||
console.log(isArguments(value)); // false
|
||||
```
|
39
docs/zh_hans/reference/predicate/isObjectLike.md
Normal file
39
docs/zh_hans/reference/predicate/isObjectLike.md
Normal file
@ -0,0 +1,39 @@
|
||||
# isObjectLike
|
||||
|
||||
检查一个值是否是类对象。
|
||||
|
||||
如果该值是类对象,则返回 `true`,否则返回 `false`。
|
||||
|
||||
这个函数也可以在 TypeScript 中作为类型断言使用,将参数的类型缩小为类对象。
|
||||
|
||||
## 签名
|
||||
|
||||
```typescript
|
||||
export function isObjectLike<T>(value: T): value is Extract<T, object>;
|
||||
```
|
||||
|
||||
### 参数
|
||||
|
||||
- `value` (`T`): 要检查是否为类对象的值。
|
||||
|
||||
### 返回值
|
||||
|
||||
(`value is Extract<T, object>`): 如果该值是类对象,则返回 `true`,否则返回 `false`。
|
||||
|
||||
## 示例
|
||||
|
||||
```typescript
|
||||
import { isObjectLike } from 'es-toolkit/predicate';
|
||||
|
||||
const value1 = { a: 1 };
|
||||
const value2 = [1, 2, 3];
|
||||
const value3 = 'abc';
|
||||
const value4 = () => {};
|
||||
const value5 = null;
|
||||
|
||||
console.log(isObjectLike(value1)); // true
|
||||
console.log(isObjectLike(value2)); // true
|
||||
console.log(isObjectLike(value3)); // false
|
||||
console.log(isObjectLike(value4)); // false
|
||||
console.log(isObjectLike(value5)); // false
|
||||
```
|
Loading…
Reference in New Issue
Block a user