@queso/pick-by
Version:
Creates an object composed of the object properties for which predicate returns truthy.
55 lines (36 loc) • 1.74 kB
Markdown
# @queso/pick-by
[](https://www.npmjs.org/package/@queso/pick-by)
[](https://travis-ci.org/jedmao/queso)
[](https://codecov.io/gh/jedmao/queso)
[](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`](../../../../)!
[](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>
```