docs(every): Update docs for every (#617)

This commit is contained in:
Dongho Kim 2024-09-29 17:37:30 +09:00 committed by GitHub
parent 93d256d21d
commit 6fa1f00e07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 39 deletions

View File

@ -18,6 +18,7 @@
## インターフェース
```typescript
function every<T>(arr: T[]): boolean;
function every<T>(arr: T[], doesMatch: (item: T, index: number, arr: T[]) => unknown): boolean;
function every<T>(arr: T[], doesMatch: Partial<T>): boolean;
function every<T>(arr: T[], doesMatch: [keyof T, unknown]): boolean;
@ -25,7 +26,7 @@ function every<T>(arr: T[], doesMatch: string): boolean;
function every<T extends Record<string, unknown>>(
object: T,
doesMatch: (item: T[keyof T], index: number, object: T) => unknown
doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown
): boolean;
function every<T extends Record<string, unknown>>(object: T, doesMatch: Partial<T[keyof T]>): boolean;
function every<T extends Record<string, unknown>>(object: T, doesMatch: [keyof T, unknown]): boolean;
@ -46,7 +47,7 @@ function every<T extends Record<string, unknown>>(object: T, doesMatch: string):
- **プロパティ名** (`string`): 指定されたプロパティがすべての要素に対して真と評価される場合、結果は `true` になります。
- オブジェクトの場合:
- **検査関数** (`(item: T[keyof T], index: number, object: T) => unknown`): 条件を満たすかどうかを確認する関数。すべての要素が条件を満たす場合、結果は `true` になります。
- **検査関数** (`(value: T[keyof T], key: keyof T, object: T) => unknown`): 条件を満たすかどうかを確認する関数。すべての要素が条件を満たす場合、結果は `true` になります。
- **部分値** (`Partial<T[keyof T]>`): 与えられた部分値に一致する場合、すべての要素が条件を満たす必要があります。
- **プロパティ-値ペア** (`[keyof T, unknown]`): 最初が一致させるプロパティ、2番目が一致させる値を表すタプル。すべての要素がこの条件を満たす場合、結果は `true` になります。
- **プロパティ名** (`string`): 指定されたプロパティがすべての要素に対して真と評価される場合、結果は `true` になります。
@ -89,7 +90,7 @@ const items = [
{ id: 2, name: 'Bob' },
];
const result = every(items, 'name');
console.log(result); // false
console.log(result); // true
```
### オブジェクトの場合
@ -99,7 +100,7 @@ import { every } from 'es-toolkit/compat';
// 検査関数を使う場合
const obj = { a: 1, b: 2, c: 3 };
const result = every(obj, item => item > 0);
const result = every(obj, value => value > 0);
console.log(result); // true
// 部分オブジェクトを使う場合
@ -108,12 +109,12 @@ const result = every(obj, { name: 'Bob' });
console.log(result); // false
// プロパティ-値ペアを使う場合
const items = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
const result = every(items, ['name', 'Alice']);
const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
const result = every(obj, ['name', 'Alice']);
console.log(result); // false
// プロパティ名を使う場合
const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } };
const result = every(obj, 'name');
console.log(result); // false
console.log(result); // true
```

View File

@ -18,6 +18,7 @@
## 인터페이스
```typescript
function every<T>(arr: T[]): boolean;
function every<T>(arr: T[], doesMatch: (item: T, index: number, arr: T[]) => unknown): boolean;
function every<T>(arr: T[], doesMatch: Partial<T>): boolean;
function every<T>(arr: T[], doesMatch: [keyof T, unknown]): boolean;
@ -25,7 +26,7 @@ function every<T>(arr: T[], doesMatch: string): boolean;
function every<T extends Record<string, unknown>>(
object: T,
doesMatch: (item: T[keyof T], index: number, object: T) => unknown
doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown
): boolean;
function every<T extends Record<string, unknown>>(object: T, doesMatch: Partial<T[keyof T]>): boolean;
function every<T extends Record<string, unknown>>(object: T, doesMatch: [keyof T, unknown]): boolean;
@ -46,7 +47,7 @@ function every<T extends Record<string, unknown>>(object: T, doesMatch: string):
- **프로퍼티 이름** (`string`): 모든 요소가 해당 프로퍼티에 대해 참으로 평가되는 값을 가져야 `true`를 반환.
- 객체의 경우:
- **검사 함수** (`(item: T[keyof T], index: number, object: T) => unknown`): 모든 요소가 조건을 만족하는지 확인하는 함수.
- **검사 함수** (`(value: T[keyof T], key: keyof T, object: T) => unknown`): 모든 요소가 조건을 만족하는지 확인하는 함수.
- **Partial value** (`Partial<T[keyof T]>`): 모든 요소가 주어진 부분 값에 일치해야 `true`를 반환하는 객체.
- **Property-value pair** (`[keyof T, unknown]`): 첫 번째가 일치시킬 프로퍼티, 두 번째가 일치시킬 값을 나타내는 튜플로, 모든 요소가 이 조건을 만족해야 `true`를 반환.
- **Property name** (`string`): 모든 요소가 해당 프로퍼티에 대해 참으로 평가되는 값을 가져야 `true`를 반환.
@ -89,7 +90,7 @@ const items = [
{ id: 2, name: 'Bob' },
];
const result = every(items, 'name');
console.log(result); // false
console.log(result); // true
```
### 객체의 경우
@ -99,7 +100,7 @@ import { every } from 'es-toolkit/compat';
// 검사 함수를 쓰는 경우
const obj = { a: 1, b: 2, c: 3 };
const result = every(obj, item => item > 0);
const result = every(obj, value => value > 0);
console.log(result); // true
// 부분 객체를 쓰는 경우
@ -108,12 +109,12 @@ const result = every(obj, { name: 'Bob' });
console.log(result); // false
// 프로퍼티-값 쌍을 쓰는 경우
const items = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
const result = every(items, ['name', 'Alice']);
const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
const result = every(obj, ['name', 'Alice']);
console.log(result); // false
// 프로퍼티 이름을 쓰는 경우
const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } };
const result = every(obj, 'name');
console.log(result); // false
console.log(result); // true
```

