overEvery
util
Creates a function that checks if all of the predicates return truthy when invoked with the arguments it receives.
Installation
Import
import { overEvery } from '@tulx/utils';Source Code
Implementation
/**
* Creates a function that checks if all of the predicates return truthy when invoked with the arguments it receives.
*
* @param predicates - The predicates to check.
* @returns Returns the new function.
*
* @example
* ```ts
* const func = overEvery([Boolean, isFinite]);
* func('1'); // true
* func(null); // false
* func(NaN); // false
* ```
*/
export function overEvery<T extends unknown[]>(
predicates: readonly ((...args: T) => boolean)[]
): (...args: T) => boolean {
return function (...args: T): boolean {
return predicates.every((predicate) => predicate(...args));
};
}
Example
import { overEvery } from '@tulx/utils';
const func = overEvery([Boolean, isFinite]);
func('1'); // true
func(null); // false
func(NaN); // falseRelated Functions
attempt
Attempts to invoke func, returning either the result or the caught error object.
bindAll
Binds methods of an object to the object itself, overwriting the existing method.
cond
Creates a function that iterates over pairs and invokes the corresponding function of the first predicate to return truthy.
conforms
Creates a function that invokes the predicate properties of source with the corresponding property values of a given object.
constant
Creates a function that returns value.
defaultTo
Checks value to determine whether a default value should be returned in its place.