mesh-fetcher
Version:
A Node.js package for fetching data from multiple APIs with enhanced features.
28 lines (27 loc) • 990 B
TypeScript
import { ObjectUtilOptions } from '../types';
/**
* Creates a new object with only the specified properties.
* Supports nested paths, array indices, and wildcards.
*
* @template T - The type of the source object
* @param {T} obj - The source object
* @param {string[]} paths - Array of paths to pick (e.g., ['name', 'details.age', 'contacts.*.email'])
* @param {ObjectUtilOptions} [options] - Options for pick behavior
* @returns {Partial<T>} A new object with only the specified paths
*
* @example
* ```typescript
* const user = {
* name: 'John',
* details: { age: 30, email: 'john@example.com' },
* contacts: [{ type: 'email', value: 'john@example.com' }]
* };
* const result = pick(user, ['name', 'details.age', 'contacts.*.type']);
* // {
* // name: 'John',
* // details: { age: 30 },
* // contacts: [{ type: 'email' }]
* // }
* ```
*/
export declare function pick<T extends object>(obj: T, paths: string[], options?: ObjectUtilOptions): Partial<T>;