docs(ary): Update docs for ary (#452)

* docs(ary): Update docs for `ary`

* Apply suggestions from code review

---------

Co-authored-by: Sojin Park <raon0211@gmail.com>
This commit is contained in:
Dongho Kim 2024-08-31 14:45:00 +09:00 committed by GitHub
parent f3620d76aa
commit 1890d8ff07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 38 additions and 32 deletions

View File

@ -11,7 +11,7 @@ function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: a
### パラメータ
- `func` (`F`): 引数の受け取りを制限する関数。
- `n` (`number`, オプション): 受け取る引数の最大数。
- `n` (`number`): 受け取る引数の最大数。
### 戻り値
@ -22,13 +22,12 @@ function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: a
```typescript
import { ary } from 'es-toolkit/function';
function fn(a, b, c) {
console.log(arguments);
function fn(a: number, b: number, c: number) {
return Array.from(arguments);
}
ary(fn, 2)(1, 2, 3); // [Arguments] { '0': 1, '1': 2 }
ary(fn); // [Arguments] { '0': 1, '1': 2, '2': 3 }
ary(fn, -1); // [Arguments] {}
ary(fn, 1.5); // [Arguments] { '0': 1 }
ary(fn, 2, {}); // [Arguments] { '0': 1, '1': 2, '2': 3 }
ary(fn, 0)(1, 2, 3) // []
ary(fn, 1)(1, 2, 3) // [1]
ary(fn, 2)(1, 2, 3) // [1, 2]
ary(fn, 3)(1, 2, 3) // [1, 2, 3]
```

View File

@ -11,7 +11,7 @@ function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: a
### 파라미터
- `func` (`F`): 인자를 받는 것을 제한할 함수.
- `n` (`number`, 선택): 최대로 받을 인자의 숫자.
- `n` (`number`): 최대로 받을 인자의 숫자.
### 반환 값
@ -22,13 +22,12 @@ function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: a
```typescript
import { ary } from 'es-toolkit/function';
function fn(a, b, c) {
console.log(arguments);
function fn(a: number, b: number, c: number) {
return Array.from(arguments);
}
ary(fn, 2)(1, 2, 3); // [Arguments] { '0': 1, '1': 2 }
ary(fn); // [Arguments] { '0': 1, '1': 2, '2': 3 }
ary(fn, -1); // [Arguments] {}
ary(fn, 1.5); // [Arguments] { '0': 1 }
ary(fn, 2, {}); // [Arguments] { '0': 1, '1': 2, '2': 3 }
ary(fn, 0)(1, 2, 3) // []
ary(fn, 1)(1, 2, 3) // [1]
ary(fn, 2)(1, 2, 3) // [1, 2]
ary(fn, 3)(1, 2, 3) // [1, 2, 3]
```

View File

@ -11,7 +11,7 @@ function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: a
### Parameters
- `func` (`F`): The function to cap arguments for.
- `n` (`number`, optional): The arity cap, defaulting to the number of parameters of `func`.
- `n` (`number`): The arity cap.
### Returns
@ -22,13 +22,12 @@ function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: a
```typescript
import { ary } from 'es-toolkit/function';
function fn(a, b, c) {
console.log(arguments);
function fn(a: number, b: number, c: number) {
return Array.from(arguments);
}
ary(fn, 2)(1, 2, 3); // [Arguments] { '0': 1, '1': 2 }
ary(fn); // [Arguments] { '0': 1, '1': 2, '2': 3 }
ary(fn, -1); // [Arguments] {}
ary(fn, 1.5); // [Arguments] { '0': 1 }
ary(fn, 2, {}); // [Arguments] { '0': 1, '1': 2, '2': 3 }
ary(fn, 0)(1, 2, 3) // []
ary(fn, 1)(1, 2, 3) // [1]
ary(fn, 2)(1, 2, 3) // [1, 2]
ary(fn, 3)(1, 2, 3) // [1, 2, 3]
```

View File

@ -11,7 +11,7 @@ function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: a
### 参数
- `func` (`F`): 要限制参数数量的函数。
- `n` (`number`, 可选): 参数数量上限,默认为 `func` 的参数个数
- `n` (`number`): 参数数量上限。
### 返回值
@ -22,13 +22,12 @@ function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: a
```typescript
import { ary } from 'es-toolkit/function';
function fn(a, b, c) {
console.log(arguments);
function fn(a: number, b: number, c: number) {
return Array.from(arguments);
}
ary(fn, 2)(1, 2, 3); // [Arguments] { '0': 1, '1': 2 }
ary(fn); // [Arguments] { '0': 1, '1': 2, '2': 3 }
ary(fn, -1); // [Arguments] {}
ary(fn, 1.5); // [Arguments] { '0': 1 }
ary(fn, 2, {}); // [Arguments] { '0': 1, '1': 2, '2': 3 }
ary(fn, 0)(1, 2, 3) // []
ary(fn, 1)(1, 2, 3) // [1]
ary(fn, 2)(1, 2, 3) // [1, 2]
ary(fn, 3)(1, 2, 3) // [1, 2, 3]
```

View File

@ -5,6 +5,16 @@
* @param {F} func - The function to cap arguments for.
* @param {number} n - The arity cap.
* @returns {(...args: any[]) => ReturnType<F>} Returns the new capped function.
*
* @example
* function fn(a: number, b: number, c: number) {
* return Array.from(arguments);
* }
*
* ary(fn, 0)(1, 2, 3) // []
* ary(fn, 1)(1, 2, 3) // [1]
* ary(fn, 2)(1, 2, 3) // [1, 2]
* ary(fn, 3)(1, 2, 3) // [1, 2, 3]
*/
export function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: any[]) => ReturnType<F> {
return function (this: any, ...args: Parameters<F>) {