0.3.0 • Published 5 years ago

@lavadrop/pick-by v0.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

@lavadrop/pick-by

npm license Travis Build Status codecov Try @lavadrop/pick-by on RunKit

Part of a library of zero-dependency npm modules that do just one thing.

npm

min + gzip | 124 bytes

source

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

Usage

import pickBy from '@lavadrop/pick-by'

const obj = { a: 0, b: '', c: true, d: 'hello' }
pickBy(obj)
// => { c: true, d: 'hello' }

Parameters

NameTypeDescription
objectTThe source object.
predicate<K extends keyof T>(value: T[K], key: K) => anyThe function invoked per property.

Type parameters

NameConstraint
Tobject
Kkeyof T

Returns

The new object.

Return type

Partial<T>