object-pickby
Version:
Creates an object composed of the picked object properties. Written in Typescript for ES2019+ environments.
36 lines (35 loc) • 1.46 kB
TypeScript
/**
* Creates an object composed of the picked `object` properties.
*
* @category Object
* @param object The source object.
* @param [props] The property names to pick, specified
* individually or in arrays.
* @returns Returns the new object.
* @example
*
* const object = { 'a': 1, 'b': '2', 'c': 3 };
*
* only(object, ['a', 'c']);
* // => { 'a': 1, 'c': 3 }
*/
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 unknown[]>(array: T, indexes: readonly number[]): T;
/**
* 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;