UNPKG

diginext-utils

Version:
30 lines 814 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pick = pick; /** * Creates a new object with only the specified keys from the source object. * * @template T - The type of the source object * @template K - The keys to pick * @param obj - The source object * @param keys - The keys to include in the new object * @returns A new object with only the specified keys * * @example * ```ts * const obj = { a: 1, b: 2, c: 3, d: 4 }; * pick(obj, ['a', 'c']); // { a: 1, c: 3 } * ``` */ function pick(obj, keys) { if (typeof obj !== "object" || obj === null) { return {}; } return keys.reduce((result, key) => { if (key in obj) { result[key] = obj[key]; } return result; }, {}); } //# sourceMappingURL=pick.js.map