UNPKG

@queso/pick-by

Version:

Creates an object composed of the object properties for which predicate returns truthy.

55 lines (36 loc) 1.74 kB
# @queso/pick-by [![npm license](http://img.shields.io/npm/l/@queso/pick-by.svg)](https://www.npmjs.org/package/@queso/pick-by) [![Travis Build Status](https://img.shields.io/travis/jedmao/queso.svg)](https://travis-ci.org/jedmao/queso) [![codecov](https://codecov.io/gh/jedmao/queso/branch/master/graph/badge.svg)](https://codecov.io/gh/jedmao/queso) [![Try @queso/pick-by on RunKit](https://badge.runkitcdn.com/@queso/pick-by.svg)](https://npm.runkit.com/@queso/pick-by) Part of a [library](../../../../) of zero-dependency npm modules that do just one thing. - 100% [TypeScript](http://www.typescriptlang.org/) support. - It's not a party without [`Queso`](../../../../)! [![npm](https://nodei.co/npm/@queso/pick-by.svg?downloads=true)](https://nodei.co/npm/@queso/pick-by/) min + gzip | 124 bytes [source](https://github.com/jedmao/queso/blob/master/src/packages/pick-by/pickBy.ts) Creates an object composed of the object properties for which predicate returns truthy. ## Usage ```ts import pickBy from '@queso/pick-by' const obj = { a: 0, b: '', c: true, d: 'hello' } pickBy(obj) // => { c: true, d: 'hello' } ``` ## Parameters | Name | Type | Description | | :---------- | :------------------------------------------------ | :--------------------------------- | | `object` | `T` | The source object. | | `predicate` | `<K extends keyof T>(value: T[K], key: K) => any` | The function invoked per property. | ### Type parameters | Name | Constraint | | :--- | :--------- | | `T` | `object` | | `K` | `keyof T` | ## Returns The new object. ### Return type ```ts Partial<T> ```