@naverpay/hidash
Version:
improved lodash
22 lines (19 loc) • 1.46 kB
text/typescript
import { ObjectIterateeCustom, ObjectIteratorTypeGuard, ListIterateeCustom, ListIteratorTypeGuard } from './internal/baseIteratee.type.mjs';
import { List } from './internal/types.mjs';
/**
* @description
* Creates an array of elements from a collection that satisfy a given predicate.
* If no predicate is provided, it returns all elements in the collection.
*
* This function is similar to `Array.prototype.filter` but works with various types of collections.
*
* @param {List<T> | object} [collection] The collection to iterate over
* @param {ListIterateeCustom<T, boolean> | ObjectIterateeCustom<T, boolean>} [predicate] The function invoked per iteration
* @returns {T[]} An array of elements that satisfy the predicate
*/
declare function filter<T extends Record<string, unknown>>(collection: T | null | undefined, predicate?: ObjectIterateeCustom<T, boolean>): T[keyof T][];
declare function filter<T extends Record<string, unknown>, S extends T[keyof T]>(collection: T | null | undefined, predicate: ObjectIteratorTypeGuard<T, S>): S[];
declare function filter(collection: string | null | undefined, predicate?: ListIterateeCustom<string, boolean>): string[];
declare function filter<T, S extends T>(collection: List<T> | null | undefined, predicate: ListIteratorTypeGuard<T, S>): S[];
declare function filter<T>(collection: List<T> | null | undefined, predicate?: ListIterateeCustom<T, boolean>): T[];
export { filter as default, filter };