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

Package detail

array.prototype.grouptomap

es-shims302MIT1.1.3

An ESnext spec-compliant Array.prototype.groupToMap shim/polyfill/replacement that works as far down as ES3.

javascript, ecmascript, es-shim API, polyfill, shim, array, groupBy, group, grouping, groupToMap

readme

array.prototype.groupToMap Version Badge

dependency status dev dependency status License Downloads

npm badge

An ESnext spec-compliant Array.prototype.groupToMap 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.

Because Array.prototype.groupToMap depends on a receiver (the this value), the main export takes the array to operate on as the first argument.

Getting started

npm install --save array.prototype.grouptomap

Usage/Examples

var groupToMap = require('array.prototype.grouptomap');
var assert = require('assert');

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

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

assert.deepEqual(results, new Map([
    ['even', [0, 2, 4]],
    ['odd', [1, 3, 5]],
]));
var groupToMap = require('array.prototype.grouptomap');
var assert = require('assert');
/* when Array#groupToMap is not present */
delete Array.prototype.groupToMap;
var shimmed = groupToMap.shim();

assert.equal(shimmed, groupToMap.getPolyfill());
assert.deepEqual(arr.groupToMap(parity), groupToMap(arr, parity));
var groupToMap = require('array.prototype.grouptomap');
var assert = require('assert');
/* when Array#groupToMap is present */
var shimmed = groupToMap.shim();

assert.equal(shimmed, Array.prototype.groupToMap);
assert.deepEqual(arr.groupToMap(parity), groupToMap(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.1.3 - 2024-02-10

Commits

  • [Refactor] use map.groupby 76832d9
  • [Deps] update es-abstract 143c2a7
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, aud, tape e8b7f95
  • [Deps] update es-abstract, es-shim-unscopables; add missing deps 41818ef
  • [Dev Deps] update aud, npmignore, tape d29b253
  • [Refactor] use es-errors, so things that only need those do not need get-intrinsic e215815
  • [meta] add missing engines.node 858c59d
  • [Refactor] move AO dc7a4ff

v1.1.2 - 2022-11-03

Commits

  • [meta] use npmignore to autogenerate an npmignore file 2a4873c
  • [Deps] update es-abstract a647cbc
  • [actions] update rebase action to use reusable workflow 8f673cc
  • [Dev Deps] update aud, es-value-fixtures, functions-have-names, tape 5d445c4
  • [Dev Deps] use for-each instead of missing foreach 719105e

v1.1.1 - 2022-06-06

Commits

  • [Breaking] rename package/repo to array.prototype.grouptomap 2c47ed4

v1.1.0 - 2022-04-11

Commits

  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, tape 2de4b01
  • [New] shim/auto: add groupByToMap to Symbol.unscopables feed658
  • [Deps] update es-abstract b7d7bd4

v1.0.0 - 2021-12-14

Commits