View File

@ -18,6 +18,7 @@ You can specify the condition in several ways:
## Signature
```typescript
function every<T>(arr: T[]): boolean;
function every<T>(arr: T[], doesMatch: (item: T, index: number, arr: T[]) => unknown): boolean;
function every<T>(arr: T[], doesMatch: Partial<T>): boolean;
function every<T>(arr: T[], doesMatch: [keyof T, unknown]): boolean;
@ -25,7 +26,7 @@ function every<T>(arr: T[], doesMatch: string): boolean;
function every<T extends Record<string, unknown>>(
object: T,
doesMatch: (item: T[keyof T], index: number, object: T) => unknown
doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown
): boolean;
function every<T extends Record<string, unknown>>(object: T, doesMatch: Partial<T[keyof T]>): boolean;
function every<T extends Record<string, unknown>>(object: T, doesMatch: [keyof T, unknown]): boolean;
@ -46,7 +47,7 @@ function every<T extends Record<string, unknown>>(object: T, doesMatch: string):
- **Property name** (`string`): The name of the property to check for a truthy value.
- For the `every` overloads with objects:
- **Predicate function** (`(item: T[keyof T], index: number, object: T) => unknown`): A function that takes an item, its key, and the object, and returns a truthy value if the item matches the criteria.
- **Predicate function** (`(value: T[keyof T], key: keyof T, object: T) => unknown`): A function that takes an value, its key, and the object, and returns a truthy value if the item matches the criteria.
- **Partial value** (`Partial<T[keyof T]>`): A partial value to match against the values of the object.
- **Property-value pair** (`[keyof T, unknown]`): An array where the first element is the property key and the second element is the value to match.
- **Property name** (`string`): The name of the property to check for a truthy value.
@ -89,7 +90,7 @@ const items = [
{ id: 2, name: 'Bob' },
];
const result = every(items, 'name');
console.log(result); // false
console.log(result); // true
```
### Objects
@ -99,7 +100,7 @@ import { every } from 'es-toolkit/compat';
// Using a predicate function
const obj = { a: 1, b: 2, c: 3 };
const result = every(obj, item => item > 0);
const result = every(obj, value => value > 0);
console.log(result); // true
// Using a partial value
@ -108,12 +109,12 @@ const result = every(obj, { name: 'Bob' });
console.log(result); // false
// Using a property-value pair
const items = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
const result = every(items, ['name', 'Alice']);
const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
const result = every(obj, ['name', 'Alice']);
console.log(result); // false
// Using a property name
const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } };
const result = every(obj, 'name');
console.log(result); // false
console.log(result); // true
```

View File

@ -19,6 +19,7 @@
## 签名
```typescript
function every<T>(arr: T[]): boolean;
function every<T>(arr: T[], doesMatch: (item: T, index: number, arr: T[]) => unknown): boolean;
function every<T>(arr: T[], doesMatch: Partial<T>): boolean;
function every<T>(arr: T[], doesMatch: [keyof T, unknown]): boolean;
@ -26,7 +27,7 @@ function every<T>(arr: T[], doesMatch: string): boolean;
function every<T extends Record<string, unknown>>(
object: T,
doesMatch: (item: T[keyof T], index: number, object: T) => unknown
doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown
): boolean;
function every<T extends Record<string, unknown>>(object: T, doesMatch: Partial<T[keyof T]>): boolean;
function every<T extends Record<string, unknown>>(object: T, doesMatch: [keyof T, unknown]): boolean;
@ -47,7 +48,7 @@ function every<T extends Record<string, unknown>>(object: T, doesMatch: string):
- **属性名称** (`string`): 要检查其真值的属性名称,所有项必须具有该属性且其值为真。
- 对于对象的 `every` 重载:
- **检查函数** (`(item: T[keyof T], index: number, object: T) => unknown`): 一个函数,接受项、其键和对象,如果所有项都符合条件则返回 `true`
- **检查函数** (`(value: T[keyof T], key: keyof T, object: T) => unknown`): 一个函数,接受项、其键和对象,如果所有项都符合条件则返回 `true`
- **部分值** (`Partial<T[keyof T]>`): 用于与对象的值进行匹配的部分值,所有项必须匹配这些值。
- **属性-值对** (`[keyof T, unknown]`): 一个数组,第一个元素是属性键,第二个元素是要匹配的值,所有项必须匹配该属性和值。
- **属性名称** (`string`): 要检查其真值的属性名称,所有项必须具有该属性且其值为真。
@ -90,7 +91,7 @@ const items = [
{ id: 2, name: 'Bob' },
];
const result = every(items, 'name');
console.log(result); // false
console.log(result); // true
```
### 对象
@ -100,7 +101,7 @@ import { every } from 'es-toolkit/compat';
// 使用谓词函数
const obj = { a: 1, b: 2, c: 3 };
const result = every(obj, item => item > 0);
const result = every(obj, value => value > 0);
console.log(result); // true
// 使用部分对象
@ -109,12 +110,12 @@ const result = every(obj, { name: 'Bob' });
console.log(result); // false
// 使用属性-值对
const items = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
const result = every(items, ['name', 'Alice']);
const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
const result = every(obj, ['name', 'Alice']);
console.log(result); // false
// 使用属性名称
const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } };
const result = every(obj, 'name');
console.log(result); // false
console.log(result); // true
```

