Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(overEvery): add overEvery to compat #1078

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions benchmarks/performance/overEvery.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { bench, describe } from 'vitest';
import { overEvery as overEveryToolkit_ } from 'es-toolkit/compat';
import { overEvery as overEveryLodash_ } from 'lodash';

const overEveryToolkit = overEveryToolkit_;
const overEveryLodash = overEveryLodash_;

describe('overEvery', () => {
bench('es-toolkit/overEvery', () => {
const overEvery = overEveryToolkit([Boolean, Number.isFinite]);
overEvery('1');
});

bench('lodash/overEvery', () => {
const overEvery = overEveryLodash([Boolean, Number.isFinite]);
overEvery('1');
});
});
65 changes: 65 additions & 0 deletions docs/ja/reference/compat/util/overEvery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# overEvery

::: info
この関数は互換性のために `es-toolkit/compat` からのみインポートできます。代替可能なネイティブ JavaScript API があるか、まだ十分に最適化されていないためです。

`es-toolkit/compat` からこの関数をインポートすると、[lodash と完全に同じように動作](../../../compatibility.md)します。
:::

提供された値に対して、すべての指定された述語が真を返すかどうかを確認する関数を作成します。

この関数は、複数の述語を受け取ります。これは個別の述語関数や述語の配列のいずれかであり、
提供された値に対してすべての述語が真を返すかどうかを確認する新しい関数を返します。

## インターフェース

```typescript
function overEvery<T, U extends T, V extends T>(
predicate1: (value: T) => value is U,
predicate2: (value: T) => value is V
): (value: T) => value is U & V;
function overEvery<T>(
...predicates: Array<((...args: T[]) => boolean) | ReadonlyArray<(...args: T[]) => boolean>>
): (...args: T[]) => boolean;
```

### パラメータ

- `predicates` (`...Array<((...values: T[]) => boolean) | ReadonlyArray<(...values: T[]) => boolean>>`): -
述語または述語の配列のリストです。各述語は、型 `T` の1つ以上の値を受け取り、
その値に対して条件が満たされるかどうかを示すブール値を返す関数です。

### 戻り値

(`(...values: T[]) => boolean`): 値のリストを取り、提供された値に対してすべての述語が真を返す場合は `true` を、
そうでない場合は `false` を返す関数です。

## 例

```typescript
const func = overEvery(
(value) => typeof value === 'string',
(value) => value.length > 3
);

func("hello"); // true
func("hi"); // false
func(42); // false

const func = overEvery([
(value) => value.a > 0,
(value) => value.b > 0
]);

func({ a: 1, b: 2 }); // true
func({ a: 0, b: 2 }); // false

const func = overEvery(
(a, b) => typeof a === 'string' && typeof b === 'string',
(a, b) => a.length > 3 && b.length > 3
);

func("hello", "world"); // true
func("hi", "world"); // false
func(1, 10); // false
```
65 changes: 65 additions & 0 deletions docs/ko/reference/compat/util/overEvery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# overEvery

::: info
이 함수는 호환성을 위한 `es-toolkit/compat` 에서만 가져올 수 있어요. 대체할 수 있는 네이티브 JavaScript API가 있거나, 아직 충분히 최적화되지 않았기 때문이에요.

`es-toolkit/compat`에서 이 함수를 가져오면, [lodash와 완전히 똑같이 동작](../../../compatibility.md)해요.
:::

주어진 모든 조건 함수들에 대해 제공된 값들이 참을 반환하는지 확인하는 함수를 생성해요.

이 함수는 여러 개의 조건 함수를 받아요. 이 조건 함수들은 개별적인 함수일 수도 있고, 조건 함수들의 배열로도 이루어질 수 있어요.
제공된 값들에 대해 호출되었을 때 모든 조건 함수가 참을 반환하는지 확인하는 새로운 함수를 반환해요.

## 인터페이스

```typescript
function overEvery<T, U extends T, V extends T>(
predicate1: (value: T) => value is U,
predicate2: (value: T) => value is V
): (value: T) => value is U & V;
function overEvery<T>(
...predicates: Array<((...args: T[]) => boolean) | ReadonlyArray<(...args: T[]) => boolean>>
): (...args: T[]) => boolean;
```

### 파라미터

- `predicates` (`...Array<((...values: T[]) => boolean) | ReadonlyArray<(...values: T[]) => boolean>>`): -
조건 함수 또는 조건 함수 배열의 목록이에요. 각 조건 함수는 하나 이상의 값 `T` 타입을 받아들이고,
그 값들이 조건을 만족하는지 여부를 나타내는 boolean을 반환하는 함수에요.

### 반환 값

(`(...values: T[]) => boolean`): 값의 리스트를 받아 제공된 값들에 대해 모든 조건 함수가 참을 반환하면 `true`를,
그렇지 않으면 `false`를 반환하는 함수에요.

## 예시

