uinix-fp-filter-entries
v1.0.1
Published
uinix fp object filter entries utility
Downloads
5
Maintainers
Readme
uinix-fp-filter-entries
uinix-fp
object filter entries utility.
Install
This package is ESM-only and requires Node 12+.
npm install uinix-fp-filter-entries
Use
filterEntries
applies the provided filter predicate over an object's entries. It is recommended that the provided objects follow a single value interface when using with filterEntries
.
import {filterEntries} from 'uinix-fp-filter-entries';
const isEvenEntries = ([_k, v]) => v % 2 === 0;
filterEntries(isEvenEntries)({a: 1, b: 2, c: 3}); // {b: 2}
const filterEvenEntries = filterEntries(isEvenEntries); // curried
filterEvenEntries({a: 1, b: 2, c: 3}); // {b: 2}
const keyedIsEvenEntries = ([k, v]) => k.startsWith('a') ? v % 2 === 0 : false;
filterEntries(keyedIsEvenEntries)({a1: 2, b1: 3, a2: 5, b2: 6}); // {a1: 2}
API
This package exports the following identifiers: filterEntries
. There is no default export.
filterEntries(f)(object)
Parameters (Curried)
f
((x: X) => boolean
): The filter predicate function.object
(Record<string, X>
): An object with values of a single type.
Returns
Record<string, X>
— Partial object of filtered entries passing the predicate test.