object.groupby (1.0.3)
Published 2026-02-24 14:02:05 +00:00 by atheaadmin
Installation
registry=npm install object.groupby@1.0.3"object.groupby": "1.0.3"About this package
object.groupby 
An ESnext spec-compliant Object.groupBy shim/polyfill/replacement that works as far down as ES3.
This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the proposed spec.
Getting started
npm install --save object.groupby
Usage/Examples
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],
});
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));
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
Dependencies
Dependencies
| ID | Version |
|---|---|
| call-bind | ^1.0.7 |
| define-properties | ^1.2.1 |
| es-abstract | ^1.23.2 |
Development Dependencies
| ID | Version |
|---|---|
| @es-shims/api | ^2.4.2 |
| @ljharb/eslint-config | ^21.1.0 |
| aud | ^2.0.4 |
| auto-changelog | ^2.4.0 |
| es-value-fixtures | ^1.4.2 |
| eslint | =8.8.0 |
| evalmd | ^0.0.19 |
| for-each | ^0.3.3 |
| functions-have-names | ^1.2.3 |
| in-publish | ^2.0.1 |
| npmignore | ^0.3.1 |
| nyc | ^10.3.2 |
| object-inspect | ^1.13.1 |
| safe-publish-latest | ^2.0.0 |
| tape | ^5.7.5 |
Keywords
ecmascript
javascript
polyfill
shim
es-shim API
array
object
group
groupBy
