# group-object

> Group object keys and values into lists.

Latest version **0.1.1** (published 2015-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install group-object
pnpm add group-object
yarn add group-object
bun add group-object
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2015-07-19 |
| First published | 2015-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Brian Woodward |
| Maintainers | doowb, jonschlinkert |

## Links

- npm: https://www.npmjs.com/package/group-object
- Repository: https://github.com/doowb/group-object
- Issues: https://github.com/doowb/group-object/issues
- npm.io page: https://npm.io/package/group-object

## Dependencies (2)

- [for-in](https://npm.io/package/for-in.md) ^0.1.4
- [upsert-value](https://npm.io/package/upsert-value.md) ^0.1.0

## Recent versions

- 0.1.1 (latest) — 2015-07-19
- 0.1.0 — 2015-07-10

## README

# group-object [![NPM version](https://badge.fury.io/js/group-object.svg)](http://badge.fury.io/js/group-object)  [![Build Status](https://travis-ci.org/doowb/group-object.svg)](https://travis-ci.org/doowb/group-object)

> Group object keys and values into lists.

Install with [npm](https://www.npmjs.com/)

```sh
$ npm i group-object --save
```

## Usage

```js
var groupBy = require('group-object');
```

## API

### [groupBy](index.js#L62)

Create groupings from an object's keys and values.

**Params**

* `obj` **{Object}**: Object to group.
* `grouper` **{Function}**: Optional grouping function that takes `acc, value, key, obj, setter`
* `setter` **{Function}**: Optional setter function that takes `acc, group, value, key, obj`
* `acc` **{Object}**: Optional accumulator object passed to the setter function.
* `returns` **{Object}**: Object containing groups as keys and list of objects as values in the group.

**Example**

```js
function grouper (acc, value, key, obj, setter) {
  return value.group;
}

function setter (acc, group, value, key, obj) {
  acc[group] = acc[group] || {};
  acc[group][key] = value;
}

var obj = {
  a: { group: 'one', content: 'A'},
  b: { group: 'one', content: 'B'},
  c: { group: 'two', content: 'C'},
  d: { group: 'two', content: 'D'},
  e: { group: 'three', content: 'E'},
  f: { group: 'three', content: 'F'}
};

var groups = groupBy(obj, grouper, setter);
//=> {
//=>   one: {
//=>     a: { group: 'one', content: 'A'},
//=>     b: { group: 'one', content: 'B'}
//=>   },
//=>   two: {
//=>     c: { group: 'two', content: 'C'},
//=>     d: { group: 'two', content: 'D'}
//=>   },
//=>   three: {
//=>     e: { group: 'three', content: 'E'},
//=>     f: { group: 'three', content: 'F'}
//=>   }
//=> }
```

## Related projects

* [for-in](https://github.com/jonschlinkert/for-in): Iterate over the own and inherited enumerable properties of an objecte, and return an object… [more](https://github.com/jonschlinkert/for-in)
* [group-array](https://github.com/doowb/group-array): Group array of objects into lists.
* [get-value](https://github.com/jonschlinkert/get-value): Use property paths (`  a.b.c`) to get a nested value from an object.
* [sort-object](https://github.com/doowb/sort-object): Sort the keys in an object.
* [set-value](https://github.com/jonschlinkert/set-value): Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.
* [upsert-value](https://github.com/doowb/upsert-value): Update or set nested values and any intermediaries with dot notation (`'a.b.c'`) paths.

## Running tests

Install dev dependencies:

```sh
$ npm i -d && npm test
```

## Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/doowb/group-object/issues/new)

## Author

**Brian Woodward**

+ [github/doowb](https://github.com/doowb)
+ [twitter/doowb](http://twitter.com/doowb)

## License

Copyright © 2015 Brian Woodward
Released under the MIT license.

***

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on July 19, 2015._

---
_Source: https://npm.io/package/group-object · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
