1.1.0 • Published 8 years ago

to-object-by v1.1.0

Weekly downloads
42
License
MIT
Repository
github
Last release
8 years ago

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

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago