uinix-fp-map-entries
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

uinix-fp-map-entries

Build Coverage Downloads Size

uinix-fp object map entries utility.


Install

This package is ESM-only and requires Node 12+.

npm install uinix-fp-map-entries

Use

mapEntries applies the provided mapper over an object's entries. It is recommended that the provided objects follow a single value interface when used with mapEntries.

import {mapEntries} from 'uinix-fp-map-entries';

const squareEntries = ([_k, v]) => v ** 2;

mapEntries(squareEntries)({a: 1, b: 2, c: 3}); // {a: 1, b: 4, c: 9}

const mapSquareEntries = mapEntries(squareEntries); // curried
mapSquareEntries({a: 1, b: 2, c: 3}); // {a: 1, b: 4, c: 9}

const keyedSquareEntries = ([k, v]) => k.startsWith('a') ? v ** 2 : v;
mapEntries(keyedSquareEntries)({a1: 2, b1: 3, a2: 4, b2: 5}); // {a1: 4, b1: 3, a2: 16, b2: 5}

API

This package exports the following identifiers: mapEntries. There is no default export.

mapEntries(f)(object)

Parameters (Curried)
  • f ((x: X) => Y): The mapping function
  • object (Record<string, X>): An object with values of a single type.
Returns
  • Record<string, Y> — An object with mapped values of a single type.

License

MIT © Chris Zhou

Package Sidebar

Install

npm i uinix-fp-map-entries

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

3.75 kB

Total Files

4

Last publish

Collaborators

  • chrisrzhou