View File

@ -57,7 +57,7 @@ export function every<T>(arr: readonly T[], doesMatch: Partial<T>): boolean;
* Checks if every item in an array matches a property with a specific value.
*
* @template T
* @param {readonly T[]} arr - The array to check through.
* @param {T[]} arr - The array to check through.
* @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
* @returns {boolean} - `true` if every item has the specified property value, or `false` if at least one item does not match.
*
@ -73,7 +73,7 @@ export function every<T>(arr: readonly T[], doesMatchProperty: [keyof T, unknown
* Checks if every item in an array has a specific property, where the property name is provided as a string.
*
* @template T
* @param {readonly T[]} arr - The array to check through.
* @param {T[]} arr - The array to check through.
* @param {string} propertyToCheck - The property name to check.
* @returns {boolean} - `true` if every item has the specified property, or `false` if at least one item does not match.
*
@ -89,26 +89,26 @@ export function every<T>(arr: readonly T[], propertyToCheck: string): boolean;
* Checks if every item in an object matches the given predicate function.
*
* @template T
* @param {T extends Record<string, unknown> ? T : never} object - The object to check through.
* @param {(item: T[keyof T], index: keyof T, arr: T) => unknown} doesMatch - A function that takes an item, its key, and the object, and returns a truthy value if the item matches the criteria.
* @param {T} object - The object to check through.
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} doesMatch - A function that takes an value, its key, and the object, and returns a truthy value if the item matches the criteria.
* @returns {boolean} - `true` if every property value matches the predicate, or `false` if at least one does not match.
*
* @example
* // Using a predicate function
* const obj = { a: 1, b: 2, c: 3 };
* const result = every(obj, (item) => item > 0);
* const result = every(obj, (value) => value > 0);
* console.log(result); // true
*/
export function every<T extends Record<string, unknown>>(
object: T,
doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown
doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown
): boolean;
/**
* Checks if every item in an object matches the given partial value.
*
* @template T
* @param {T extends Record<string, unknown> ? T : never} object - The object to check through.
* @param {T} object - The object to check through.
* @param {Partial<T[keyof T]>} doesMatch - A partial value to match against the values of the object.
* @returns {boolean} - `true` if every property value matches the partial value, or `false` if at least one does not match.
*
@ -124,14 +124,14 @@ export function every<T extends Record<string, unknown>>(object: T, doesMatch: P
* Checks if every item in an object matches a property with a specific value.
*
* @template T
* @param {readonly T[]} object - The object to check through.
* @param {T[]} object - The object to check through.
* @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
* @returns {boolean} - `true` if every item has the specified property value, or `false` if at least one item does not match.
*
* @example
* // Using a property-value pair
* const items = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
* const result = every(items, ['name', 'Alice']);
* const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
* const result = every(obj, ['name', 'Alice']);
* console.log(result); // false
*/
export function every<T extends Record<string, unknown>>(object: T, doesMatchProperty: [keyof T, unknown]): boolean;
@ -140,7 +140,7 @@ export function every<T extends Record<string, unknown>>(object: T, doesMatchPro
* Checks if every item in an object has a specific property, where the property name is provided as a string.
*
* @template T
* @param {T extends Record<string, unknown> ? T : never} object - The object to check through.
* @param {T} object - The object to check through.
* @param {string} propertyToCheck - The property name to check.
* @returns {boolean} - `true` if every property value has the specified property, or `false` if at least one does not match.
*