UNPKG

@lavadrop/pick-by

Version:

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

55 lines (36 loc) 1.79 kB
# @lavadrop/pick-by [![npm license](http://img.shields.io/npm/l/@lavadrop/pick-by.svg)](https://www.npmjs.org/package/@lavadrop/pick-by) [![Travis Build Status](https://img.shields.io/travis/jedmao/lavadrop.svg)](https://travis-ci.org/jedmao/lavadrop) [![codecov](https://codecov.io/gh/jedmao/lavadrop/branch/master/graph/badge.svg)](https://codecov.io/gh/jedmao/lavadrop) [![Try @lavadrop/pick-by on RunKit](https://badge.runkitcdn.com/@lavadrop/pick-by.svg)](https://npm.runkit.com/@lavadrop/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 [`Lavadrop`](../../../../)! [![npm](https://nodei.co/npm/@lavadrop/pick-by.svg?downloads=true)](https://nodei.co/npm/@lavadrop/pick-by/) min + gzip | 124 bytes [source](https://github.com/jedmao/lavadrop/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 '@lavadrop/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> ```