to-object-by
v1.1.0
Published
Reduce an Array into Object for indexing purpose.
Downloads
6,617
Maintainers
Readme
to-object-by
Reduce an Array into Object for indexing purpose.
Installation
$ npm install to-object-by --save
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
).