UNPKG

super-utils-plus

Version:

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

59 lines (58 loc) 1.76 kB
/** * Iterates over elements of collection, returning an array of all elements * the predicate returns truthy for. * * @param collection - The collection to iterate over * @param predicate - The function invoked per iteration * @returns The new filtered array * * @example * ```ts * const users = [ * { 'user': 'barney', 'age': 36, 'active': true }, * { 'user': 'fred', 'age': 40, 'active': false } * ]; * * filter(users, function(o) { return !o.active; }); * // => objects for ['fred'] * * // The `_.matches` iteratee shorthand. * filter(users, { 'age': 36, 'active': true }); * // => objects for ['barney'] * * // The `_.matchesProperty` iteratee shorthand. * filter(users, ['active', false]); * // => objects for ['fred'] * * // The `_.property` iteratee shorthand. * filter(users, 'active'); * // => objects for ['barney'] * ``` */ export declare function filter<T>(collection: T[], predicate: ((value: T, index: number, collection: T[]) => boolean) | Record<string, any> | string | [ string, any ]): T[]; /** * The opposite of filter; this method returns the elements of collection * that predicate does NOT return truthy for. * * @param collection - The collection to iterate over * @param predicate - The function invoked per iteration * @returns The new filtered array * * @example * ```ts * const users = [ * { 'user': 'barney', 'age': 36, 'active': false }, * { 'user': 'fred', 'age': 40, 'active': true } * ]; * * reject(users, function(o) { return !o.active; }); * // => objects for ['fred'] * ``` */ export declare function reject<T>(collection: T[], predicate: ((value: T, index: number, collection: T[]) => boolean) | Record<string, any> | string | [ string, any ]): T[];