# object.groupby

> An ESnext spec-compliant `Object.groupBy` shim/polyfill/replacement that works as far down as ES3.

Latest version **1.0.3** (published 2024-03-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install object.groupby
pnpm add object.groupby
yarn add object.groupby
bun add object.groupby
```

## Health

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

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2024-03-18 |
| First published | 2023-07-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/object.groupby) |
| Module format | ESM + CommonJS |
| Node | >= 0.4 |
| Dependencies | 3 |
| Unpacked size | 14.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Jordan Harband |
| Maintainers | ljharb |
| Keywords | ecmascript, javascript, polyfill, shim, es-shim API, array, object, group, groupBy |

## Links

- npm: https://www.npmjs.com/package/object.groupby
- Repository: https://github.com/es-shims/Object.groupBy
- Homepage: https://github.com/es-shims/Object.groupBy#readme
- Issues: https://github.com/es-shims/Object.groupBy/issues
- npm.io page: https://npm.io/package/object.groupby

## Dependencies (3)

- [call-bind](https://npm.io/package/call-bind.md) ^1.0.7
- [es-abstract](https://npm.io/package/es-abstract.md) ^1.23.2
- [define-properties](https://npm.io/package/define-properties.md) ^1.2.1

## Recent versions

- 1.0.3 (latest) — 2024-03-18
- 1.0.2 — 2024-02-05
- 1.0.1 — 2023-08-28
- 1.0.0 — 2023-07-11

## README

# object.groupby <sup>[![Version Badge][npm-version-svg]][package-url]</sup>

[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][npm-badge-png]][package-url]

An ESnext spec-compliant `Object.groupBy` shim/polyfill/replacement that works as far down as ES3.

This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the proposed [spec](https://tc39.github.io/proposal-array-grouping/).

## Getting started

```sh
npm install --save object.groupby
```

## Usage/Examples

```js
var groupBy = require('object.groupby');
var assert = require('assert');

var arr = [0, 1, 2, 3, 4, 5];
var parity = function (x) { return x % 2 === 0 ? 'even' : 'odd'; };

var results = groupBy(arr, function (x, i) {
    assert.equal(x, arr[i]);
    return parity(x);
});

assert.deepEqual(results, {
    __proto__: null,
    even: [0, 2, 4],
    odd: [1, 3, 5],
});
```

```js
var groupBy = require('object.groupby');
var assert = require('assert');
/* when Object.groupBy is not present */
delete Object.groupBy;
var shimmed = groupBy.shim();

assert.equal(shimmed, groupBy.getPolyfill());
assert.deepEqual(Object.groupBy(arr, parity), groupBy(arr, parity));
```

```js
var groupBy = require('object.groupby');
var assert = require('assert');
/* when Array#group is present */
var shimmed = groupBy.shim();

assert.equal(shimmed, Object.groupBy);
assert.deepEqual(Object.groupBy(arr, parity), groupBy(arr, parity));
```

## Tests
Simply clone the repo, `npm install`, and run `npm test`

[package-url]: https://npmjs.org/package/object.groupby
[npm-version-svg]: https://versionbadg.es/es-shims/Object.groupBy.svg
[deps-svg]: https://david-dm.org/es-shims/Object.groupBy.svg
[deps-url]: https://david-dm.org/es-shims/Object.groupBy
[dev-deps-svg]: https://david-dm.org/es-shims/Object.groupBy/dev-status.svg
[dev-deps-url]: https://david-dm.org/es-shims/Object.groupBy#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/object.groupby.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/object.groupby.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/object.groupby.svg
[downloads-url]: https://npm-stat.com/charts.html?package=object.groupby
[codecov-image]: https://codecov.io/gh/es-shims/Object.groupBy/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/es-shims/Object.groupBy/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Object.groupBy
[actions-url]: https://github.com/es-shims/Object.groupBy/actions

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