Socket
Socket
Sign inDemoInstall

array-group-by-to-map-ponyfill

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    array-group-by-to-map-ponyfill

`Array.prototype.groupByToMap` ponyfill.


Version published
Weekly downloads
10
increased by11.11%
Maintainers
1
Install size
27.2 kB
Created
Weekly downloads
 

Changelog

Source

[2.0.0][] - 2021-12-16

Fixed

  • Make spec compliant by returning Map

Readme

Source

array-group-by-to-map-ponyfill

Build Status Browser testing by BrowserStack

Array.prototype.groupByToMap ponyfill.

A proposal to make grouping of items in an array easier.

Install

npm install array-group-by-to-map-ponyfill --save

Usage

import groupByToMap from 'array-group-by-to-map-ponyfill';

groupByToMap([1, 2, 3, 4, 5], (value) => (value % 2 === 0 ? 'even' : 'odd'));

// Map([['odd', [1, 3, 5]], ['even', [2, 4]]])

You can use named export preferNative if you wish to use native implementation if it’s available. In all other cases, ponyfill will be used. Beware of caveats!

API

groupByToMap(array, callback)

Returns: Map

Group array items to map.

array

Type: any[]

Array to group.

callback

Type: Function

Callback which should return key with which to group array.

ArgumentTypeDescription
valueanyCurrent iteration value.
indexnumberCurrent iteration index.
arrayany[]Original array reference.

Browser support

Tested in Chrome 72, Edge 15, Firefox 65 and should work in all modern browsers (support based on Browserslist configuration).

Test

Test suite is taken and modified from core-js test suite.

For automated tests, run npm run test:automated (append :watch for watcher support).

License

MIT © Ivan Nikolić

Keywords

FAQs

Last updated on 16 Dec 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc