UNPKG

es-toolkit

Version:

A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

65 lines (64 loc) 2.13 kB
import { ListIterateeCustom } from "../_internal/ListIterateeCustom.js"; import { ObjectIterateeCustom } from "../_internal/ObjectIteratee.js"; //#region src/compat/array/every.d.ts /** * Checks if all elements in a collection pass the predicate check. * The predicate is invoked with three arguments: (value, index|key, collection). * * @template T - The type of elements in the collection * @param collection - The collection to iterate over * @param [predicate=identity] - The function invoked per iteration * @returns Returns true if all elements pass the predicate check, else false * * @example * // Using a function predicate * every([true, 1, null, 'yes'], Boolean) * // => false * * // Using property shorthand * const users = [{ user: 'barney', age: 36 }, { user: 'fred', age: 40 }] * every(users, 'age') * // => true * * // Using matches shorthand * every(users, { age: 36 }) * // => false * * // Using matchesProperty shorthand * every(users, ['age', 36]) * // => false */ declare function every<T>(collection: ArrayLike<T> | null | undefined, predicate?: ListIterateeCustom<T, boolean>): boolean; /** * Checks if all elements in an object pass the predicate check. * The predicate is invoked with three arguments: (value, key, object). * * @template T - The type of the object * @param collection - The object to iterate over * @param [predicate=identity] - The function invoked per iteration * @returns Returns true if all elements pass the predicate check, else false * * @example * // Using a function predicate * every({ a: true, b: 1, c: null }, Boolean) * // => false * * // Using property shorthand * const users = { * barney: { active: true, age: 36 }, * fred: { active: true, age: 40 } * } * every(users, 'active') * // => true * * // Using matches shorthand * every(users, { active: true }) * // => true * * // Using matchesProperty shorthand * every(users, ['age', 36]) * // => false */ declare function every<T extends object>(collection: T | null | undefined, predicate?: ObjectIterateeCustom<T, boolean>): boolean; //#endregion export { every };