to-object-by

1.1.0 • Public • Published

to-object-by

Reduce an Array into Object for indexing purpose.

Travis Codecov Status npm package npm downloads license

Dependency Status devDependency Status peerDependency Status

Installation

$ npm install to-object-by --save

Quick DEMO on tonicdev

Usage

import toObjectBy from 'to-object-by';
 
t.deepEqual(
  toObjectBy(
    [
      { foo: 'foo1', bar: 'bar1' },
      { foo: 'foo2', bar: 'bar1' },
    ],
    e => ({ [e.foo]: e }),
  ),
  {
    foo1: { foo: 'foo1', bar: 'bar1' },
    foo2: { foo: 'foo2', bar: 'bar1' },
  }
);

API

type Element = Object;
 
toObjectBy(
  array: Array<Element>,
  propertyMapper: (e: Element) => Object,
): Object

Test

$ npm run lint
$ npm run test:watch

CONTRIBUTING

  • ⇄ Pull requests and ★ Stars are always welcome.
  • For bugs and feature requests, please create an issue.
  • Pull requests must be accompanied by passing automated tests ($ npm test).

CHANGELOG

LICENSE

MIT: http://michaelhsu.mit-license.org

Package Sidebar

Install

npm i to-object-by

Weekly Downloads

5

Version

1.1.0

License

MIT

Last publish

Collaborators

  • evenchange4