Socket
Socket
Sign inDemoInstall

101

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

101 - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

group-by.js

2

index-by.js

@@ -10,3 +10,3 @@ /**

/**
* Hashes an array of objects based on the value of a provided common key.
* Hashes an array based on the value of a provided common key.
* @function module:101/index-by

@@ -13,0 +13,0 @@ * @param {array|function|string} arr|indexer - array of objects to be indexed

{
"name": "101",
"version": "1.5.0",
"version": "1.6.0",
"description": "common javascript utils that can be required selectively that assume es5+",

@@ -5,0 +5,0 @@ "main": "index.js",

![101](http://i.imgur.com/MFrmMt6.png)
===
[![NPM](https://nodei.co/npm/101.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/101/)
[![NPM](https://nodei.co/npm/101.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/101/)

@@ -324,3 +324,41 @@ [![Build Status](https://travis-ci.org/tjmehta/101.svg?branch=master)](https://travis-ci.org/tjmehta/101)

flip(prefix)('hello', '_'); // "_hello"
```
## groupBy
Hashes an array into groups based on the value of a provided common key.
Works nicely with `pluck` and `reduce`.
```js
var arr = [
{id: 1, foo: 'bar'},
{id: 2, foo: 'qux'},
{id: 3, foo: 'qux'}
];
groupBy(arr, 'foo')
/*
{
bar: [
{id: 1, foo: 'bar'}
],
qux: [
{id: 2, foo: 'qux'},
{id: 3, foo: 'qux'}
]
}
*/
// always provide initial value when using with reduce!
arr.reduce(groupBy('foo'), {}) // assumes pluck if passed string
arr.reduce(groupBy(pluck('foo')), {}) // also accepts function
/*
{
bar: [
{id: 1, foo: 'bar'}
],
qux: [
{id: 2, foo: 'qux'},
{id: 3, foo: 'qux'}
]
}
*/
```

@@ -433,7 +471,9 @@

var arr = [
{foo: 'bar'},
{foo: 'qux'}
{foo: 'bar'},
{foo: 'qux'}
];
indexBy(arr, 'foo') // {bar: {foo: 'bar'}, qux: {foo: 'qux'}}
arr.reduce(indexBy('foo'), {}) // assumes pluck if passed string
arr.reduce(indexBy(pluck('foo')), {}) // also accepts function
// {bar: {foo: 'bar'}, qux: {foo: 'qux'}}
// always provide initial value when using with reduce!

@@ -440,0 +480,0 @@ arr.reduce(indexBy(pluck('foo')), {}) // {bar: {foo: 'bar'}, qux: {foo: 'qux'}}

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc