Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

object.groupby

es-shims50.7mMIT1.0.3TypeScript support: definitely-typed

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

ecmascript, javascript, polyfill, shim, es-shim API, array, object, group, groupBy

readme

object.groupby Version Badge

github actions coverage License Downloads

npm badge

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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.0.3 - 2024-03-18

Commits

  • [Deps] update call-bind, es-abstract f1d3e70
  • [Dev Deps] update tape 272a736
  • [meta] add missing engines.node 7a9c8b0

v1.0.2 - 2024-02-04

Commits

  • [Refactor] use es-errors where possible, so things that only need those do not need get-intrinsic a6c01d0
  • [Deps] update call-bind, define-properties, es-abstract, get-intrinsic 65383da
  • [Dev Deps] update aud, npmignore, tape e8aeb5b
  • [Robustness] filter is not available pre-ES5 8f185b8

v1.0.1 - 2023-08-28

Commits

v1.0.0 - 2023-07-11

Commits

  • Initial implementation, tests, readme 77809f3
  • Initial commit 24ea8cd
  • npm init 36a7d4d
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, aud, tape bd7b39f
  • [Deps] update define-properties, es-abstract, get-intrinsic 9615141
  • Only apps should have lockfiles 63b79a9