JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 299
  • Score
    100M100P100Q85446F
  • License MIT

Group objects by their properties.

Package Exports

  • grouper

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (grouper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Grouper.js npm Version Build Status Coverage Status

Group objects by their properties.

var arr = [
  { name: 'foo', age: 2, score: 0 },
  { name: 'bar', age: 2, score: 0 },
  { name: 'baz', age: 3, score: 0 },
  { name: 'qux', age: 2, score: 1 }
];

grouper(arr, 'age'); // group by a single property
/* =>
 * [ [ { name: 'foo', age: 2, score: 0 },
 *     { name: 'bar', age: 2, score: 0 },
 *     { name: 'qux', age: 2, score: 1 } ],
 *   [ { name: 'baz', age: 3, score: 0 } ] ]
 */

grouper(arr, ['age', 'score']); // group by multiple properties
/* =>
 * [ [ { name: 'foo', age: 2, score: 0 },
 *     { name: 'bar', age: 2, score: 0 } ],
 *   [ { name: 'baz', age: 3, score: 0 } ],
 *   [ { name: 'qux', age: 2, score: 1 } ] ]
 */

API

grouper(arr, props)

Groups objects in arr by props. Objects to be grouped together must have the same value (strict ===) for every property in props.

  • arr is an array of objects.

  • props is a string, or an array of property names.

Installation

Install via npm:

$ npm i --save grouper

License

MIT license