UNPKG

object-pickby

Version:

Creates an object composed of the picked object properties. Written in Typescript for ES2022+ environments.

21 lines (20 loc) 1.11 kB
export declare function pick<T extends object, U extends keyof T>(object: T, props: readonly U[]): Pick<T, U>; export declare function pick<T extends readonly unknown[]>(array: T, indexes: readonly number[]): Array<T[number]>; /** * Creates an object composed of the `object` properties `predicate` returns * truthy for. The predicate is invoked with two arguments: (value, key). * * @category Object * @param object The source object. * @param [predicate] The function invoked per property. * @returns Returns the new object. * @example * * const object = { 'a': 1, 'b': '2', 'c': 3 }; * * pickBy(object, Number.isInteger.bind(Number)); * // => { 'a': 1, 'c': 3 } */ export declare function pickBy<U, T extends Record<string, U>>(record: T, predicate: (value: U, key: string) => boolean): Partial<T>; export declare function pickBy<T extends Record<PropertyKey, unknown>>(object: T, predicate: (value: unknown, key: PropertyKey) => boolean): Partial<T>; export declare function pickBy<U, T extends readonly U[]>(array: T, predicate: (value: U, index: number, accumulator: U[]) => boolean): T;