UNPKG

@queso/pick

Version:

Creates an object composed of the picked object properties.

26 lines (22 loc) 555 B
'use strict'; /** * Creates an object composed of the picked `object` properties. * @param object The source object. * @param paths The property paths to pick. * @category Object * @returns A new object composed of the picked `object` properties. * @example const obj = { a: 1, b: 2, c: 3 } pick(obj, 'a', 'c') // => { a: 1, c: 3 } */ function pick(object, ...paths) { return paths.reduce((result, key) => { if (key in object) { result[key] = object[key]; } return result }, {}) } module.exports = pick; pick.default = module.exports