```typescript
const func = overEvery(
(value) => typeof value === 'string',
(value) => value.length > 3
);

func("hello"); // true
func("hi"); // false
func(42); // false

const func = overEvery([
(value) => value.a > 0,
(value) => value.b > 0
]);

func({ a: 1, b: 2 }); // true
func({ a: 0, b: 2 }); // false

const func = overEvery(
(a, b) => typeof a === 'string' && typeof b === 'string',
(a, b) => a.length > 3 && b.length > 3
);

func("hello", "world"); // true
func("hi", "world"); // false
func(1, 10); // false
```
65 changes: 65 additions & 0 deletions docs/reference/compat/util/overEvery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# overEvery

::: info
This function is only available in `es-toolkit/compat` for compatibility reasons. It either has alternative native JavaScript APIs or isn’t fully optimized yet.

When imported from `es-toolkit/compat`, it behaves exactly like lodash and provides the same functionalities, as detailed [here](../../../compatibility.md).
:::

Creates a function that checks if all of the given predicates return truthy for the provided values.

This function takes multiple predicates, which can either be individual predicate functions or arrays of predicates,
and returns a new function that checks if all of the predicates return truthy when called with the provided values.

## Signature

```typescript
function overEvery<T, U extends T, V extends T>(
predicate1: (value: T) => value is U,
predicate2: (value: T) => value is V
): (value: T) => value is U & V;
function overEvery<T>(
...predicates: Array<((...args: T[]) => boolean) | ReadonlyArray<(...args: T[]) => boolean>>
): (...args: T[]) => boolean;
```

### Parameters

- `predicates` (`...Array<((...values: T[]) => boolean) | ReadonlyArray<(...values: T[]) => boolean>>`): -
A list of predicates or arrays of predicates. Each predicate is a function that takes one or more values of
type `T` and returns a boolean indicating whether the condition is satisfied for those values.

### Returns

(`(...values: T[]) => boolean`): A function that takes a list of values and returns `true` if all of the
predicates return truthy for the provided values, and `false` otherwise.

## Examples

```typescript
const func = overEvery(
(value) => typeof value === 'string',
(value) => value.length > 3
);

func("hello"); // true
func("hi"); // false
func(42); // false

const func = overEvery([
(value) => value.a > 0,
(value) => value.b > 0
]);

func({ a: 1, b: 2 }); // true
func({ a: 0, b: 2 }); // false

const func = overEvery(
(a, b) => typeof a === 'string' && typeof b === 'string',
(a, b) => a.length > 3 && b.length > 3
);

func("hello", "world"); // true
func("hi", "world"); // false
func(1, 10); // false
```
62 changes: 62 additions & 0 deletions docs/zh_hans/reference/compat/util/overEvery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# overEvery

::: info
出于兼容性原因,此函数仅在 `es-toolkit/compat` 中提供。它可能具有替代的原生 JavaScript API,或者尚未完全优化。

从 `es-toolkit/compat` 导入时,它的行为与 lodash 完全一致,并提供相同的功能,详情请见 [这里](../../../compatibility.md)。
:::

创建一个函数来检查所有给定的谓词是否对提供的值返回真值。

此函数接收多个谓词,可以是单个谓词函数或谓词数组,并返回一个新函数,该函数检查当调用提供的值时,所有谓词是否返回真值。

## 签名

```typescript
function overEvery<T, U extends T, V extends T>(
predicate1: (value: T) => value is U,
predicate2: (value: T) => value is V
): (value: T) => value is U & V;
function overEvery<T>(
...predicates: Array<((...args: T[]) => boolean) | ReadonlyArray<(...args: T[]) => boolean>>
): (...args: T[]) => boolean;
```

### 参数

- `predicates` (`...Array<((...values: T[]) => boolean) | ReadonlyArray<(...values: T[]) => boolean>>`): -
一个谓词或谓词数组的列表。每个谓词是一个函数,它接受一个或多个类型为`T`的值,并返回一个布尔值,指示这些值是否满足条件。

### 返回值

(`(...values: T[]) => boolean`): 一个函数,该函数接收一个值列表,如果所有谓词对提供的值返回真值,则返回`true`,否则返回`false`。

## 示例

```typescript
const func = overEvery(
(value) => typeof value === 'string',
(value) => value.length > 3
);

func("hello"); // true
func("hi"); // false
func(42); // false

const func = overEvery([
(value) => value.a > 0,
(value) => value.b > 0
]);

func({ a: 1, b: 2 }); // true
func({ a: 0, b: 2 }); // false

const func = overEvery(
(a, b) => typeof a === 'string' && typeof b === 'string',
(a, b) => a.length > 3 && b.length > 3
);

func("hello", "world"); // true
func("hi", "world"); // false
func(1, 10); // false
```
1 change: 1 addition & 0 deletions src/compat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export { lte } from './util/lte.ts';
export { method } from './util/method.ts';
export { methodOf } from './util/methodOf.ts';
export { now } from './util/now.ts';
export { overEvery } from './util/overEvery.ts';
export { stubArray } from './util/stubArray.ts';
export { stubFalse } from './util/stubFalse.ts';
export { stubObject } from './util/stubObject.ts';
Expand Down
Loading
Loading