Aller au contenu principal

overEvery()

overEvery<T>(predicates): (value) => boolean

Creates a function that checks if all of the predicates return truthy when invoked with the arguments it receives.

DEPRECATED

Use predicates.every(fn => fn(value)) directly instead.


Type Parameters

T: T

The type of the value to check.


Parameters

predicates: (value) => boolean[]

The predicates to check.


Returns

A function that returns true if all predicates pass.


See Also

Array.every() - MDN


Since

2.0.0


Also known as

allPass (Ramda) · overEvery (Lodash, es-toolkit) · ❌ (Remeda, Radashi, Effect, Modern Dash, Antfu)


Example

// ❌ Deprecated approach
const isPositiveEven = overEvery([n => n > 0, n => n % 2 === 0]);
isPositiveEven(4); // => true
isPositiveEven(-2); // => false

// ✅ Recommended approach
const predicates = [(n: number) => n > 0, (n: number) => n % 2 === 0];
const isPositiveEven = (n: number) => predicates.every(fn => fn(n));
isPositiveEven(4); // => true
isPositiveEven(-2); // => false

How it works?

Creates a function that checks if all predicates return truthy. Deprecated: Use Array.every() with predicates.

Native Equivalent

// ❌ overEvery([fn1, fn2])(value)
// ✅ [fn1, fn2].every(fn => fn(value))

Use Cases

Combine predicates with AND 📌

Check if all predicates pass.

const predicates = [
(n: number) => n > 0,
(n: number) => n % 2 === 0
];
const isPositiveEven = (n: number) => predicates.every(fn => fn(n));
isPositiveEven(4); // true
isPositiveEven(-2); // false

Validate multiple rules

Ensure value passes all validation rules.

const rules = [
(s: string) => s.length >= 8,
(s: string) => /[A-Z]/.test(s),
(s: string) => /[0-9]/.test(s)
];
const isValidPassword = (s: string) => rules.every(r => r(s));