UNPKG

super-utils-plus

Version:

A superior alternative to Lodash with improved performance, TypeScript support, and developer experience

109 lines (108 loc) 3.42 kB
/** * Iterates over elements of collection, returning the first element * predicate returns truthy for. * * @param collection - The collection to inspect * @param predicate - The function invoked per iteration * @param fromIndex - The index to search from * @returns The matched element, else undefined * * @example * ```ts * const users = [ * { 'user': 'barney', 'age': 36, 'active': true }, * { 'user': 'fred', 'age': 40, 'active': false }, * { 'user': 'pebbles', 'age': 1, 'active': true } * ]; * * find(users, function(o) { return o.age < 40; }); * // => object for 'barney' * * // The `_.matches` iteratee shorthand. * find(users, { 'age': 1, 'active': true }); * // => object for 'pebbles' * * // The `_.matchesProperty` iteratee shorthand. * find(users, ['active', false]); * // => object for 'fred' * * // The `_.property` iteratee shorthand. * find(users, 'active'); * // => object for 'barney' * ``` */ export declare function find<T>(collection: T[], predicate: ((value: T, index: number, collection: T[]) => boolean) | Record<string, any> | string | [ string, any ], fromIndex?: number): T | undefined; /** * This method is like find except that it iterates over elements of * collection from right to left. * * @param collection - The collection to inspect * @param predicate - The function invoked per iteration * @param fromIndex - The index to search from * @returns The matched element, else undefined * * @example * ```ts * findLast([1, 2, 3, 4], function(n) { * return n % 2 === 1; * }); * // => 3 * ``` */ export declare function findLast<T>(collection: T[], predicate: ((value: T, index: number, collection: T[]) => boolean) | Record<string, any> | string | [ string, any ], fromIndex?: number): T | undefined; /** * This method is like find except that it returns the index of the first * element predicate returns truthy for, instead of the element itself. * * @param array - The array to inspect * @param predicate - The function invoked per iteration * @param fromIndex - The index to search from * @returns The index of the found element, else -1 * * @example * ```ts * const users = [ * { 'user': 'barney', 'active': false }, * { 'user': 'fred', 'active': false }, * { 'user': 'pebbles', 'active': true } * ]; * * findIndex(users, function(o) { return o.user === 'barney'; }); * // => 0 * ``` */ export declare function findIndex<T>(array: T[], predicate: ((value: T, index: number, array: T[]) => boolean) | Record<string, any> | string | [ string, any ], fromIndex?: number): number; /** * This method is like findIndex except that it iterates over elements * of collection from right to left. * * @param array - The array to inspect * @param predicate - The function invoked per iteration * @param fromIndex - The index to search from * @returns The index of the found element, else -1 * * @example * ```ts * const users = [ * { 'user': 'barney', 'active': true }, * { 'user': 'fred', 'active': false }, * { 'user': 'pebbles', 'active': false } * ]; * * findLastIndex(users, function(o) { return o.user === 'pebbles'; }); * // => 2 * ``` */ export declare function findLastIndex<T>(array: T[], predicate: ((value: T, index: number, array: T[]) => boolean) | Record<string, any> | string | [ string, any ], fromIndex?: number): number;